Files
blitzkit/packages/website/src/components/Tankopedia/CalloutsSection.tsx
T

58 lines
1.9 KiB
TypeScript
Raw Normal View History

2025-01-17 20:29:33 -06:00
import { assertSecret, fetchTankDefinitions } from '@blitzkit/core';
2024-08-28 18:08:23 -05:00
import { MinusCircledIcon } from '@radix-ui/react-icons';
import { Callout, Flex } from '@radix-ui/themes';
2024-11-12 21:53:22 -06:00
import { uniq } from 'lodash-es';
import { useEffect } from 'react';
2024-09-22 22:04:03 -05:00
import { Duel } from '../../stores/duel';
2024-11-12 21:53:22 -06:00
import { TankopediaPersistent } from '../../stores/tankopediaPersistent';
2024-11-22 10:50:35 -06:00
import { AesonPlug } from '../AesonPlug';
2024-09-22 22:04:03 -05:00
import { ExperimentIcon } from '../ExperimentIcon';
2024-11-12 21:53:22 -06:00
import { MAX_RECENTLY_VIEWED } from '../TankSearch/constants';
2024-08-28 18:08:23 -05:00
2025-01-17 20:29:33 -06:00
const tankDefinitions = await fetchTankDefinitions();
2024-08-28 18:08:23 -05:00
export function CalloutsSection() {
const tank = Duel.use((state) => state.protagonist.tank);
2024-11-12 21:53:22 -06:00
const mutateTankopediaPersistent = TankopediaPersistent.useMutation();
2024-11-22 10:50:35 -06:00
const promoteAeson =
2025-06-08 17:32:13 +00:00
assertSecret(import.meta.env.PUBLIC_BRANCH) === 'preview';
2024-11-12 21:53:22 -06:00
useEffect(() => {
mutateTankopediaPersistent((draft) => {
2025-01-17 20:29:33 -06:00
draft.recentlyViewed = uniq([tank.id, ...draft.recentlyViewed])
.filter((id) => id in tankDefinitions.tanks)
.slice(0, MAX_RECENTLY_VIEWED);
2024-11-12 21:53:22 -06:00
});
}, [tank]);
2024-08-28 18:08:23 -05:00
2024-11-22 10:50:35 -06:00
if (!tank.testing && !tank.deprecated && !promoteAeson) return null;
2024-08-28 18:08:23 -05:00
return (
2024-11-29 13:29:22 -06:00
<Flex direction="column" align="center" gap="2" mb="4" px="4">
2024-11-24 20:39:21 -06:00
{promoteAeson && <AesonPlug />}
2024-11-22 10:50:35 -06:00
2024-08-28 18:08:23 -05:00
{tank.deprecated && (
<Callout.Root color="red">
<Callout.Icon>
<MinusCircledIcon />
</Callout.Icon>
<Callout.Text>
2024-11-29 13:29:22 -06:00
Deprecated tanks may display undefined behavior.
2024-08-28 18:08:23 -05:00
</Callout.Text>
</Callout.Root>
)}
{tank.testing && (
<Callout.Root color="red">
<Callout.Icon>
<ExperimentIcon style={{ width: '1em', height: '1em' }} />
</Callout.Icon>
<Callout.Text>
Tanks in testing are subject to change and may not represent the
final product.
</Callout.Text>
</Callout.Root>
)}
</Flex>
);
}