From 7877eaa89b86c68c5841b736adbbac02aeff4c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sat, 10 Feb 2024 00:04:43 -0600 Subject: [PATCH] feat: named sorting --- .../components/TankSearch/index.tsx | 9 ++- src/stores/tankopedia.ts | 57 ++++++++++--------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/app/tools/tankopedia/components/TankSearch/index.tsx b/src/app/tools/tankopedia/components/TankSearch/index.tsx index bc2c89c3b..b99873b30 100644 --- a/src/app/tools/tankopedia/components/TankSearch/index.tsx +++ b/src/app/tools/tankopedia/components/TankSearch/index.tsx @@ -35,6 +35,7 @@ import { tankIcon } from '../../../../../core/blitzkrieg/tankIcon'; import { unionBoundingBox } from '../../../../../core/blitzkrieg/unionBoundingBox'; import { theme } from '../../../../../stitches.config'; import mutateTankopediaPersistent, { + SORT_NAMES, TankopediaSortDirection, useTankopediaPersistent, } from '../../../../../stores/tankopedia'; @@ -756,10 +757,15 @@ export function TankSearch({ compact, onSelect = () => {} }: TankSearchProps) { + + + Sorting: {SORT_NAMES[sort.by]}, {sort.direction} + + + {!compact && ( )} - {!compact && searchResultsPageSlice.map((tank) => ( @@ -884,7 +890,6 @@ export function TankSearch({ compact, onSelect = () => {} }: TankSearchProps) { )} - ); diff --git a/src/stores/tankopedia.ts b/src/stores/tankopedia.ts index 266edf075..c756054b5 100644 --- a/src/stores/tankopedia.ts +++ b/src/stores/tankopedia.ts @@ -15,33 +15,7 @@ import { TurretDefinition, } from '../core/blitzkrieg/tankDefinitions'; -export type TankopediaSortBy = - | 'meta.tier' - | 'meta.name' - | 'survivability.health' - | 'survivability.viewRange' - | 'survivability.camouflageStill' - | 'survivability.camouflageMoving' - | 'survivability.camouflageShooting' - | 'survivability.size' - | 'fire.dpm' - | 'fire.reload' - | 'fire.caliber' - | 'fire.standardPenetration' - | 'fire.premiumPenetration' - | 'fire.damage' - | 'fire.shellVelocity' - | 'fire.aimTime' - | 'fire.dispersionStill' - | 'fire.dispersionMoving' - | 'fire.gunDepression' - | 'fire.gunElevation' - | 'maneuverability.forwardsSpeed' - | 'maneuverability.backwardsSpeed' - | 'maneuverability.power' - | 'maneuverability.powerToWeight' - | 'maneuverability.weight' - | 'maneuverability.traverseSpeed'; +export type TankopediaSortBy = keyof typeof SORT_NAMES; export type TankopediaSortDirection = 'ascending' | 'descending'; export type TankopediaTestTankDisplay = 'include' | 'exclude' | 'only'; export type TankopediaMode = 'model' | 'armor'; @@ -125,6 +99,35 @@ export type ArmorPiercingLayer = gap: number; }; +export const SORT_NAMES = { + 'meta.tier': 'tier', + 'meta.name': 'name', + 'survivability.health': 'health', + 'survivability.viewRange': 'view range', + 'survivability.camouflageStill': 'camouflage still', + 'survivability.camouflageMoving': 'camouflage moving', + 'survivability.camouflageShooting': 'camouflage shooting', + 'survivability.size': 'size', + 'fire.dpm': 'DPM', + 'fire.reload': 'reload', + 'fire.caliber': 'caliber', + 'fire.standardPenetration': 'standard penetration', + 'fire.premiumPenetration': 'premium penetration', + 'fire.damage': 'damage', + 'fire.shellVelocity': 'shell velocity', + 'fire.aimTime': 'aim time', + 'fire.dispersionStill': 'dispersion still', + 'fire.dispersionMoving': 'dispersion moving', + 'fire.gunDepression': 'gun depression', + 'fire.gunElevation': 'gun elevation', + 'maneuverability.forwardsSpeed': 'forwards speed', + 'maneuverability.backwardsSpeed': 'backwards speed', + 'maneuverability.power': 'power', + 'maneuverability.powerToWeight': 'power to weight', + 'maneuverability.weight': 'weight', + 'maneuverability.traverseSpeed': 'traverse speed', +} as const; + export const useTankopediaPersistent = create()( persist( subscribeWithSelector(() => ({