feat: sticky

This commit is contained in:
TrèsAbhi committed 2024-06-21 18:26:49 -05:00
1 parent a57734cdee
commit c8e207b6a2
2 files changed
+49 -35

No files matched your search

@@ -1,5 +1,5 @@
import { Flex, Grid, Heading, Separator } from '@radix-ui/themes'; import { Flex, Grid, Heading, Separator } from '@radix-ui/themes';
import { useEffect, useRef } from 'react'; import { memo, useEffect, useRef } from 'react';
import { import {
TankDefinition, TankDefinition,
Tier, Tier,
@@ -14,42 +14,47 @@ interface TierCardProps {
tanks: TankDefinition[]; tanks: TankDefinition[];
} }
export function TierCard({ tier, tanks }: TierCardProps) { export const TierCard = memo(
const container = useRef<HTMLDivElement>(null); ({ tier, tanks }: TierCardProps) => {
const container = useRef<HTMLDivElement>(null);
useEffect(() => { useEffect(() => {
const unsubscribe = useTankopediaFilters.subscribe((filters) => { const unsubscribe = useTankopediaFilters.subscribe((filters) => {
if (!container.current) return; if (!container.current) return;
const visible = tanks.some((tank) => tankopediaFilterTank(filters, tank)); const visible = tanks.some((tank) =>
container.current.style.display = visible ? 'flex' : 'none'; tankopediaFilterTank(filters, tank),
}); );
container.current.style.display = visible ? 'flex' : 'none';
});
return unsubscribe; return unsubscribe;
}, []); }, []);
return ( return (
<Flex <Flex
ref={container} ref={container}
direction="column" direction="column"
gap="4" gap="4"
display={tanks.length === 0 ? 'none' : 'flex'} display={tanks.length === 0 ? 'none' : 'flex'}
>
<Flex align="center" mb="4" gap="4">
<Heading weight="regular">Tier {TIER_ROMAN_NUMERALS[tier]}</Heading>
<Separator style={{ flex: 1 }} />
</Flex>
<Grid
flexGrow="1"
columns="repeat(auto-fill, minmax(100px, 1fr))"
gap="2"
gapY="6"
> >
{tanks.map((tank) => ( <Flex align="center" mb="4" gap="4">
<TankCard key={tank.id} tank={tank} /> <Heading weight="regular">Tier {TIER_ROMAN_NUMERALS[tier]}</Heading>
))} <Separator style={{ flex: 1 }} />
</Grid> </Flex>
</Flex>
); <Grid
} flexGrow="1"
columns="repeat(auto-fill, minmax(100px, 1fr))"
gap="2"
gapY="6"
>
{tanks.map((tank) => (
<TankCard key={tank.id} tank={tank} />
))}
</Grid>
</Flex>
);
},
(prev, next) => prev.tier === next.tier,
);
+9
View File
@@ -6,6 +6,7 @@ import { times } from 'lodash';
import { use } from 'react'; import { use } from 'react';
import { classIcons } from '../../../components/ClassIcon'; import { classIcons } from '../../../components/ClassIcon';
import { ExperimentIcon } from '../../../components/ExperimentIcon'; import { ExperimentIcon } from '../../../components/ExperimentIcon';
import { NAVBAR_HEIGHT } from '../../../components/Navbar';
import PageWrapper from '../../../components/PageWrapper'; import PageWrapper from '../../../components/PageWrapper';
import { ResearchedIcon } from '../../../components/ResearchedIcon'; import { ResearchedIcon } from '../../../components/ResearchedIcon';
import { ScienceIcon } from '../../../components/ScienceIcon'; import { ScienceIcon } from '../../../components/ScienceIcon';
@@ -44,6 +45,7 @@ export default function Page() {
initial: 'row', initial: 'row',
sm: 'column', sm: 'column',
}} }}
height="fit-content"
gap="2" gap="2"
align={{ align={{
initial: 'start', initial: 'start',
@@ -53,6 +55,13 @@ export default function Page() {
initial: 'center', initial: 'center',
sm: 'start', sm: 'start',
}} }}
position={{
initial: 'static',
sm: 'sticky',
}}
style={{
top: `calc(${NAVBAR_HEIGHT}px + var(--space-3))`,
}}
> >
<Flex <Flex
direction={{ direction={{