-
Notifications
You must be signed in to change notification settings - Fork 39
Feature: Multi-select on relevant pages #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
618a92b
feat: half-baked multi-select, needs styling
jacc c9ad28d
feat: multi-select on crafting
jacc 405fb74
feat: multi-select on fishing
jacc cf2c381
fix: random validation error on poly/monoculture
jacc 74e445c
feat: filter update on shipping
jacc e7a1bde
feat: multi-select on museum
jacc d40c133
feat: multi-select on walnuts
jacc 97c6dae
feat: filter update on relationships
jacc 0664d58
feat: search on museum page
jacc 0f1a116
fix: linting error on fish-sheet
jacc 77b7e7d
fix: dynamic labels based on type and not window
jacc f0606c1
fix: add lucide (?)
jacc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| import { usePlayers } from "@/contexts/players-context"; | ||
| import { useMultiSelect } from "@/contexts/multi-select-context"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from "@/components/ui/dialog"; | ||
|
|
||
| interface Props { | ||
| open: boolean; | ||
| setOpen: (open: boolean) => void; | ||
| type: "cooking" | "crafting" | "shipping" | "museum"; | ||
| onBulkAction?: ( | ||
| status: number | null, | ||
| selectedItems: Set<string>, | ||
| close: () => void, | ||
| ) => void; | ||
| } | ||
|
|
||
| export const BulkActionDialog = ({ | ||
| open, | ||
| setOpen, | ||
| type, | ||
| onBulkAction, | ||
| }: Props) => { | ||
| const { selectedItems, clearSelection } = useMultiSelect(); | ||
| const { activePlayer, patchPlayer } = usePlayers(); | ||
|
|
||
| const close = () => { | ||
| clearSelection(); | ||
| setOpen(false); | ||
| }; | ||
|
|
||
| const handleBulkAction = async (status: number | null) => { | ||
| if (onBulkAction) { | ||
| onBulkAction(status, selectedItems, close); | ||
| return; | ||
| } | ||
| if (!activePlayer) return; | ||
|
|
||
| const patch: any = {}; | ||
| const items = Array.from(selectedItems); | ||
|
|
||
| switch (type) { | ||
| case "cooking": | ||
| patch.cooking = { | ||
| recipes: Object.fromEntries(items.map((id) => [id, status])), | ||
| }; | ||
| break; | ||
| case "crafting": | ||
| patch.crafting = { | ||
| recipes: Object.fromEntries(items.map((id) => [id, status])), | ||
| }; | ||
| break; | ||
| case "shipping": | ||
| patch.shipping = { | ||
| shipped: Object.fromEntries(items.map((id) => [id, status])), | ||
| }; | ||
| break; | ||
| case "museum": | ||
| patch.museum = { | ||
| donated: Object.fromEntries(items.map((id) => [id, status])), | ||
| }; | ||
| break; | ||
| } | ||
|
|
||
| await patchPlayer(patch); | ||
| close(); | ||
| }; | ||
|
|
||
| let foundLabel = "Set All Selected as Completed"; | ||
| let notFoundLabel = "Set All Selected as Incomplete"; | ||
| if (type === "museum") { | ||
| foundLabel = "Set All Selected as Found"; | ||
| notFoundLabel = "Set All Selected as Not Found"; | ||
| } else if (type === "shipping") { | ||
| foundLabel = "Set All Selected as Shipped"; | ||
| notFoundLabel = "Set All Selected as Unshipped"; | ||
| } | ||
|
|
||
| if ( | ||
| type === "museum" || | ||
| type === "shipping" || | ||
| type === "cooking" || | ||
| type === "crafting" | ||
| ) { | ||
| return ( | ||
| <Dialog open={open} onOpenChange={setOpen}> | ||
| <DialogContent> | ||
| <DialogHeader> | ||
| <DialogTitle>Bulk Action</DialogTitle> | ||
| </DialogHeader> | ||
| <div className="flex flex-col gap-2"> | ||
| <Button | ||
| variant="secondary" | ||
| onClick={() => handleBulkAction(2)} | ||
| disabled={selectedItems.size === 0} | ||
| > | ||
| {foundLabel} | ||
| </Button> | ||
| <Button | ||
| variant="secondary" | ||
| onClick={() => handleBulkAction(0)} | ||
| disabled={selectedItems.size === 0} | ||
| > | ||
| {notFoundLabel} | ||
| </Button> | ||
| </div> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Dialog open={open} onOpenChange={setOpen}> | ||
| <DialogContent> | ||
| <DialogHeader> | ||
| <DialogTitle>Bulk Action</DialogTitle> | ||
| <DialogDescription> | ||
| {selectedItems.size} items selected | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
| <div className="grid gap-4 py-4"> | ||
| <div className="grid grid-cols-1 gap-2"> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => handleBulkAction(null)} | ||
| disabled={!activePlayer} | ||
| > | ||
| Set Unknown | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => handleBulkAction(1)} | ||
| disabled={!activePlayer} | ||
| > | ||
| Set Known | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => handleBulkAction(2)} | ||
| disabled={!activePlayer} | ||
| > | ||
| Set Completed | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| <DialogFooter> | ||
| <Button variant="secondary" onClick={() => setOpen(false)}> | ||
| Cancel | ||
| </Button> | ||
| </DialogFooter> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The
lastSelectedIndexref isn’t reset when toggling multi-select mode, which could lead to unexpected range selections. Consider clearinglastSelectedIndex.currentwhen exiting or entering multi-select mode.