diff --git a/src/components/Posters/CollectionPreview.tsx b/src/components/Posters/CollectionPreview.tsx new file mode 100644 index 0000000..4ff61d4 --- /dev/null +++ b/src/components/Posters/CollectionPreview.tsx @@ -0,0 +1,84 @@ +import { AnimatePresence, motion } from 'framer-motion'; +import React, { memo } from 'react'; +import Image from 'next/image'; + +type CollectionItem = { + collectionName: string; + collection: { + id: number; + title: string; + subtitle: string; + url: string; + alt: string; + }[]; +}; + +type Props = { + selectedId: number | null; + setSelectedId: React.Dispatch>; + collection: CollectionItem[]; +}; + +// eslint-disable-next-line react/display-name +const CollectionPreview: React.FC = memo(({ selectedId, setSelectedId, collection }: Props) => { + const [selectedItem, setSelectedItem] = React.useState<{ id: number; url: string; alt: string } | null>(null); + + const handleClick = (item: { id: number; url: string; alt: string }) => { + if (selectedItem && selectedItem.id === item.id) { + // If the same item is clicked again, close the modal + setSelectedId(null); + setSelectedItem(null); + } else { + setSelectedId(item.id); + setSelectedItem(item); + } + }; + + return ( + <> + {collection.map((collectionItem) => ( +
+
{collectionItem.collectionName}
+
+ {collectionItem.collection.map((item) => ( + handleClick(item)} + className={`imageNeon relative w-36 h-48 shadow-[0px_0px_20px_2px_#fff] rounded-lg ease-in transition-all duration-300 ${selectedId === item.id ? 'border-4 border-purple-500' : '' + }`} + > + {item.alt} + + ))} +
+ + + {selectedItem && ( + + {selectedItem.alt} + +
handleClick(selectedItem)}> + + + +
+
+
+ + + )} +
+
+ ))} + + ); +}); + +export default CollectionPreview; diff --git a/src/components/Posters/posterCollectionApi.ts b/src/components/Posters/posterCollectionApi.ts new file mode 100644 index 0000000..be58d97 --- /dev/null +++ b/src/components/Posters/posterCollectionApi.ts @@ -0,0 +1,54 @@ +export const posterApi = [ + { + collectionName: 'Human Animals', + collection: [ + { + id: 8372982, + title: 'Uno', + subtitle: 'Dos', + url: 'https://raw.githubusercontent.com/MatthysDev/Matthys.Dev/main/src/images/posters/shark.png', + alt: 'oui', + }, + { + id: 823239, + title: 'Uno', + subtitle: 'Dos', + url: 'https://raw.githubusercontent.com/MatthysDev/Matthys.Dev/main/src/images/posters/shark.png', + alt: 'oui', + }, + { + id: 637829, + title: 'Uno', + subtitle: 'Dos', + url: 'https://raw.githubusercontent.com/MatthysDev/Matthys.Dev/main/src/images/posters/shark.png', + alt: 'oui', + }, + { + id: 9093738, + title: 'Uno', + subtitle: 'Dos', + url: 'https://raw.githubusercontent.com/MatthysDev/Matthys.Dev/main/src/images/posters/shark.png', + alt: 'oui', + }, + { + id: 137929, + title: 'Uno', + subtitle: 'Dos', + url: 'https://raw.githubusercontent.com/MatthysDev/Matthys.Dev/main/src/images/posters/shark.png', + alt: 'oui', + } + ] + }, + { + collectionName: 'requin', + collection: [ + { + id: 1384749, + title: 'Uno', + subtitle: 'Dos', + url: 'https://raw.githubusercontent.com/MatthysDev/Matthys.Dev/main/src/images/posters/shark.png', + alt: 'oui', + }, + ] + }, +]; diff --git a/src/pages/posters.tsx b/src/pages/posters.tsx index 0c01e11..9e55b12 100644 --- a/src/pages/posters.tsx +++ b/src/pages/posters.tsx @@ -1,14 +1,18 @@ import { neonBlanc, neonPurple } from '@/components/neonStyles' -import React, { useEffect } from 'react' +import React, { useEffect, useState } from 'react' import Image from 'next/image' import { randomNeonColor } from '@/utils/randomNeonColor' import ImageGridContainer from '@/components/ImageGridContainer' import PosterGridHero from '@/components/PosterGridHero' import CustomLayout from '@/components/CustomLayout' +import CollectionPreview from '@/components/Posters/CollectionPreview' +import { posterApi } from '@/components/Posters/posterCollectionApi' type Props = {} export default function posters({ }: Props) { + // eslint-disable-next-line react-hooks/rules-of-hooks + const [selectedId, setSelectedId] = useState(null); // eslint-disable-next-line react-hooks/rules-of-hooks useEffect(() => { randomNeonColor('imageNeon'); @@ -31,6 +35,13 @@ export default function posters({ }: Props) { +
+ +