feat: nation filters

This commit is contained in:
TrèsAbhi committed 2023-12-04 19:10:26 -06:00
1 parent 7bde92c7f1
commit cadc84b32f
5 files changed
+122 -32

No files matched your search

+34 -22
View File
@@ -166,30 +166,42 @@ Promise.all(
// }), // }),
// ) // )
// ).flat() as FileChange[]; // ).flat() as FileChange[];
const flagChanges = await readdir( const flags = await readdir(`${TEMP}/${directoriesOfInterest.flags}`);
`${TEMP}/${directoriesOfInterest.flags}`, // const scratchedFlags = await Promise.all(
).then((flags) => // flags
Promise.all( // .filter((flag) => flag.startsWith('flag_tutor-tank_'))
flags // .map(async (flag) => {
.filter((flag) => flag.startsWith('flag_tutor-tank_')) // const content = await readFile(
.map(async (flag) => { // `${TEMP}/${directoriesOfInterest.flags}/${flag}`,
const content = await readFile( // { encoding: 'base64' },
`${TEMP}/${directoriesOfInterest.flags}/${flag}`, // );
{ encoding: 'base64' }, // const name = flag.match(/flag_tutor-tank_(.+)\.packed\.webp/)![1];
);
const name = flag.match(/flag_tutor-tank_(.+)\.packed\.webp/)![1];
return { // return {
content, // content,
encoding: 'base64', // encoding: 'base64',
path: `flags/scratched/${name}.webp`, // path: `flags/scratched/${name}.webp`,
} satisfies FileChange; // } satisfies FileChange;
}), // }),
), // );
const circleFlags = await Promise.all(
flags
.filter((flag) => flag.startsWith('flag_profile-stat_'))
.map(async (flag) => {
const content = await readFile(
`${TEMP}/${directoriesOfInterest.flags}/${flag}`,
{ encoding: 'base64' },
);
const name = flag.match(/flag_profile-stat_(.+)\.packed\.webp/)![1];
return {
content,
encoding: 'base64',
path: `flags/circle/${name}.webp`,
} satisfies FileChange;
}),
); );
console.log(flagChanges);
console.log('Writing files...'); console.log('Writing files...');
await commitMultipleFiles( await commitMultipleFiles(
octokit, octokit,
@@ -197,7 +209,7 @@ Promise.all(
'blitzkrieg-assets', 'blitzkrieg-assets',
'main', 'main',
new Date().toString(), new Date().toString(),
flagChanges, circleFlags,
true, true,
); );
} else { } else {
@@ -2,6 +2,7 @@
import { CaretDownIcon } from '@radix-ui/react-icons'; import { CaretDownIcon } from '@radix-ui/react-icons';
import { Button, DropdownMenu, Flex } from '@radix-ui/themes'; import { Button, DropdownMenu, Flex } from '@radix-ui/themes';
import { use } from 'react';
import { import {
TANK_TYPES, TANK_TYPES,
TREE_TYPES, TREE_TYPES,
@@ -9,7 +10,9 @@ import {
TREE_TYPE_IMAGES, TREE_TYPE_IMAGES,
TreeTypeEnum, TreeTypeEnum,
} from '../../../../components/Tanks'; } from '../../../../components/Tanks';
import { asset } from '../../../../core/blitzkrieg/asset';
import { import {
NATIONS,
TIERS, TIERS,
TIER_ROMAN_NUMERALS, TIER_ROMAN_NUMERALS,
} from '../../../../core/blitzkrieg/tankopedia'; } from '../../../../core/blitzkrieg/tankopedia';
@@ -20,11 +23,12 @@ import mutateTankopedia, {
} from '../../../../stores/tankopedia'; } from '../../../../stores/tankopedia';
export function Options() { export function Options() {
const nations = use(NATIONS);
const tankopediaState = useTankopedia(); const tankopediaState = useTankopedia();
return ( return (
<Flex justify="center" wrap="wrap" gap="4"> <Flex justify="center" wrap="wrap" gap="4">
<Flex gap="1"> <Flex gap="2">
<DropdownMenu.Root> <DropdownMenu.Root>
<DropdownMenu.Trigger> <DropdownMenu.Trigger>
<Button variant="soft"> <Button variant="soft">
@@ -142,6 +146,49 @@ export function Options() {
))} ))}
</Flex> </Flex>
<Flex>
{nations.map((nation, index) => (
<Button
key={nation}
variant={
tankopediaState.filters.nations.includes(nation)
? 'solid'
: 'soft'
}
style={{
margin: -0.5,
borderTopLeftRadius: index === 0 ? undefined : 0,
borderBottomLeftRadius: index === 0 ? undefined : 0,
borderTopRightRadius:
index === nations.length - 1 ? undefined : 0,
borderBottomRightRadius:
index === nations.length - 1 ? undefined : 0,
}}
onClick={() =>
mutateTankopedia((draft) => {
if (draft.filters.nations.includes(nation)) {
draft.filters.nations = draft.filters.nations.filter(
(preexistingType) => preexistingType !== nation,
);
} else {
draft.filters.nations.push(nation);
}
})
}
>
<img
src={asset(`flags/circle/${nation}.webp`)}
style={{
width: '1em',
height: '1em',
scale: 2,
transform: 'translate(15%, 15%)',
}}
/>
</Button>
))}
</Flex>
<Flex> <Flex>
{TREE_TYPES.map((type, index) => ( {TREE_TYPES.map((type, index) => (
<Button <Button
@@ -179,6 +226,22 @@ export function Options() {
</Button> </Button>
))} ))}
</Flex> </Flex>
<Button
color="red"
onClick={() =>
useTankopedia.setState({
filters: {
nations: [],
tiers: [],
treeTypes: [],
types: [],
},
})
}
>
Clear
</Button>
</Flex> </Flex>
); );
} }
+12 -9
View File
@@ -41,7 +41,10 @@ export default function Page() {
: tankopediaState.filters.types.includes(tank.type)) && : tankopediaState.filters.types.includes(tank.type)) &&
(tankopediaState.filters.treeTypes.length === 0 (tankopediaState.filters.treeTypes.length === 0
? true ? true
: tankopediaState.filters.treeTypes.includes(tank.tree_type)), : tankopediaState.filters.treeTypes.includes(tank.tree_type)) &&
(tankopediaState.filters.nations.length === 0
? true
: tankopediaState.filters.nations.includes(tank.nation)),
) )
.sort((a, b) => { .sort((a, b) => {
let diff = 0; let diff = 0;
@@ -81,7 +84,7 @@ export default function Page() {
return ( return (
<PageWrapper size="wide" color="purple"> <PageWrapper size="wide" color="purple">
<Suspense fallback={<Text>Loading...</Text>}> <Suspense fallback={<Text>Loading...</Text>}>
<Flex direction="column" gap="3"> <Flex direction="column" gap="6">
<TextField.Root> <TextField.Root>
<TextField.Slot> <TextField.Slot>
<MagnifyingGlassIcon height="16" width="16" /> <MagnifyingGlassIcon height="16" width="16" />
@@ -108,14 +111,14 @@ export default function Page() {
</TextField.Root> </TextField.Root>
<Options /> <Options />
</Flex>
<PageTurner <PageTurner
page={page} page={page}
setPage={setPage} setPage={setPage}
tanksPerPage={TANKS_PER_PAGE} tanksPerPage={TANKS_PER_PAGE}
searchedList={searchedList} searchedList={searchedList}
/> />
</Flex>
<Flex wrap="wrap" gap="3" justify="center"> <Flex wrap="wrap" gap="3" justify="center">
{searchedList {searchedList
+10
View File
@@ -98,3 +98,13 @@ export const TIER_ROMAN_NUMERALS: Record<Tier, string> = {
9: 'IX', 9: 'IX',
10: 'X', 10: 'X',
}; };
export const NATIONS = tanks.then((tanks) => {
const nationsObject: Record<string, true> = {};
tanks.forEach(({ nation }) => {
nationsObject[nation] = true;
});
return Object.keys(nationsObject);
});
+2
View File
@@ -16,6 +16,7 @@ type Tankopedia = {
tiers: Tier[]; tiers: Tier[];
types: TankType[]; types: TankType[];
treeTypes: TreeTypeString[]; treeTypes: TreeTypeString[];
nations: string[];
}; };
}; };
@@ -31,6 +32,7 @@ export const useTankopedia = create<Tankopedia>()(
tiers: [], tiers: [],
types: [], types: [],
treeTypes: [], treeTypes: [],
nations: [],
}, },
}), }),
{ name: 'tankopedia' }, { name: 'tankopedia' },