feat: instant model loading

This commit is contained in:
TrèsAbhi committed 2024-07-10 20:47:02 -05:00
1 parent db4c207708
commit 11e75e48ce
2 files changed
+32 -11

No files matched your search

@@ -1,7 +1,7 @@
import { ChevronLeftIcon, MixIcon } from '@radix-ui/react-icons'; import { ChevronLeftIcon, MixIcon } from '@radix-ui/react-icons';
import { Box, Button, Flex, Heading, Text } from '@radix-ui/themes'; import { Box, Button, Flex, Heading, Text } from '@radix-ui/themes';
import Link from 'next/link'; import Link from 'next/link';
import { Suspense } from 'react'; import { Suspense, useEffect, useState } from 'react';
import { classIcons } from '../../../../../../components/ClassIcon'; import { classIcons } from '../../../../../../components/ClassIcon';
import { TIER_ROMAN_NUMERALS } from '../../../../../../core/blitzkit/tankDefinitions/constants'; import { TIER_ROMAN_NUMERALS } from '../../../../../../core/blitzkit/tankDefinitions/constants';
import { useFullScreen } from '../../../../../../hooks/useFullScreen'; import { useFullScreen } from '../../../../../../hooks/useFullScreen';
@@ -20,6 +20,11 @@ export function HeroSection({ id }: { id: number }) {
: [protagonist.id, antagonist.id]; : [protagonist.id, antagonist.id];
const isFullScreen = useFullScreen(); const isFullScreen = useFullScreen();
const Icon = classIcons[protagonist.class]; const Icon = classIcons[protagonist.class];
const [dummyLoader, setDummyLoader] = useState(true);
useEffect(() => {
setDummyLoader(false);
}, []);
return ( return (
<Flex <Flex
@@ -49,6 +54,10 @@ export function HeroSection({ id }: { id: number }) {
height: '100%', height: '100%',
}} }}
> >
<Flex gap="4">
<Heading size={{ initial: '8', md: '9' }}>
<Icon style={{ width: '0.75em', height: '0.75em' }} />{' '}
</Heading>
<Heading <Heading
size={{ initial: '8', md: '9' }} size={{ initial: '8', md: '9' }}
align={{ initial: 'center', md: 'left' }} align={{ initial: 'center', md: 'left' }}
@@ -60,9 +69,9 @@ export function HeroSection({ id }: { id: number }) {
: undefined : undefined
} }
> >
<Icon style={{ width: '0.75em', height: '0.75em' }} />{' '}
{protagonist.name} {protagonist.name}
</Heading> </Heading>
</Flex>
<Text color="gray" ml={{ initial: '0', md: '9' }}> <Text color="gray" ml={{ initial: '0', md: '9' }}>
Tier {TIER_ROMAN_NUMERALS[protagonist.tier]}{' '} Tier {TIER_ROMAN_NUMERALS[protagonist.tier]}{' '}
@@ -73,7 +82,6 @@ export function HeroSection({ id }: { id: number }) {
}{' '} }{' '}
{strings.common.tank_class_short[protagonist.class]} {strings.common.tank_class_short[protagonist.class]}
</Text> </Text>
<Flex gap="4" ml={{ initial: '0', md: '9' }} mt="-1"> <Flex gap="4" ml={{ initial: '0', md: '9' }} mt="-1">
<Link href="/tools/tankopedia"> <Link href="/tools/tankopedia">
<Button variant="ghost" size="1" ml="-1"> <Button variant="ghost" size="1" ml="-1">
@@ -108,7 +116,19 @@ export function HeroSection({ id }: { id: number }) {
> >
<Box width="100%" height="100%" position="absolute"> <Box width="100%" height="100%" position="absolute">
<Box width="100%" height="100%"> <Box width="100%" height="100%">
<Suspense fallback={<TankSandboxLoader id={id} />}> <TankSandboxLoader
id={id}
display={dummyLoader ? 'flex' : 'none'}
/>
<Suspense
fallback={
<TankSandboxLoader
id={id}
display={dummyLoader ? 'none' : 'flex'}
/>
}
>
<TankSandbox /> <TankSandbox />
</Suspense> </Suspense>
</Box> </Box>
@@ -1,16 +1,17 @@
import { Flex, Progress } from '@radix-ui/themes'; import { Flex, FlexProps, Progress } from '@radix-ui/themes';
import { useProgress } from '@react-three/drei'; import { useProgress } from '@react-three/drei';
import { tankIcon } from '../../../../../../core/blitzkit/tankIcon'; import { tankIcon } from '../../../../../../core/blitzkit/tankIcon';
export function TankSandboxLoader({ id }: { id: number }) { type TankSandboxLoaderProps = Omit<FlexProps, 'id'> & {
id: number;
};
export function TankSandboxLoader({ id, ...props }: TankSandboxLoaderProps) {
const data = useProgress(); const data = useProgress();
return ( return (
<Flex width="100%" height="100%" align="center" justify="center"> <Flex width="100%" height="100%" align="center" justify="center" {...props}>
<img <img src={tankIcon(id)} style={{ height: '60%', filter: 'blur(4px)' }} />
src={tankIcon(id)}
style={{ height: '60%', filter: 'blur(4px) grayscale(1)' }}
/>
<Progress <Progress
size="3" size="3"
value={data.progress} value={data.progress}