mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-29 04:44:23 +01:00
compiling search
This commit is contained in:
1 parent
edc3aba545
commit
b400ff6d07
12 files changed
+213
-228
No files matched your search
@@ -0,0 +1,3 @@
|
||||
.recent {
|
||||
/* mt="2" mb="6" */
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { isEqual } from "lodash-es";
|
||||
import { useMemo } from "react";
|
||||
import { api } from "../../core/blitzkit/api";
|
||||
import { useLocale } from "../../hooks/useLocale";
|
||||
import { TankFilters } from "../../stores/tankFilters";
|
||||
import { TankopediaPersistent } from "../../stores/tankopediaPersistent";
|
||||
import { TankSort } from "../../stores/tankopediaSort";
|
||||
import { Flex } from "../Flex";
|
||||
import { Separator } from "../Separator";
|
||||
import { TankCard } from "../TankCard";
|
||||
import { TankCardWrapper } from "../TankCardWrapper";
|
||||
import { Text } from "../Text";
|
||||
import styles from "./index.module.css";
|
||||
|
||||
const tankDefinitions = await api.tankDefinitions();
|
||||
|
||||
export function RecentlyViewedTanks() {
|
||||
const filters = TankFilters.use();
|
||||
// non-reactive because it is a little weird that it updates instantly even before the page loads
|
||||
const recentlyViewed = TankopediaPersistent.state.recentlyViewed.filter(
|
||||
(id) => id in tankDefinitions.tanks,
|
||||
);
|
||||
const hasFilters = useMemo(
|
||||
() =>
|
||||
Object.entries(filters).some(([key, value]) => {
|
||||
return !isEqual(
|
||||
value,
|
||||
TankFilters.initial[key as keyof typeof TankFilters.initial],
|
||||
);
|
||||
}),
|
||||
[filters],
|
||||
);
|
||||
const { strings } = useLocale();
|
||||
const by = TankSort.use((state) => state.by);
|
||||
|
||||
if (recentlyViewed.length === 0 || by !== "meta.none" || hasFilters) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Flex column gap="2" className={styles.recent}>
|
||||
<Text color="gray" align="center">
|
||||
{strings.website.common.tank_search.recent}
|
||||
</Text>
|
||||
<TankCardWrapper>
|
||||
{recentlyViewed.map((id) => (
|
||||
<TankCard tank={tankDefinitions.tanks[id]} key={id} />
|
||||
))}
|
||||
</TankCardWrapper>
|
||||
|
||||
<Separator />
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user