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 && ( + + )} + + ) +}