mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
fix: handle deleted tanks
This commit is contained in:
1 parent
0ae59c2fd7
commit
3708a3ced7
4 files changed
+23
-12
No files matched your search
@@ -1,4 +1,9 @@
|
|||||||
import { asset, TankType, type TankDefinition } from '@blitzkit/core';
|
import {
|
||||||
|
asset,
|
||||||
|
fetchTankDefinitions,
|
||||||
|
TankType,
|
||||||
|
type TankDefinition,
|
||||||
|
} from '@blitzkit/core';
|
||||||
import { Flex, Text, type TextProps } from '@radix-ui/themes';
|
import { Flex, Text, type TextProps } from '@radix-ui/themes';
|
||||||
import { uniq } from 'lodash-es';
|
import { uniq } from 'lodash-es';
|
||||||
import { forwardRef, type ReactNode } from 'react';
|
import { forwardRef, type ReactNode } from 'react';
|
||||||
@@ -16,6 +21,8 @@ type TankCardProps = TextProps & {
|
|||||||
noLink?: boolean;
|
noLink?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const tankDefinitions = await fetchTankDefinitions();
|
||||||
|
|
||||||
export const TankCard = forwardRef<HTMLSpanElement, TankCardProps>(
|
export const TankCard = forwardRef<HTMLSpanElement, TankCardProps>(
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
@@ -49,10 +56,9 @@ export const TankCard = forwardRef<HTMLSpanElement, TankCardProps>(
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
onSelect?.(tank);
|
onSelect?.(tank);
|
||||||
mutateTankopediaPersistent((draft) => {
|
mutateTankopediaPersistent((draft) => {
|
||||||
draft.recentlyViewed = uniq([
|
draft.recentlyViewed = uniq([tank.id, ...draft.recentlyViewed])
|
||||||
tank.id,
|
.filter((id) => id in tankDefinitions.tanks)
|
||||||
...draft.recentlyViewed,
|
.slice(0, MAX_RECENTLY_VIEWED);
|
||||||
]).slice(0, MAX_RECENTLY_VIEWED);
|
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
className="tank-search-card"
|
className="tank-search-card"
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ export function RecentlyViewed() {
|
|||||||
const tankopediaPersistentStore = TankopediaPersistent.useStore();
|
const tankopediaPersistentStore = TankopediaPersistent.useStore();
|
||||||
const filters = useStore($tankFilters);
|
const filters = useStore($tankFilters);
|
||||||
// non-reactive because it is a little weird that it updates instantly even before the page loads
|
// non-reactive because it is a little weird that it updates instantly even before the page loads
|
||||||
const recentlyViewed = tankopediaPersistentStore.getState().recentlyViewed;
|
const recentlyViewed = tankopediaPersistentStore
|
||||||
|
.getState()
|
||||||
|
.recentlyViewed.filter((id) => id in tankDefinitions.tanks);
|
||||||
const sort = useStore($tankopediaSort);
|
const sort = useStore($tankopediaSort);
|
||||||
const hasFilters = useMemo(
|
const hasFilters = useMemo(
|
||||||
() =>
|
() =>
|
||||||
|
|||||||
@@ -456,7 +456,9 @@ export const TankSearch = memo<TankSearchProps>(
|
|||||||
draft.recentlyViewed = uniq([
|
draft.recentlyViewed = uniq([
|
||||||
...tanksFiltered.map(({ id }) => id),
|
...tanksFiltered.map(({ id }) => id),
|
||||||
...draft.recentlyViewed,
|
...draft.recentlyViewed,
|
||||||
]).slice(0, MAX_RECENTLY_VIEWED);
|
])
|
||||||
|
.filter((id) => id in tankDefinitions.tanks)
|
||||||
|
.slice(0, MAX_RECENTLY_VIEWED);
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { assertSecret } from '@blitzkit/core';
|
import { assertSecret, fetchTankDefinitions } from '@blitzkit/core';
|
||||||
import { MinusCircledIcon } from '@radix-ui/react-icons';
|
import { MinusCircledIcon } from '@radix-ui/react-icons';
|
||||||
import { Callout, Flex } from '@radix-ui/themes';
|
import { Callout, Flex } from '@radix-ui/themes';
|
||||||
import { uniq } from 'lodash-es';
|
import { uniq } from 'lodash-es';
|
||||||
@@ -9,6 +9,8 @@ import { AesonPlug } from '../AesonPlug';
|
|||||||
import { ExperimentIcon } from '../ExperimentIcon';
|
import { ExperimentIcon } from '../ExperimentIcon';
|
||||||
import { MAX_RECENTLY_VIEWED } from '../TankSearch/constants';
|
import { MAX_RECENTLY_VIEWED } from '../TankSearch/constants';
|
||||||
|
|
||||||
|
const tankDefinitions = await fetchTankDefinitions();
|
||||||
|
|
||||||
export function CalloutsSection() {
|
export function CalloutsSection() {
|
||||||
const tank = Duel.use((state) => state.protagonist.tank);
|
const tank = Duel.use((state) => state.protagonist.tank);
|
||||||
const mutateTankopediaPersistent = TankopediaPersistent.useMutation();
|
const mutateTankopediaPersistent = TankopediaPersistent.useMutation();
|
||||||
@@ -17,10 +19,9 @@ export function CalloutsSection() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
mutateTankopediaPersistent((draft) => {
|
mutateTankopediaPersistent((draft) => {
|
||||||
draft.recentlyViewed = uniq([tank.id, ...draft.recentlyViewed]).slice(
|
draft.recentlyViewed = uniq([tank.id, ...draft.recentlyViewed])
|
||||||
0,
|
.filter((id) => id in tankDefinitions.tanks)
|
||||||
MAX_RECENTLY_VIEWED,
|
.slice(0, MAX_RECENTLY_VIEWED);
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}, [tank]);
|
}, [tank]);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user