diff --git a/public/bg-watermelon-v1.webp b/public/bg-watermelon-v1.webp new file mode 100644 index 0000000..f8c1db0 Binary files /dev/null and b/public/bg-watermelon-v1.webp differ diff --git a/src/app/page.tsx b/src/app/page.tsx index 09a9a3b..f677200 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,38 +1,58 @@ -'use client' -import { SocialPlatform } from '@/types'; -import download from 'downloadjs'; -import { toPng } from 'html-to-image'; -import Image from 'next/image'; +"use client"; +import { SocialPlatform } from "@/types"; +import download from "downloadjs"; +import { toPng } from "html-to-image"; +import Image from "next/image"; import { useEffect, useRef, useState } from "react"; -import { FaArrowRotateLeft, FaDownload, FaGithub, FaGitlab, FaShare, FaXTwitter } from "react-icons/fa6"; +import { + FaArrowRotateLeft, + FaDownload, + FaGithub, + FaGitlab, + FaShare, + FaXTwitter, +} from "react-icons/fa6"; export default function Home() { - const ref = useRef(null) + const ref = useRef(null); const [userImageUrl, setUserImageUrl] = useState(); + const [backgroundImageUrl, setBackgroundImageUrl] = + useState("/bg.webp"); const [unsuportedBrowser, setUnsupportedBrowser] = useState(false); - const [loader, setLoader] = useState(false) - const [gazaStatusSummary, setGazaStatusSummary] = useState() - const [filePostfix, setFilePostfix] = useState() + const [loader, setLoader] = useState(false); + const [gazaStatusSummary, setGazaStatusSummary] = useState(); + const [filePostfix, setFilePostfix] = useState< + SocialPlatform | "user-upload" + >(); useEffect(() => { const isInstagramBrowser = /Instagram/i.test(navigator.userAgent); const isFacebookBrowser = /FBAN|FBAV/i.test(navigator.userAgent); if (isInstagramBrowser || isFacebookBrowser) { - setUnsupportedBrowser(true) + setUnsupportedBrowser(true); } - }, [unsuportedBrowser]) + }, [unsuportedBrowser]); useEffect(() => { - fetch('/api/gaza-status').then(res => res.json()).then(data => setGazaStatusSummary(data.summary)); - }, [gazaStatusSummary]) + fetch("/api/gaza-status") + .then((res) => res.json()) + .then((data) => setGazaStatusSummary(data.summary)); + }, [gazaStatusSummary]); + const handleBgImageSwitch = () => { + if (backgroundImageUrl === "/bg.webp") { + setBackgroundImageUrl("/bg-watermelon-v1.webp"); + } else { + setBackgroundImageUrl("/bg.webp"); + } + }; const handleImageUpload = (e: any) => { const file = e.target.files[0]; const reader = new FileReader(); reader.onload = async (event: any) => { - setFilePostfix('user-upload') + setFilePostfix("user-upload"); setUserImageUrl(event.target.result); }; @@ -40,45 +60,49 @@ export default function Home() { }; const handleUploadButtonClick = () => { - document.getElementById('fileInput')?.click(); + document.getElementById("fileInput")?.click(); }; const handleRetrieveProfilePicture = async (platform: SocialPlatform) => { const userProvidedUsername = prompt(`Enter your ${platform} username:`); if (userProvidedUsername) { - setFilePostfix(platform) + setFilePostfix(platform); try { setLoader(true); - const response = await fetch(`/api/retrieve-profile-pic?username=${userProvidedUsername}&platform=${platform}`).then(res => res.ok ? res.json() : null); + const response = await fetch( + `/api/retrieve-profile-pic?username=${userProvidedUsername}&platform=${platform}` + ).then((res) => (res.ok ? res.json() : null)); setLoader(false); if (response === null) { - alert('Error fetching your profile picture. Please make sure that you entered a correct username.'); + alert( + "Error fetching your profile picture. Please make sure that you entered a correct username." + ); return; } setUserImageUrl(response.profilePicUrl); } catch (error) { - console.error('Error fetching profile picture:', error); + console.error("Error fetching profile picture:", error); } } }; const generateImage = async () => { try { - return await toPng(ref.current as HTMLElement) + return await toPng(ref.current as HTMLElement); } catch (error) { - console.log("Error generating image", error) + console.log("Error generating image", error); } - } + }; const handleDownload = async () => { - // TODO: Fix if possible. This is a hack to ensure that image generated is as expected. Without repeating generateImage(), at times, the image wont be generated correctly. - await generateImage() - await generateImage() - await generateImage() - const generatedImageUrl = await generateImage() + // TODO: Fix if possible. This is a hack to ensure that image generated is as expected. Without repeating generateImage(), at times, the image wont be generated correctly. + await generateImage(); + await generateImage(); + await generateImage(); + const generatedImageUrl = await generateImage(); if (generatedImageUrl) { - download(generatedImageUrl, `profile-pic-${filePostfix}.png`) + download(generatedImageUrl, `profile-pic-${filePostfix}.png`); } }; @@ -87,26 +111,43 @@ export default function Home() { }; return ( -
+
{unsuportedBrowser && ( -
-

⚠️ Unsupported Browser Detected

+
+

⚠️ Unsupported Browser Detected

Please open on regular browsers like Chrome or Safari.

)} {gazaStatusSummary && ( - + 😥 {gazaStatusSummary} → )} -

Show Solidarity 🇵🇸

-

Let's unite in our profile pictures to spotlight the cause. ✊

-

Watch the step-by-step guide 👀

+

Show Solidarity 🇵🇸

+ +

+ Let's unite in our profile pictures to spotlight the cause. ✊ +

+

+ Watch the{" "} + + step-by-step guide + {" "} + 👀 +

-
+
@@ -114,23 +155,25 @@ export default function Home() { border {loader ? ( spinner-animation @@ -138,15 +181,15 @@ export default function Home() { profile-image @@ -154,40 +197,106 @@ export default function Home() {
-
{userImageUrl ? ( - <> -

Download the image, then use it as your new profile picture.

- - - - ) : - <> - - - - - - - } +
+ {userImageUrl ? ( + <> +

+ Download the image, then use it as your new profile picture. +

+ + + + ) : ( + <> + + + + + + + + + + )}
-
-

Note: This app runs purely on your browser end. No images nor data will be saved by the app.

-

Have any feedback? Let me know!

-

For any bugs, please report them to our GitHub repository.

+
+

+ Note: This app runs purely on your browser end. No images nor data + will be saved by the app. +

+

+ Have any feedback?{" "} + + Let me know! + +

+

+ For any bugs, please report them to our{" "} + + {" "} + GitHub repository. + +

- ) + ); }