From 11150400aba1a8707b3063b4f325cd84c6ff0e4a Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Thu, 15 Feb 2024 13:23:20 -0800 Subject: [PATCH] fix snowfall --- src/app/author/[author]/AuthorDisplay.tsx | 40 +++-------------- src/app/author/[author]/KonamiSnowfall.tsx | 51 ++++++++++++++++++++++ 2 files changed, 56 insertions(+), 35 deletions(-) create mode 100644 src/app/author/[author]/KonamiSnowfall.tsx diff --git a/src/app/author/[author]/AuthorDisplay.tsx b/src/app/author/[author]/AuthorDisplay.tsx index e11ecb2..b0ce724 100644 --- a/src/app/author/[author]/AuthorDisplay.tsx +++ b/src/app/author/[author]/AuthorDisplay.tsx @@ -1,14 +1,12 @@ -'use client' import Link from 'next/link' -import { Fragment, useState } from 'react' +import { Fragment } from 'react' import { affiliations, nationalities, authors } from '../../db/data' import { Zilla_Slab } from 'next/font/google' import { notFound } from 'next/navigation' import DocumentCard from '@/app/components/DocumentCard' import findDocumentsByAuthor from './findDocumentsByAuthor' import cardEffects from '@/app/styles/cardEffects.module.css' -import Konami from 'react-konami-code' -import Snowfall from 'react-snowfall' +import KonamiSnowfall from './KonamiSnowfall' const zillaSlab = Zilla_Slab({ subsets: ['latin'], weight: ['500'] }) @@ -20,13 +18,9 @@ export default function AuthorDisplay({ notFound() } - const [snowfallActivated, setSnowfallActivated] = useState(false) const { name, affiliation, image, nationality, formerAffiliations } = data const authorsDocuments = findDocumentsByAuthor(author) - const handleKonami = () => { - setSnowfallActivated(!snowfallActivated) - } const MainPosition = () => { const mainAffiliationShort = affiliation[0].split('@')[1] @@ -34,33 +28,8 @@ export default function AuthorDisplay({ const mainAffiliation = affiliations[mainAffiliationShort] const { website } = data - const images: HTMLImageElement[] = [] - nationality.forEach((n) => { - const { flag } = nationalities[n] - const image = new Image() - image.src = flag - images.push(image) - }) - return ( <> - - {snowfallActivated && ( - - )} {mainPosition} at {mainAffiliation.name} @@ -173,7 +142,8 @@ export default function AuthorDisplay({ } return ( -
+ <> +
)}
-
+ ) } diff --git a/src/app/author/[author]/KonamiSnowfall.tsx b/src/app/author/[author]/KonamiSnowfall.tsx new file mode 100644 index 0000000..b96dc6b --- /dev/null +++ b/src/app/author/[author]/KonamiSnowfall.tsx @@ -0,0 +1,51 @@ +'use client' +import Konami from 'react-konami-code' +import { Snowfall } from 'react-snowfall' +import { useEffect, useState } from 'react' +import { nationalities } from '@/app/db/data' + +export default function KonamiSnowfall({ + nationalityList, +}: Readonly<{ + nationalityList: string[] +}>) { + const [snowfallActivated, setSnowfallActivated] = useState(false) + const [images, setImages] = useState([]) + + const handleKonami = () => { + setSnowfallActivated(!snowfallActivated) + } + + useEffect(() => { + const imagesTemp: HTMLImageElement[] = [] + nationalityList.forEach((n) => { + const { flag } = nationalities[n] + const image = new Image() + image.src = flag + imagesTemp.push(image) + }) + setImages(imagesTemp) + }, []) + + return ( + <> + + {snowfallActivated && ( + + )} + + ) +}