diff --git a/src/app/tools/tankopedia/components/Options.tsx b/src/app/tools/tankopedia/components/Options.tsx index 9a4e887c0..c4ec3e29b 100644 --- a/src/app/tools/tankopedia/components/Options.tsx +++ b/src/app/tools/tankopedia/components/Options.tsx @@ -2,6 +2,13 @@ import { CaretDownIcon } from '@radix-ui/react-icons'; import { Button, DropdownMenu, Flex } from '@radix-ui/themes'; +import { + TANK_TYPES, + TREE_TYPES, + TREE_TYPE_ICONS, + TREE_TYPE_IMAGES, + TreeTypeEnum, +} from '../../../../components/Tanks'; import { TIERS, TIER_ROMAN_NUMERALS, @@ -16,7 +23,7 @@ export function Options() { const tankopediaState = useTankopedia(); return ( - + @@ -67,38 +74,110 @@ export function Options() { - - - {TIERS.toReversed().map((tier, index) => ( - - ))} - + + {TIERS.toReversed().map((tier, index) => ( + + ))} + + + + {TANK_TYPES.toReversed().map((type, index) => ( + + ))} + + + + {TREE_TYPES.map((type, index) => ( + + ))} ); diff --git a/src/app/tools/tankopedia/page.tsx b/src/app/tools/tankopedia/page.tsx index a624890fd..adc61e79e 100644 --- a/src/app/tools/tankopedia/page.tsx +++ b/src/app/tools/tankopedia/page.tsx @@ -33,7 +33,18 @@ export default function Page() { const searchableTanks = useMemo( () => awaitedTanks - .filter((tank) => tankopediaState.filters.tiers.includes(tank.tier)) + .filter( + (tank) => + (tankopediaState.filters.tiers.length === 0 + ? true + : tankopediaState.filters.tiers.includes(tank.tier)) && + (tankopediaState.filters.types.length === 0 + ? true + : tankopediaState.filters.types.includes(tank.type)) && + (tankopediaState.filters.treeTypes.length === 0 + ? true + : tankopediaState.filters.treeTypes.includes(tank.tree_type)), + ) .toSorted((a, b) => { let diff = 0; diff --git a/src/components/Tanks/components/Item.tsx b/src/components/Tanks/components/Item.tsx index d92e33bd9..6195424f0 100644 --- a/src/components/Tanks/components/Item.tsx +++ b/src/components/Tanks/components/Item.tsx @@ -11,8 +11,18 @@ export enum TreeTypeEnum { Collector, } -export type TankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank'; -export type TreeTypeString = 'tech-tree' | 'premium' | 'collector'; +export const TANK_TYPES = [ + 'AT-SPG', + 'lightTank', + 'mediumTank', + 'heavyTank', +] as const; + +// TODO: remove hyphen for underscore +export const TREE_TYPES = ['tech-tree', 'premium', 'collector'] as const; + +export type TankType = (typeof TANK_TYPES)[number]; +export type TreeTypeString = (typeof TREE_TYPES)[number]; export const TREE_TYPE_NAMES: Record = { 'tech-tree': 'Tech tree', @@ -20,6 +30,12 @@ export const TREE_TYPE_NAMES: Record = { collector: 'Collector', }; +export const TREE_TYPE_IMAGES: Record = { + 'tech-tree': 'https://i.imgur.com/pJxO2XY.png', + premium: 'https://i.imgur.com/mZzSwOU.png', + collector: 'https://i.imgur.com/7A0RsG5.png', +}; + export interface ItemProps { image?: string; tankType?: TankType; diff --git a/src/core/blitzkrieg/tankopedia.ts b/src/core/blitzkrieg/tankopedia.ts index bf71b7d18..26c625710 100644 --- a/src/core/blitzkrieg/tankopedia.ts +++ b/src/core/blitzkrieg/tankopedia.ts @@ -82,9 +82,9 @@ export const TANK_ICONS_COLLECTOR: Record = { heavyTank: 'https://i.imgur.com/8xRf3nc.png', }; -export type Tier = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10; +export const TIERS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as const; -export const TIERS: Tier[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; +export type Tier = (typeof TIERS)[number]; export const TIER_ROMAN_NUMERALS: Record = { 1: 'I', diff --git a/src/stores/tankopedia.ts b/src/stores/tankopedia.ts index c3f2f7d1d..4a1ffe742 100644 --- a/src/stores/tankopedia.ts +++ b/src/stores/tankopedia.ts @@ -1,7 +1,8 @@ import { produce } from 'immer'; import { create } from 'zustand'; import { devtools, persist } from 'zustand/middleware'; -import { TIERS, Tier } from '../core/blitzkrieg/tankopedia'; +import { TankType, TreeTypeString } from '../components/Tanks'; +import { Tier } from '../core/blitzkrieg/tankopedia'; export type TankopediaSortBy = 'tier' | 'name'; export type TankopediaSortDirection = 'ascending' | 'descending'; @@ -13,6 +14,8 @@ type Tankopedia = { }; filters: { tiers: Tier[]; + types: TankType[]; + treeTypes: TreeTypeString[]; }; }; @@ -25,7 +28,9 @@ export const useTankopedia = create()( direction: 'descending', }, filters: { - tiers: [...TIERS], + tiers: [], + types: [], + treeTypes: [], }, }), { name: 'tankopedia' },