mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: sort
This commit is contained in:
1 parent
62d4ec07f0
commit
bae1e944b7
5 files changed
+50
-32
No files matched your search
@@ -43,5 +43,6 @@ export * from './uniqueGuns';
|
|||||||
export * from './unwrapBlitzkitResponse';
|
export * from './unwrapBlitzkitResponse';
|
||||||
export * from './votes';
|
export * from './votes';
|
||||||
// export * from './withCORSProxy';
|
// export * from './withCORSProxy';
|
||||||
|
export * from './metaSortTank';
|
||||||
export * from './romanize';
|
export * from './romanize';
|
||||||
export * from './youtubers';
|
export * from './youtubers';
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { TANK_CLASSES } from '../blitz/constants';
|
||||||
|
import { GameDefinitions, TankDefinition, TankType } from '../protos';
|
||||||
|
|
||||||
|
const treeTypeOrder = [
|
||||||
|
TankType.RESEARCHABLE,
|
||||||
|
TankType.PREMIUM,
|
||||||
|
TankType.COLLECTOR,
|
||||||
|
];
|
||||||
|
|
||||||
|
export function metaSortTank(
|
||||||
|
tanks: TankDefinition[],
|
||||||
|
gameDefinitions: GameDefinitions,
|
||||||
|
) {
|
||||||
|
return tanks
|
||||||
|
.sort((a, b) => b.tier - a.tier)
|
||||||
|
.sort(
|
||||||
|
(a, b) => treeTypeOrder.indexOf(b.type) - treeTypeOrder.indexOf(a.type),
|
||||||
|
)
|
||||||
|
.sort(
|
||||||
|
(a, b) => TANK_CLASSES.indexOf(b.class) - TANK_CLASSES.indexOf(a.class),
|
||||||
|
)
|
||||||
|
.sort(
|
||||||
|
(a, b) =>
|
||||||
|
gameDefinitions.nations.indexOf(b.nation) -
|
||||||
|
gameDefinitions.nations.indexOf(a.nation),
|
||||||
|
)
|
||||||
|
.sort((a, b) => a.tier - b.tier);
|
||||||
|
}
|
||||||
@@ -1,9 +1 @@
|
|||||||
import { TankType } from '@blitzkit/core';
|
|
||||||
|
|
||||||
export const treeTypeOrder = [
|
|
||||||
TankType.RESEARCHABLE,
|
|
||||||
TankType.PREMIUM,
|
|
||||||
TankType.COLLECTOR,
|
|
||||||
];
|
|
||||||
|
|
||||||
export const MAX_RECENTLY_VIEWED = 9;
|
export const MAX_RECENTLY_VIEWED = 9;
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
TANK_CLASSES,
|
|
||||||
fetchGameDefinitions,
|
fetchGameDefinitions,
|
||||||
fetchModelDefinitions,
|
fetchModelDefinitions,
|
||||||
fetchTankDefinitions,
|
fetchTankDefinitions,
|
||||||
fetchTankNames,
|
fetchTankNames,
|
||||||
|
metaSortTank,
|
||||||
normalizeBoundingBox,
|
normalizeBoundingBox,
|
||||||
resolveDpm,
|
resolveDpm,
|
||||||
unionBoundingBox,
|
unionBoundingBox,
|
||||||
@@ -31,7 +31,7 @@ import { RecentlyViewed } from './components/RecentlyViewed';
|
|||||||
import { SearchBar } from './components/SearchBar';
|
import { SearchBar } from './components/SearchBar';
|
||||||
import { SkeletonTankCard } from './components/SkeletonTankCard';
|
import { SkeletonTankCard } from './components/SkeletonTankCard';
|
||||||
import { TankCardWrapper } from './components/TankCardWrapper';
|
import { TankCardWrapper } from './components/TankCardWrapper';
|
||||||
import { MAX_RECENTLY_VIEWED, treeTypeOrder } from './constants';
|
import { MAX_RECENTLY_VIEWED } from './constants';
|
||||||
|
|
||||||
type TankSearchProps = Omit<FlexProps, 'onSelect'> & {
|
type TankSearchProps = Omit<FlexProps, 'onSelect'> & {
|
||||||
compact?: boolean;
|
compact?: boolean;
|
||||||
@@ -62,22 +62,7 @@ export const TankSearch = memo<TankSearchProps>(
|
|||||||
|
|
||||||
switch (tankopediaSort.by) {
|
switch (tankopediaSort.by) {
|
||||||
case 'meta.none':
|
case 'meta.none':
|
||||||
sorted = filtered
|
sorted = metaSortTank(filtered, gameDefinitions);
|
||||||
.sort((a, b) => b.tier - a.tier)
|
|
||||||
.sort(
|
|
||||||
(a, b) =>
|
|
||||||
treeTypeOrder.indexOf(b.type) - treeTypeOrder.indexOf(a.type),
|
|
||||||
)
|
|
||||||
.sort(
|
|
||||||
(a, b) =>
|
|
||||||
TANK_CLASSES.indexOf(b.class) - TANK_CLASSES.indexOf(a.class),
|
|
||||||
)
|
|
||||||
.sort(
|
|
||||||
(a, b) =>
|
|
||||||
gameDefinitions.nations.indexOf(b.nation) -
|
|
||||||
gameDefinitions.nations.indexOf(a.nation),
|
|
||||||
)
|
|
||||||
.sort((a, b) => a.tier - b.tier);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'survivability.health': {
|
case 'survivability.health': {
|
||||||
|
|||||||
@@ -1,23 +1,35 @@
|
|||||||
import { fetchTankDefinitions } from '@blitzkit/core';
|
import {
|
||||||
|
fetchGameDefinitions,
|
||||||
|
fetchTankDefinitions,
|
||||||
|
metaSortTank,
|
||||||
|
} from '@blitzkit/core';
|
||||||
import { useStore } from '@nanostores/react';
|
import { useStore } from '@nanostores/react';
|
||||||
|
import { useMemo } from 'react';
|
||||||
import { filterTank } from '../../core/blitzkit/filterTank';
|
import { filterTank } from '../../core/blitzkit/filterTank';
|
||||||
import { $tankFilters } from '../../stores/tankFilters';
|
import { $tankFilters } from '../../stores/tankFilters';
|
||||||
import { TankCardWrapper } from '../TankSearch/components/TankCardWrapper';
|
import { TankCardWrapper } from '../TankSearch/components/TankCardWrapper';
|
||||||
import { TierListTile } from './Tile';
|
import { TierListTile } from './Tile';
|
||||||
|
|
||||||
const tankDefinitions = await fetchTankDefinitions();
|
const tankDefinitions = await fetchTankDefinitions();
|
||||||
|
const gameDefinitions = await fetchGameDefinitions();
|
||||||
const tanks = Object.values(tankDefinitions.tanks);
|
const tanks = Object.values(tankDefinitions.tanks);
|
||||||
|
|
||||||
export function TierListTiles() {
|
export function TierListTiles() {
|
||||||
const filters = useStore($tankFilters);
|
const filters = useStore($tankFilters);
|
||||||
|
const sorted = useMemo(
|
||||||
|
() =>
|
||||||
|
metaSortTank(
|
||||||
|
tanks.filter((tank) => filterTank(filters, tank)),
|
||||||
|
gameDefinitions,
|
||||||
|
).reverse(),
|
||||||
|
[filters],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TankCardWrapper>
|
<TankCardWrapper>
|
||||||
{tanks
|
{sorted.map((tank) => (
|
||||||
.filter((tank) => filterTank(filters, tank))
|
<TierListTile key={tank.id} tank={tank} />
|
||||||
.map((tank, tileIndex) => (
|
))}
|
||||||
<TierListTile key={tank.id} tank={tank} />
|
|
||||||
))}
|
|
||||||
</TankCardWrapper>
|
</TankCardWrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user