diff --git a/components/ToolMain.tsx b/components/ToolMain.tsx index d8227da..ca23e19 100644 --- a/components/ToolMain.tsx +++ b/components/ToolMain.tsx @@ -1,16 +1,20 @@ -import { Avatar, Badge, Button, Carousel, Spinner } from "flowbite-react"; +import { Avatar, Badge, Button, Carousel, Modal, Spinner } from "flowbite-react"; import Link from "next/link"; import { MDXRemote } from 'next-mdx-remote' -import { Suspense } from "react"; +import { Suspense, useState } from "react"; import { FaExclamationCircle, FaGithub, FaLink, FaStar, FaTwitter } from "react-icons/fa"; import { RiFilePaper2Fill } from "react-icons/ri"; import { CgGitFork } from "react-icons/cg"; import EmbeddedSearchbar from "./EmbeddedSearchbar"; import Image from "next/image"; import ImageNotLoaded from "../assets/ImageNotLoaded.png"; +import Vibrant from "node-vibrant" export default function ToolMain(props: any) { + const [vibrantColors, setVibrantColors] = useState([]); + const [modals, setModal] = useState([]); + // Show the tool page depending on the id of the tool return (
@@ -24,7 +28,7 @@ export default function ToolMain(props: any) { {`Logo
-

+

{props.toolData.tool_name}

@@ -69,14 +73,63 @@ export default function ToolMain(props: any) {
}> { + props.toolData.tool_images.length > 0 ? ( props.toolData.tool_images.map((image: any, index: number) => { return ( -
+
+ { + let modifiedArray = [...modals]; + modifiedArray[index] = false + setModal(modifiedArray); + }} + size="4xl" + > + + Image {index + 1} + + +
+ {`Image +
+
+ + Image owner: {props.toolData.tool_name} + +
{ + Vibrant.from(image.image_link).getPalette().then(p => { + setModal(prevState => { + let newState = [...prevState] + newState[index] = false + return newState + }) + setVibrantColors(prevState => { + // Thanks to @taubi19 on https://stackoverflow.com/questions/60754088/how-to-update-a-state-array-multiple-times-faster-than-the-setstate-without-over + let newState = [...prevState]; + newState[index] = p.Vibrant?.getHex() ?? "rgba(255,255,255,0.5)"; + return newState; + }) + }) + }} + onClick={(e) => { + let modifiedArray = [...modals] + modifiedArray[index] = true; + setModal(modifiedArray); + }} objectFit="contain" onError={(e: any) => { e.target.src = ImageNotLoaded }} alt={props.toolData.tool_name} diff --git a/package.json b/package.json index fc7e459..08ef7a4 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "next": "12.1.6", "next-mdx-remote": "^4.0.3", "next-seo": "^5.4.0", + "node-vibrant": "^3.1.6", "react": "18.1.0", "react-dom": "18.1.0", "react-icons": "^4.3.1", diff --git a/tsconfig.json b/tsconfig.json index 99710e8..334af7f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "allowJs": true, "skipLibCheck": true, "strict": true, + "allowSyntheticDefaultImports": true, "forceConsistentCasingInFileNames": true, "noEmit": true, "esModuleInterop": true,