Files
blitzkit/packages/website/src/components/TankSearch/index.tsx
T

538 lines
19 KiB
TypeScript
Raw Normal View History

2024-09-06 22:05:06 -05:00
import {
2024-11-25 14:11:53 -06:00
metaSortTank,
normalizeBoundingBox,
resolveDpm,
unionBoundingBox,
2024-09-17 22:13:35 -05:00
type TankDefinition,
2024-09-06 22:05:06 -05:00
} from '@blitzkit/core';
2025-01-15 20:14:05 -06:00
import { literals } from '@blitzkit/i18n/src/literals';
2024-09-17 22:13:35 -05:00
import { useStore } from '@nanostores/react';
2024-10-13 00:26:38 -05:00
import { Callout, Flex, Link, Text, type FlexProps } from '@radix-ui/themes';
2024-09-17 22:13:35 -05:00
import fuzzysort from 'fuzzysort';
2024-11-11 10:50:15 -06:00
import { times, uniq } from 'lodash-es';
2024-10-18 10:24:39 -05:00
import { memo, useEffect, useMemo, useState } from 'react';
2024-11-29 13:20:27 -06:00
import { awaitableGameDefinitions } from '../../core/awaitables/gameDefinitions';
import { awaitableModelDefinitions } from '../../core/awaitables/modelDefinitions';
import { awaitableTankDefinitions } from '../../core/awaitables/tankDefinitions';
import { awaitableTankNames } from '../../core/awaitables/tankNames';
2024-09-17 22:13:35 -05:00
import { filterTank } from '../../core/blitzkit/filterTank';
import { resolveReload } from '../../core/blitzkit/resolveReload';
2025-01-07 13:50:06 -06:00
import { useLocale } from '../../hooks/useLocale';
2024-09-17 22:13:35 -05:00
import { $tankFilters } from '../../stores/tankFilters';
2024-11-11 10:50:15 -06:00
import { TankopediaPersistent } from '../../stores/tankopediaPersistent';
2025-01-07 13:50:06 -06:00
import { SORT_UNITS } from '../../stores/tankopediaPersistent/constants';
2024-09-17 22:13:35 -05:00
import { $tankopediaSort } from '../../stores/tankopediaSort';
import { ExperimentIcon } from '../ExperimentIcon';
2024-11-16 23:11:31 -06:00
import { TankSearchCard } from './components/Card';
2024-09-17 22:13:35 -05:00
import { FilterControl } from './components/FilterControl';
import { NoResults } from './components/NoResults';
2024-11-11 10:50:15 -06:00
import { RecentlyViewed } from './components/RecentlyViewed';
2024-09-17 22:13:35 -05:00
import { SearchBar } from './components/SearchBar';
import { SkeletonTankCard } from './components/SkeletonTankCard';
import { TankCardWrapper } from './components/TankCardWrapper';
2024-11-25 14:11:53 -06:00
import { MAX_RECENTLY_VIEWED } from './constants';
2024-01-21 11:06:40 -06:00
2024-06-25 20:05:41 -05:00
type TankSearchProps = Omit<FlexProps, 'onSelect'> & {
2024-01-21 11:06:40 -06:00
compact?: boolean;
onSelect?: (tank: TankDefinition) => void;
2024-06-25 19:24:33 -05:00
onSelectAll?: (tanks: TankDefinition[]) => void;
2024-06-25 19:58:29 -05:00
};
2024-01-21 11:06:40 -06:00
2024-12-16 13:30:35 -06:00
const PREVIEW_COUNT = 20;
const DEFAULT_LOADED_CARDS = 64;
2024-07-09 21:16:20 -05:00
2024-11-29 13:20:27 -06:00
const [gameDefinitions, modelDefinitions, tankDefinitions, tankNames] =
await Promise.all([
awaitableGameDefinitions,
awaitableModelDefinitions,
awaitableTankDefinitions,
awaitableTankNames,
]);
2024-09-21 12:16:51 -05:00
2024-06-25 19:24:33 -05:00
export const TankSearch = memo<TankSearchProps>(
2024-06-25 19:58:29 -05:00
({ compact, onSelect, onSelectAll, ...props }) => {
2025-01-07 13:50:06 -06:00
const { strings, locale } = useLocale();
2024-11-11 10:50:15 -06:00
const mutateTankopediaPersistent = TankopediaPersistent.useMutation();
2024-10-02 10:21:16 -05:00
const awaitedTanksDefinitionsArray = Object.values(tankDefinitions.tanks);
2024-09-17 22:13:35 -05:00
const tankFilters = useStore($tankFilters);
const tankopediaSort = useStore($tankopediaSort);
2024-09-17 22:50:34 -05:00
const tanksFiltered = useMemo(() => {
2024-09-17 22:13:35 -05:00
if (tankFilters.search === undefined) {
2024-06-25 19:24:33 -05:00
const filtered = awaitedTanksDefinitionsArray.filter((tank) =>
2024-09-17 22:13:35 -05:00
filterTank(tankFilters, tank),
2024-06-25 19:24:33 -05:00
);
let sorted: TankDefinition[];
2024-01-21 11:06:40 -06:00
2024-09-17 22:13:35 -05:00
switch (tankopediaSort.by) {
2024-06-25 19:24:33 -05:00
case 'meta.none':
2024-11-25 14:11:53 -06:00
sorted = metaSortTank(filtered, gameDefinitions);
2024-06-25 19:24:33 -05:00
break;
case 'survivability.health': {
sorted = filtered.sort((a, b) => {
const aHealth = a.health + a.turrets.at(-1)!.health;
const bHealth = b.health + b.turrets.at(-1)!.health;
return aHealth - bHealth;
});
break;
}
case 'survivability.viewRange':
sorted = filtered.sort(
2024-06-25 19:17:53 -05:00
(a, b) =>
2024-10-07 18:45:11 -05:00
a.turrets.at(-1)!.view_range - b.turrets.at(-1)!.view_range,
2024-06-25 19:24:33 -05:00
);
break;
case 'survivability.camouflageStill':
sorted = filtered.sort(
2024-10-07 18:45:11 -05:00
(a, b) => a.camouflage_still - b.camouflage_still,
2024-06-25 19:24:33 -05:00
);
break;
case 'survivability.camouflageMoving':
sorted = filtered.sort(
2024-10-07 18:45:11 -05:00
(a, b) => a.camouflage_moving - b.camouflage_moving,
2024-06-25 19:24:33 -05:00
);
break;
case 'survivability.camouflageShooting':
sorted = filtered.sort(
2024-06-25 19:17:53 -05:00
(a, b) =>
2024-10-07 18:45:11 -05:00
a.camouflage_still *
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base
.camouflage_loss -
b.camouflage_still *
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base
.camouflage_loss,
2024-06-25 19:24:33 -05:00
);
break;
case 'survivability.volume':
sorted = filtered.sort((a, b) => {
2024-10-02 10:21:16 -05:00
const aTankModelDefinition = modelDefinitions.models[a.id];
const bTankModelDefinition = modelDefinitions.models[b.id];
2024-06-25 19:24:33 -05:00
const aTurretModelDefinition =
aTankModelDefinition.turrets[a.turrets.at(-1)!.id];
const bTurretModelDefinition =
bTankModelDefinition.turrets[b.turrets.at(-1)!.id];
const aSize = normalizeBoundingBox(
unionBoundingBox(
2024-10-07 18:45:11 -05:00
aTankModelDefinition.bounding_box,
aTurretModelDefinition.bounding_box,
2024-06-25 19:24:33 -05:00
),
);
const bSize = normalizeBoundingBox(
unionBoundingBox(
2024-10-07 18:45:11 -05:00
bTankModelDefinition.bounding_box,
bTurretModelDefinition.bounding_box,
2024-06-25 19:24:33 -05:00
),
);
2024-10-05 23:20:04 -05:00
const aVolume = aSize.x * aSize.y * aSize.z;
const bVolume = bSize.x * bSize.y * bSize.z;
2024-06-25 19:24:33 -05:00
return aVolume - bVolume;
});
break;
case 'survivability.length':
sorted = filtered.sort((a, b) => {
2024-10-05 15:57:34 -05:00
const aTankModelDefinition = modelDefinitions.models[a.id];
const bTankModelDefinition = modelDefinitions.models[b.id];
2024-06-25 19:24:33 -05:00
const aTurretModelDefinition =
aTankModelDefinition.turrets[a.turrets.at(-1)!.id];
const bTurretModelDefinition =
bTankModelDefinition.turrets[b.turrets.at(-1)!.id];
const aSize = normalizeBoundingBox(
unionBoundingBox(
2024-10-07 18:45:11 -05:00
aTankModelDefinition.bounding_box,
aTurretModelDefinition.bounding_box,
2024-06-25 19:24:33 -05:00
),
);
const bSize = normalizeBoundingBox(
unionBoundingBox(
2024-10-07 18:45:11 -05:00
bTankModelDefinition.bounding_box,
bTurretModelDefinition.bounding_box,
2024-06-25 19:24:33 -05:00
),
);
2024-10-05 23:20:04 -05:00
const aLength = Math.max(aSize.x, aSize.y, aSize.z);
const bLength = Math.max(bSize.x, bSize.y, bSize.z);
2024-06-25 19:24:33 -05:00
return aLength - bLength;
});
break;
case 'fire.dpm':
sorted = filtered.sort(
2024-06-25 19:17:53 -05:00
(a, b) =>
2024-06-25 19:24:33 -05:00
resolveDpm(
a.turrets.at(-1)!.guns.at(-1)!,
2024-10-07 18:45:11 -05:00
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0],
2024-06-25 19:24:33 -05:00
) -
resolveDpm(
b.turrets.at(-1)!.guns.at(-1)!,
2024-10-07 18:45:11 -05:00
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0],
2024-06-25 19:24:33 -05:00
),
2024-06-25 19:17:53 -05:00
);
2024-06-25 19:24:33 -05:00
break;
2024-02-09 16:01:06 -06:00
2024-06-29 13:29:43 -05:00
case 'fire.dpmPremium':
sorted = filtered.sort(
(a, b) =>
2024-10-07 18:45:11 -05:00
(a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[1]
2024-06-29 13:29:43 -05:00
? resolveDpm(
a.turrets.at(-1)!.guns.at(-1)!,
2024-10-07 18:45:11 -05:00
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base
2024-10-05 15:57:34 -05:00
.shells[1],
2024-06-29 13:29:43 -05:00
)
: 0) -
2024-10-07 18:45:11 -05:00
(b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[1]
2024-06-29 13:29:43 -05:00
? resolveDpm(
b.turrets.at(-1)!.guns.at(-1)!,
2024-10-07 18:45:11 -05:00
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base
2024-10-05 15:57:34 -05:00
.shells[1],
2024-06-29 13:29:43 -05:00
)
: 0),
);
break;
2024-06-25 19:24:33 -05:00
case 'fire.reload':
sorted = filtered.sort(
(a, b) =>
resolveReload(a.turrets.at(-1)!.guns.at(-1)!) -
resolveReload(b.turrets.at(-1)!.guns.at(-1)!),
2024-06-25 19:17:53 -05:00
);
2024-06-25 19:24:33 -05:00
break;
case 'fire.caliber':
sorted = filtered.sort(
(a, b) =>
2024-10-07 18:45:11 -05:00
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
2024-10-05 15:57:34 -05:00
.caliber -
2024-10-07 18:45:11 -05:00
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
2024-10-05 15:57:34 -05:00
.caliber,
2024-06-25 19:17:53 -05:00
);
2024-06-25 19:24:33 -05:00
break;
2024-04-01 19:12:59 -05:00
2024-06-25 19:24:33 -05:00
case 'fire.standardPenetration':
sorted = filtered.sort(
(a, b) =>
2024-10-07 18:45:11 -05:00
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
2024-10-05 15:57:34 -05:00
.penetration.near -
2024-10-07 18:45:11 -05:00
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
2024-10-05 15:57:34 -05:00
.penetration.near,
2024-06-25 19:17:53 -05:00
);
2024-06-25 19:24:33 -05:00
break;
case 'fire.premiumPenetration':
sorted = filtered.sort(
(a, b) =>
2024-10-07 18:45:11 -05:00
(a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[1]
2024-10-05 15:57:34 -05:00
?.penetration.near ?? 0) -
2024-10-07 18:45:11 -05:00
(b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[1]
2024-10-05 15:57:34 -05:00
?.penetration.near ?? 0),
2024-06-25 19:17:53 -05:00
);
2024-06-25 19:24:33 -05:00
break;
2024-02-09 16:01:06 -06:00
2024-06-25 19:24:33 -05:00
case 'fire.damage':
sorted = filtered.sort(
(a, b) =>
2024-10-07 18:45:11 -05:00
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
.armor_damage -
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
.armor_damage,
2024-06-25 19:24:33 -05:00
);
break;
2024-02-09 16:01:06 -06:00
2024-11-09 19:22:21 -06:00
case 'fire.moduleDamage':
sorted = filtered.sort(
(a, b) =>
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
.module_damage -
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
.module_damage,
);
break;
2024-06-25 19:24:33 -05:00
case 'fire.shellVelocity':
sorted = filtered.sort(
(a, b) =>
2024-10-07 18:45:11 -05:00
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
2024-10-05 15:57:34 -05:00
.velocity -
2024-10-07 18:45:11 -05:00
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
2024-10-05 15:57:34 -05:00
.velocity,
2024-06-25 19:24:33 -05:00
);
break;
2024-02-09 16:01:06 -06:00
2024-11-09 16:00:15 -06:00
case 'fire.shellRange':
sorted = filtered.sort(
(a, b) =>
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
.range -
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
.range,
);
break;
2024-11-09 19:16:06 -06:00
case 'fire.shellCapacity':
sorted = filtered.sort(
(a, b) =>
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base
.shell_capacity -
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base
.shell_capacity,
);
break;
2024-06-25 19:24:33 -05:00
case 'fire.aimTime':
sorted = filtered.sort(
(a, b) =>
2024-10-07 18:45:11 -05:00
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.aim_time -
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.aim_time,
2024-06-25 19:24:33 -05:00
);
break;
2024-02-09 16:01:06 -06:00
2024-06-25 19:24:33 -05:00
case 'fire.dispersionStill':
sorted = filtered.sort(
(a, b) =>
2024-10-07 18:45:11 -05:00
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base
.dispersion_base -
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base
.dispersion_base,
2024-06-25 19:24:33 -05:00
);
break;
2024-02-09 16:01:06 -06:00
2024-06-25 19:24:33 -05:00
case 'fire.dispersionMoving':
sorted = filtered.sort(
(a, b) =>
2024-10-07 18:45:11 -05:00
a.tracks.at(-1)!.dispersion_move -
b.tracks.at(-1)!.dispersion_move,
2024-06-25 19:24:33 -05:00
);
break;
2024-02-09 16:01:06 -06:00
2024-06-25 19:24:33 -05:00
case 'fire.gunDepression':
sorted = filtered.sort(
(a, b) =>
2024-10-05 15:57:34 -05:00
modelDefinitions.models[a.id].turrets[a.turrets.at(-1)!.id]
2024-10-07 18:45:11 -05:00
.guns[a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.id]
2024-10-05 15:57:34 -05:00
.pitch.max +
2024-10-07 18:45:11 -05:00
(modelDefinitions.models[a.id].initial_turret_rotation?.pitch ??
2024-10-05 15:57:34 -05:00
0) -
modelDefinitions.models[b.id].turrets[b.turrets.at(-1)!.id]
2024-10-07 18:45:11 -05:00
.guns[b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.id]
2024-10-05 15:57:34 -05:00
.pitch.max -
2024-10-07 18:45:11 -05:00
(modelDefinitions.models[b.id].initial_turret_rotation?.pitch ??
2024-10-05 15:57:34 -05:00
0),
2024-06-25 19:24:33 -05:00
);
break;
2024-02-09 16:01:06 -06:00
2024-06-25 19:24:33 -05:00
case 'fire.gunElevation':
sorted = filtered.sort(
(a, b) =>
2024-10-05 15:57:34 -05:00
modelDefinitions.models[b.id].turrets[b.turrets.at(-1)!.id]
2024-10-07 18:45:11 -05:00
.guns[b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.id]
2024-10-05 15:57:34 -05:00
.pitch.min +
2024-10-07 18:45:11 -05:00
(modelDefinitions.models[b.id].initial_turret_rotation?.pitch ??
2024-10-05 15:57:34 -05:00
0) -
modelDefinitions.models[a.id].turrets[a.turrets.at(-1)!.id]
2024-10-07 18:45:11 -05:00
.guns[a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.id]
2024-10-05 15:57:34 -05:00
.pitch.min -
2024-10-07 18:45:11 -05:00
(modelDefinitions.models[a.id].initial_turret_rotation?.pitch ??
2024-10-05 15:57:34 -05:00
0),
2024-06-25 19:24:33 -05:00
);
break;
2024-02-09 16:01:06 -06:00
2024-06-25 19:24:33 -05:00
case 'maneuverability.forwardsSpeed':
2024-10-07 18:45:11 -05:00
sorted = filtered.sort(
(a, b) => a.speed_forwards - b.speed_forwards,
);
2024-06-25 19:24:33 -05:00
break;
2024-02-09 16:01:06 -06:00
2024-06-25 19:24:33 -05:00
case 'maneuverability.backwardsSpeed':
sorted = filtered.sort(
2024-10-07 18:45:11 -05:00
(a, b) => a.speed_backwards - b.speed_backwards,
2024-06-25 19:24:33 -05:00
);
break;
2024-02-09 16:01:06 -06:00
2024-06-25 19:24:33 -05:00
case 'maneuverability.power':
sorted = filtered.sort(
(a, b) => a.engines.at(-1)!.power - b.engines.at(-1)!.power,
);
break;
2024-02-09 16:01:06 -06:00
2024-06-25 19:24:33 -05:00
case 'maneuverability.powerToWeight':
sorted = filtered.sort(
(a, b) =>
a.engines.at(-1)!.power /
(a.weight +
a.engines.at(-1)!.weight +
a.tracks.at(-1)!.weight +
a.turrets.at(-1)!.weight +
2024-10-07 18:45:11 -05:00
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base
.weight) -
2024-06-25 19:24:33 -05:00
b.engines.at(-1)!.power /
(b.weight +
b.engines.at(-1)!.weight +
b.tracks.at(-1)!.weight +
b.turrets.at(-1)!.weight +
2024-10-07 18:45:11 -05:00
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.weight),
2024-06-25 19:24:33 -05:00
);
break;
2024-02-09 16:01:06 -06:00
2024-06-25 19:24:33 -05:00
case 'maneuverability.weight':
sorted = filtered.sort(
(a, b) =>
a.weight +
a.engines.at(-1)!.weight +
a.tracks.at(-1)!.weight +
a.turrets.at(-1)!.weight +
2024-10-07 18:45:11 -05:00
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.weight -
2024-06-25 19:17:53 -05:00
(b.weight +
b.engines.at(-1)!.weight +
b.tracks.at(-1)!.weight +
b.turrets.at(-1)!.weight +
2024-10-07 18:45:11 -05:00
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.weight),
2024-06-25 19:24:33 -05:00
);
break;
2024-06-25 19:17:53 -05:00
2024-06-25 19:24:33 -05:00
case 'maneuverability.traverseSpeed':
sorted = filtered.sort(
(a, b) =>
2024-10-07 18:45:11 -05:00
a.tracks.at(-1)!.traverse_speed -
b.tracks.at(-1)!.traverse_speed,
2024-06-25 19:24:33 -05:00
);
break;
}
2024-02-09 16:01:06 -06:00
2024-09-17 22:13:35 -05:00
return tankopediaSort.direction === 'ascending'
? sorted
: sorted.reverse();
2024-06-25 19:24:33 -05:00
} else {
2024-10-02 10:21:16 -05:00
const searchedRaw = fuzzysort.go(tankFilters.search, tankNames, {
2024-08-13 19:44:35 -05:00
keys: ['searchableName', 'searchableNameDeburr', 'camouflages'],
2024-06-25 19:24:33 -05:00
});
const searchedTanks = searchedRaw.map(
2024-10-05 15:57:34 -05:00
(result) => tankDefinitions.tanks[result.obj.id],
2024-06-25 19:24:33 -05:00
);
return searchedTanks;
2024-06-25 19:17:53 -05:00
}
2024-09-17 22:13:35 -05:00
}, [tankFilters, tankopediaSort]);
2024-11-25 14:16:33 -06:00
const [loadedCards, setLoadedCards] = useState(DEFAULT_LOADED_CARDS);
const tanks = tanksFiltered.slice(0, loadedCards);
2024-07-09 21:16:20 -05:00
useEffect(() => {
2024-11-25 14:16:33 -06:00
setLoadedCards(DEFAULT_LOADED_CARDS);
2024-09-17 22:13:35 -05:00
}, [tankFilters, tankopediaSort]);
2024-02-09 16:01:06 -06:00
2024-06-25 19:24:33 -05:00
return (
2024-06-25 19:58:29 -05:00
<Flex direction="column" gap="4" flexGrow="1" {...props}>
2024-06-28 20:17:47 -05:00
<SearchBar topResult={tanks?.[0]} onSelect={onSelect} />
2024-05-23 13:46:33 -05:00
2024-09-17 22:13:35 -05:00
{!tankFilters.search && !tankFilters.searching && (
2024-06-25 19:24:33 -05:00
<FilterControl compact={compact} />
)}
2024-04-06 22:00:40 -05:00
2024-11-13 10:38:59 -06:00
{!compact && <RecentlyViewed />}
2024-11-11 10:50:15 -06:00
2024-07-27 13:33:45 -05:00
<Flex mt="2" gap="1" align="center" justify="center" direction="column">
2024-07-22 20:24:32 -05:00
<Flex gap="2">
<Text color="gray">
2025-01-07 13:50:06 -06:00
{tanksFiltered.length === 1
? strings.website.common.tank_search.count_singular
: literals(strings.website.common.tank_search.count_plural, [
`${tanksFiltered.length.toLocaleString(locale)}`,
])}
2024-07-22 20:24:32 -05:00
</Text>
2024-01-21 11:06:40 -06:00
2024-06-25 19:24:33 -05:00
{onSelectAll && (
<Link
underline="always"
href="#"
onClick={(event) => {
event.preventDefault();
onSelectAll(tanksFiltered);
2024-11-11 10:50:15 -06:00
mutateTankopediaPersistent((draft) => {
draft.recentlyViewed = uniq([
...tanksFiltered.map(({ id }) => id),
...draft.recentlyViewed,
]).slice(0, MAX_RECENTLY_VIEWED);
});
}}
2024-06-25 19:24:33 -05:00
>
2025-01-07 13:50:06 -06:00
{strings.website.common.tank_search.select_all}
2024-06-25 19:24:33 -05:00
</Link>
)}
</Flex>
2024-07-22 20:24:32 -05:00
2024-09-17 22:13:35 -05:00
{tankopediaSort.by !== 'meta.none' && (
2024-07-22 20:24:32 -05:00
<Text color="gray">
2025-01-07 13:50:06 -06:00
{literals(strings.website.common.tank_search.sorting_by, [
strings.website.common.tank_search.sort[tankopediaSort.by],
])}
2024-09-17 22:13:35 -05:00
{SORT_UNITS[tankopediaSort.by] === undefined
2024-07-22 20:24:32 -05:00
? ''
2024-09-17 22:13:35 -05:00
: ` (${SORT_UNITS[tankopediaSort.by]})`}
, {tankopediaSort.direction}
2024-07-22 20:24:32 -05:00
</Text>
)}
</Flex>
2024-04-06 17:28:45 -05:00
2024-09-17 22:13:35 -05:00
{tankFilters.testing === 'only' && (
2024-06-25 19:24:33 -05:00
<Flex justify="center" mt="4">
<Callout.Root color="amber">
<Callout.Icon>
<ExperimentIcon style={{ width: '1em', height: '1em' }} />
</Callout.Icon>
<Callout.Text>
2025-01-07 13:50:06 -06:00
{strings.website.common.warnings.test}
2024-06-25 19:24:33 -05:00
</Callout.Text>
</Callout.Root>
</Flex>
)}
2024-06-25 19:17:53 -05:00
2024-09-17 22:13:35 -05:00
{!tankFilters.searching && (
2024-06-25 19:24:33 -05:00
<>
{tanks.length > 0 && (
<TankCardWrapper>
2024-10-18 10:24:39 -05:00
{tanks.map((tank) => (
2024-11-16 23:11:31 -06:00
<TankSearchCard
tank={tank}
key={tank.id}
onSelect={onSelect}
/>
2024-10-18 10:24:39 -05:00
))}
2024-07-09 21:16:20 -05:00
{times(
2024-11-25 14:16:33 -06:00
Math.min(PREVIEW_COUNT, tanksFiltered.length - loadedCards),
2024-07-09 21:16:20 -05:00
(index) => {
return (
<SkeletonTankCard
key={index}
onIntersection={() => {
2024-11-25 14:16:33 -06:00
setLoadedCards((state) =>
2024-07-09 21:16:20 -05:00
Math.min(state + 2, tanksFiltered.length),
);
}}
/>
);
},
)}
2024-06-25 19:24:33 -05:00
</TankCardWrapper>
)}
2024-06-25 19:17:53 -05:00
2024-06-25 19:24:33 -05:00
{tanks.length === 0 && <NoResults type="search" />}
</>
)}
2024-06-25 19:17:53 -05:00
2024-09-17 22:13:35 -05:00
{tankFilters.searching && (
2024-06-25 19:24:33 -05:00
<TankCardWrapper>
{times(Math.round(10 + 10 * Math.random()), (index) => (
<SkeletonTankCard key={index} />
))}
</TankCardWrapper>
)}
</Flex>
);
},
);