better hydrating recent tanks list

This commit is contained in:
tresabhi committed 2026-11-21 20:24:47 -06:00
1 parent 16ff393ea0
commit 8dd412ed32
5 files changed
+63 -14

No files matched your search

+1
View File
@@ -809,6 +809,7 @@
"login": "Login to use this", "login": "Login to use this",
"search_bar_hint": "Search tanks...", "search_bar_hint": "Search tanks...",
"recent": "Recently viewed", "recent": "Recently viewed",
"recent_empty": "Tanks you view will show up here",
"select_all": "Select all", "select_all": "Select all",
"count_singular": "1 tank", "count_singular": "1 tank",
"count_plural": "{count} tanks", "count_plural": "{count} tanks",
@@ -3,20 +3,38 @@
flex-direction: column; flex-direction: column;
gap: var(--space-4); gap: var(--space-4);
box-sizing: border-box;
padding: var(--space-4); padding: var(--space-4);
min-width: 100%;
background-color: var(--gray-a2);
border-radius: var(--space-3);
width: fit-content; width: fit-content;
background-color: var(--gray-a2);
border-radius: var(--space-3);
.list { .list {
--min-tank-card-size: 7rem;
display: flex; display: flex;
gap: var(--space-4); gap: var(--space-4);
width: fit-content; width: 100%;
min-width: fit-content;
--min-tank-card-size: 7rem; &[data-empty="true"] {
position: relative;
}
.placeholder {
visibility: hidden;
}
.message {
position: absolute;
inset: 0;
display: flex;
justify-content: center;
align-items: center;
}
} }
} }
@@ -2,11 +2,14 @@ import { isEqual } from "lodash-es";
import { useMemo } from "react"; import { useMemo } from "react";
import { api } from "../../api/dynamic"; import { api } from "../../api/dynamic";
import { withLocale } from "../../hocs/withLocale"; import { withLocale } from "../../hocs/withLocale";
import { useMounted } from "../../hooks/useMounted";
import { useStrings } from "../../hooks/useStrings"; import { useStrings } from "../../hooks/useStrings";
import { TankFilters } from "../../stores/tankFilters"; import { TankFilters } from "../../stores/tankFilters";
import { TankopediaPersistent } from "../../stores/tankopediaPersistent"; import { TankopediaPersistent } from "../../stores/tankopediaPersistent";
import { TankSort } from "../../stores/tankopediaSort"; import { TankSort } from "../../stores/tankopediaSort";
import { TankCard } from "../TankCard"; import { TankCard } from "../TankCard";
import { TankCardSkeleton } from "../TankCardSkeleton";
import { MAX_RECENTLY_VIEWED } from "../TankSearchResults/constants";
import { Text } from "../Text"; import { Text } from "../Text";
import styles from "./index.module.css"; import styles from "./index.module.css";
@@ -15,6 +18,7 @@ const tankDefinitions = await api.tanks();
export const RecentlyViewedTanks = withLocale(Content); export const RecentlyViewedTanks = withLocale(Content);
function Content() { function Content() {
const mounted = useMounted();
const filters = TankFilters.use(); const filters = TankFilters.use();
// 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 = TankopediaPersistent.state.recentlyViewed.filter( const recentlyViewed = TankopediaPersistent.state.recentlyViewed.filter(
@@ -34,7 +38,7 @@ function Content() {
const strings = useStrings(); const strings = useStrings();
const by = TankSort.use((state) => state.by); const by = TankSort.use((state) => state.by);
if (recentlyViewed.length === 0 || by !== null || hasFilters) { if (by !== null || hasFilters) {
return null; return null;
} }
@@ -44,10 +48,29 @@ function Content() {
{strings.website.common.tank_search.recent} {strings.website.common.tank_search.recent}
</Text> </Text>
<div className={styles.list}> <div
{recentlyViewed.map((id) => ( className={styles.list}
<TankCard compact tank={tankDefinitions.tanks[id]} key={id} /> data-empty={mounted && recentlyViewed.length === 0}
))} >
{!mounted &&
Array.from({ length: MAX_RECENTLY_VIEWED }, (_, index) => (
<TankCardSkeleton compact key={index} />
))}
{mounted && recentlyViewed.length === 0 && (
<>
<TankCardSkeleton compact className={styles.placeholder} />
<Text color="gray" lowContrast className={styles.message}>
{strings.website.common.tank_search.recent_empty}
</Text>
</>
)}
{mounted &&
recentlyViewed.map((id) => (
<TankCard compact tank={tankDefinitions.tanks[id]} key={id} />
))}
</div> </div>
</div> </div>
); );
@@ -1,4 +1,6 @@
.wrapper { .wrapper {
min-width: var(--min-tank-card-size);
--image-height: 6rem; --image-height: 6rem;
&[data-compact="true"] { &[data-compact="true"] {
@@ -6,9 +6,14 @@ import styles from "./index.module.css";
type TankCardProps = { type TankCardProps = {
compact?: boolean; compact?: boolean;
onIntersection?: () => void; onIntersection?: () => void;
className?: string;
}; };
export const TankCardSkeleton = ({ compact, onIntersection }: TankCardProps) => { export const TankCardSkeleton = ({
compact,
onIntersection,
className,
}: TankCardProps) => {
const wrapper = useRef<HTMLDivElement>(null); const wrapper = useRef<HTMLDivElement>(null);
useEffect(() => { useEffect(() => {
@@ -26,7 +31,7 @@ export const TankCardSkeleton = ({ compact, onIntersection }: TankCardProps) =>
return ( return (
<div <div
ref={wrapper} ref={wrapper}
className={styles.wrapper} className={`${styles.wrapper} ${className ?? ""}`}
data-compact={compact} data-compact={compact}
style={{ style={{
display: "flex", display: "flex",