mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-22 05:15:32 +01:00
better hydrating recent tanks list
This commit is contained in:
5 files changed
+63
-14
No files matched your search
@@ -809,6 +809,7 @@
|
||||
"login": "Login to use this",
|
||||
"search_bar_hint": "Search tanks...",
|
||||
"recent": "Recently viewed",
|
||||
"recent_empty": "Tanks you view will show up here",
|
||||
"select_all": "Select all",
|
||||
"count_singular": "1 tank",
|
||||
"count_plural": "{count} tanks",
|
||||
|
||||
@@ -3,20 +3,38 @@
|
||||
flex-direction: column;
|
||||
gap: var(--space-4);
|
||||
|
||||
box-sizing: border-box;
|
||||
padding: var(--space-4);
|
||||
|
||||
background-color: var(--gray-a2);
|
||||
|
||||
border-radius: var(--space-3);
|
||||
|
||||
min-width: 100%;
|
||||
width: fit-content;
|
||||
|
||||
background-color: var(--gray-a2);
|
||||
border-radius: var(--space-3);
|
||||
|
||||
.list {
|
||||
--min-tank-card-size: 7rem;
|
||||
|
||||
display: flex;
|
||||
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 { api } from "../../api/dynamic";
|
||||
import { withLocale } from "../../hocs/withLocale";
|
||||
import { useMounted } from "../../hooks/useMounted";
|
||||
import { useStrings } from "../../hooks/useStrings";
|
||||
import { TankFilters } from "../../stores/tankFilters";
|
||||
import { TankopediaPersistent } from "../../stores/tankopediaPersistent";
|
||||
import { TankSort } from "../../stores/tankopediaSort";
|
||||
import { TankCard } from "../TankCard";
|
||||
import { TankCardSkeleton } from "../TankCardSkeleton";
|
||||
import { MAX_RECENTLY_VIEWED } from "../TankSearchResults/constants";
|
||||
import { Text } from "../Text";
|
||||
import styles from "./index.module.css";
|
||||
|
||||
@@ -15,6 +18,7 @@ const tankDefinitions = await api.tanks();
|
||||
export const RecentlyViewedTanks = withLocale(Content);
|
||||
|
||||
function Content() {
|
||||
const mounted = useMounted();
|
||||
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(
|
||||
@@ -34,7 +38,7 @@ function Content() {
|
||||
const strings = useStrings();
|
||||
const by = TankSort.use((state) => state.by);
|
||||
|
||||
if (recentlyViewed.length === 0 || by !== null || hasFilters) {
|
||||
if (by !== null || hasFilters) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -44,10 +48,29 @@ function Content() {
|
||||
{strings.website.common.tank_search.recent}
|
||||
</Text>
|
||||
|
||||
<div className={styles.list}>
|
||||
{recentlyViewed.map((id) => (
|
||||
<TankCard compact tank={tankDefinitions.tanks[id]} key={id} />
|
||||
))}
|
||||
<div
|
||||
className={styles.list}
|
||||
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>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
.wrapper {
|
||||
min-width: var(--min-tank-card-size);
|
||||
|
||||
--image-height: 6rem;
|
||||
|
||||
&[data-compact="true"] {
|
||||
|
||||
@@ -6,9 +6,14 @@ import styles from "./index.module.css";
|
||||
type TankCardProps = {
|
||||
compact?: boolean;
|
||||
onIntersection?: () => void;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export const TankCardSkeleton = ({ compact, onIntersection }: TankCardProps) => {
|
||||
export const TankCardSkeleton = ({
|
||||
compact,
|
||||
onIntersection,
|
||||
className,
|
||||
}: TankCardProps) => {
|
||||
const wrapper = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -26,7 +31,7 @@ export const TankCardSkeleton = ({ compact, onIntersection }: TankCardProps) =>
|
||||
return (
|
||||
<div
|
||||
ref={wrapper}
|
||||
className={styles.wrapper}
|
||||
className={`${styles.wrapper} ${className ?? ""}`}
|
||||
data-compact={compact}
|
||||
style={{
|
||||
display: "flex",
|
||||
|
||||
Reference in new issue
Block a user