|
1 | | -'use client' |
2 | | - |
3 | | -import { useState } from 'react' |
4 | | -import { Card, CardBody, CardFooter, CardHeader } from '@heroui/card' |
5 | | -import { Chip } from '@heroui/chip' |
6 | | -import { Image } from '@heroui/image' |
7 | | -import { KunCardStats } from '~/components/kun/CardStats' |
8 | | -import Link from 'next/link' |
9 | | -import { KunPatchAttribute } from '~/components/kun/PatchAttribute' |
10 | | -import { cn } from '~/utils/cn' |
11 | | -import { GALGAME_AGE_LIMIT_MAP } from '~/constants/galgame' |
12 | | - |
13 | | -interface Props { |
14 | | - patch: GalgameCard |
15 | | -} |
16 | | - |
17 | | -export const GalgameCard = ({ patch }: Props) => { |
18 | | - const [imageLoaded, setImageLoaded] = useState(false) |
19 | | - |
20 | | - return ( |
21 | | - <Card |
22 | | - isPressable |
23 | | - as={Link} |
24 | | - href={`/patch/${patch.id}/introduction`} |
25 | | - className="w-full border border-default-100 dark:border-default-200" |
26 | | - > |
27 | | - <CardHeader className="p-0"> |
28 | | - <div className="relative w-full mx-auto overflow-hidden text-center rounded-t-lg opacity-90"> |
29 | | - <div |
30 | | - className={cn( |
31 | | - 'absolute inset-0 animate-pulse bg-default-100', |
32 | | - imageLoaded ? 'opacity-0' : 'opacity-90', |
33 | | - 'transition-opacity duration-300' |
34 | | - )} |
35 | | - style={{ aspectRatio: '16/9' }} |
36 | | - /> |
37 | | - <Image |
38 | | - radius="none" |
39 | | - alt={patch.name} |
40 | | - className={cn( |
41 | | - 'size-full object-cover transition-all duration-300', |
42 | | - imageLoaded ? 'scale-100 opacity-90' : 'scale-105 opacity-0' |
43 | | - )} |
44 | | - removeWrapper={true} |
45 | | - src={ |
46 | | - patch.banner |
47 | | - ? patch.banner.replace(/\.avif$/, '-mini.avif') |
48 | | - : '/kungalgame.avif' |
49 | | - } |
50 | | - style={{ aspectRatio: '16/9' }} |
51 | | - onLoad={() => setImageLoaded(true)} |
52 | | - /> |
53 | | - |
54 | | - <div className="absolute z-10 rounded-full bg-background left-2 top-2"> |
55 | | - <Chip |
56 | | - color={patch.content_limit === 'sfw' ? 'success' : 'danger'} |
57 | | - variant="flat" |
58 | | - > |
59 | | - {GALGAME_AGE_LIMIT_MAP[patch.content_limit]} |
60 | | - </Chip> |
61 | | - </div> |
62 | | - </div> |
63 | | - </CardHeader> |
64 | | - <CardBody className="justify-between space-y-2"> |
65 | | - <h2 className="font-semibold transition-colors text-medium sm:text-lg line-clamp-2 hover:text-primary-500"> |
66 | | - {patch.name} |
67 | | - </h2> |
68 | | - <KunCardStats patch={patch} /> |
69 | | - </CardBody> |
70 | | - <CardFooter className="pt-0"> |
71 | | - <KunPatchAttribute |
72 | | - types={patch.type} |
73 | | - languages={patch.language} |
74 | | - platforms={patch.platform} |
75 | | - size="sm" |
76 | | - /> |
77 | | - </CardFooter> |
78 | | - </Card> |
79 | | - ) |
80 | | -} |
| 1 | +'use client' |
| 2 | + |
| 3 | +import { useState } from 'react' |
| 4 | +import { Card, CardBody, CardFooter, CardHeader } from '@heroui/card' |
| 5 | +import { Chip } from '@heroui/chip' |
| 6 | +import { Image } from '@heroui/image' |
| 7 | +import { KunCardStats } from '~/components/kun/CardStats' |
| 8 | +import Link from 'next/link' |
| 9 | +import { KunPatchAttribute } from '~/components/kun/PatchAttribute' |
| 10 | +import { cn } from '~/utils/cn' |
| 11 | +import { GALGAME_AGE_LIMIT_MAP } from '~/constants/galgame' |
| 12 | +import { formatDistanceToNow } from '~/utils/formatDistanceToNow' |
| 13 | + |
| 14 | +interface Props { |
| 15 | + patch: GalgameCard |
| 16 | +} |
| 17 | + |
| 18 | +export const GalgameCard = ({ patch }: Props) => { |
| 19 | + const [imageLoaded, setImageLoaded] = useState(false) |
| 20 | + |
| 21 | + return ( |
| 22 | + <Card |
| 23 | + isPressable |
| 24 | + as={Link} |
| 25 | + href={`/patch/${patch.id}/introduction`} |
| 26 | + className="w-full border border-default-100 dark:border-default-200" |
| 27 | + > |
| 28 | + <CardHeader className="p-0"> |
| 29 | + <div className="relative w-full mx-auto overflow-hidden text-center rounded-t-lg opacity-90"> |
| 30 | + <div |
| 31 | + className={cn( |
| 32 | + 'absolute inset-0 animate-pulse bg-default-100', |
| 33 | + imageLoaded ? 'opacity-0' : 'opacity-90', |
| 34 | + 'transition-opacity duration-300' |
| 35 | + )} |
| 36 | + style={{ aspectRatio: '16/9' }} |
| 37 | + /> |
| 38 | + <Image |
| 39 | + radius="none" |
| 40 | + alt={patch.name} |
| 41 | + className={cn( |
| 42 | + 'size-full object-cover transition-all duration-300', |
| 43 | + imageLoaded ? 'scale-100 opacity-90' : 'scale-105 opacity-0' |
| 44 | + )} |
| 45 | + removeWrapper={true} |
| 46 | + src={ |
| 47 | + patch.banner |
| 48 | + ? patch.banner.replace(/\.avif$/, '-mini.avif') |
| 49 | + : '/kungalgame.avif' |
| 50 | + } |
| 51 | + style={{ aspectRatio: '16/9' }} |
| 52 | + onLoad={() => setImageLoaded(true)} |
| 53 | + /> |
| 54 | + |
| 55 | + <div className="absolute z-10 rounded-full bg-background left-2 top-2"> |
| 56 | + <Chip |
| 57 | + color={patch.content_limit === 'sfw' ? 'success' : 'danger'} |
| 58 | + variant="flat" |
| 59 | + > |
| 60 | + {GALGAME_AGE_LIMIT_MAP[patch.content_limit]} |
| 61 | + </Chip> |
| 62 | + </div> |
| 63 | + |
| 64 | + <div className="absolute z-10 rounded-full bg-background right-2 bottom-2"> |
| 65 | + <Chip size="sm" variant="flat"> |
| 66 | + {formatDistanceToNow(patch.created)} |
| 67 | + </Chip> |
| 68 | + </div> |
| 69 | + </div> |
| 70 | + </CardHeader> |
| 71 | + <CardBody className="justify-between space-y-2"> |
| 72 | + <h2 className="font-semibold transition-colors text-medium sm:text-lg line-clamp-2 hover:text-primary-500"> |
| 73 | + {patch.name} |
| 74 | + </h2> |
| 75 | + <KunCardStats patch={patch} /> |
| 76 | + </CardBody> |
| 77 | + <CardFooter className="pt-0"> |
| 78 | + <KunPatchAttribute |
| 79 | + types={patch.type} |
| 80 | + languages={patch.language} |
| 81 | + platforms={patch.platform} |
| 82 | + size="sm" |
| 83 | + /> |
| 84 | + </CardFooter> |
| 85 | + </Card> |
| 86 | + ) |
| 87 | +} |
0 commit comments