feat: select all option

This commit is contained in:
TrèsAbhi committed 2024-04-06 10:36:07 -05:00
1 parent 184ca522dd
commit 49d3e1d1c2
3 files changed
+57 -3

No files matched your search

+1
View File
@@ -148,6 +148,7 @@
"whitespaces", "whitespaces",
"winrate", "winrate",
"wireframe", "wireframe",
"Woah",
"WOTB", "WOTB",
"wotblitz", "wotblitz",
"xffn", "xffn",
+10 -1
View File
@@ -293,7 +293,16 @@ export default function Page() {
tankToCompareMember(tank, awaitedSkillDefinitions), tankToCompareMember(tank, awaitedSkillDefinitions),
); );
}); });
setAddTankDialogOpen(false);
}}
onSelectAll={(tanks) => {
mutateCompareTemporary((draft) => {
draft.members.push(
...tanks.map((tank) =>
tankToCompareMember(tank, awaitedSkillDefinitions),
),
);
});
setAddTankDialogOpen(false); setAddTankDialogOpen(false);
}} }}
/> />
@@ -5,6 +5,7 @@ import {
TrashIcon, TrashIcon,
} from '@radix-ui/react-icons'; } from '@radix-ui/react-icons';
import { import {
AlertDialog,
Button, Button,
Card, Card,
DropdownMenu, DropdownMenu,
@@ -51,11 +52,16 @@ import { Options } from './components/Options';
interface TankSearchProps { interface TankSearchProps {
compact?: boolean; compact?: boolean;
onSelect?: (tank: TankDefinition) => void; onSelect?: (tank: TankDefinition) => void;
onSelectAll?: (tanks: TankDefinition[]) => void;
} }
const treeTypeOrder: TreeType[] = ['researchable', 'premium', 'collector']; const treeTypeOrder: TreeType[] = ['researchable', 'premium', 'collector'];
export function TankSearch({ compact, onSelect = () => {} }: TankSearchProps) { export function TankSearch({
compact,
onSelect = () => {},
onSelectAll,
}: TankSearchProps) {
const tanksPerPage = compact ? 16 : 96; const tanksPerPage = compact ? 16 : 96;
const nations = use(NATIONS); const nations = use(NATIONS);
const filters = useTankopediaPersistent((state) => state.filters); const filters = useTankopediaPersistent((state) => state.filters);
@@ -796,10 +802,47 @@ export function TankSearch({ compact, onSelect = () => {} }: TankSearchProps) {
<Options /> <Options />
</Flex> </Flex>
<Flex justify="center"> <Flex justify="center" gap="4" align="center">
<Text color="gray"> <Text color="gray">
Sorting: {SORT_NAMES[sort.by]}, {sort.direction} Sorting: {SORT_NAMES[sort.by]}, {sort.direction}
</Text> </Text>
{onSelectAll && searchResults.length <= 8 && (
<Button variant="ghost" onClick={() => onSelectAll(searchResults)}>
Select all
</Button>
)}
{onSelectAll && searchResults.length > 8 && (
<AlertDialog.Root>
<AlertDialog.Trigger>
<Button variant="ghost">Select all</Button>
</AlertDialog.Trigger>
<AlertDialog.Content>
<AlertDialog.Title>
Woah! That's a lot of tanks.
</AlertDialog.Title>
<AlertDialog.Description>
Would you like to select{' '}
<Text color="red">all {searchResults.length} tanks</Text>?
</AlertDialog.Description>
<Flex gap="2" justify="end">
<AlertDialog.Cancel>
<Button variant="soft" color="gray">
Cancel
</Button>
</AlertDialog.Cancel>
<AlertDialog.Action onClick={() => onSelectAll(searchResults)}>
<Button variant="solid" color="red">
Select {searchResults.length} tanks
</Button>
</AlertDialog.Action>
</Flex>
</AlertDialog.Content>
</AlertDialog.Root>
)}
</Flex> </Flex>
{!compact && ( {!compact && (
@@ -935,6 +978,7 @@ export function TankSearch({ compact, onSelect = () => {} }: TankSearchProps) {
<CompactSearchResultRow tanks={secondChunk} onSelect={onSelect} /> <CompactSearchResultRow tanks={secondChunk} onSelect={onSelect} />
)} )}
</Flex> </Flex>
<PageTurner tanksPerPage={tanksPerPage} searchedList={searchResults} /> <PageTurner tanksPerPage={tanksPerPage} searchedList={searchResults} />
</> </>
); );