From e29d7515c5e67be36d7dfee0d898336ddb7d201c Mon Sep 17 00:00:00 2001 From: JeelRajodiya Date: Sat, 3 Aug 2024 23:43:09 +0530 Subject: [PATCH] feat: feedback component closes #46 --- .../ContentViewer/ContentViewer.module.css | 2 +- .../ContentViewer/ContentViewer.tsx | 6 +- app/components/Feedback/Feedback.module.css | 4 + app/components/Feedback/Feedback.tsx | 75 +++++++++++++++++++ app/components/Feedback/index.tsx | 1 + app/styles/icons/BiDislike.tsx | 21 ++++++ app/styles/icons/BiLike.tsx | 21 ++++++ app/styles/icons/BiLikeDislike.module.css | 7 ++ 8 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 app/components/Feedback/Feedback.module.css create mode 100644 app/components/Feedback/Feedback.tsx create mode 100644 app/components/Feedback/index.tsx create mode 100644 app/styles/icons/BiDislike.tsx create mode 100644 app/styles/icons/BiLike.tsx create mode 100644 app/styles/icons/BiLikeDislike.module.css diff --git a/app/components/ContentViewer/ContentViewer.module.css b/app/components/ContentViewer/ContentViewer.module.css index 58b91d3..8e98663 100644 --- a/app/components/ContentViewer/ContentViewer.module.css +++ b/app/components/ContentViewer/ContentViewer.module.css @@ -5,7 +5,7 @@ overflow-y: auto; flex: 1; padding-right: 14px; - padding-bottom: 32px; + padding-bottom: 12px; padding-left: 14px; } .contentWrapper { diff --git a/app/components/ContentViewer/ContentViewer.tsx b/app/components/ContentViewer/ContentViewer.tsx index 6a0ccb7..0db23d9 100644 --- a/app/components/ContentViewer/ContentViewer.tsx +++ b/app/components/ContentViewer/ContentViewer.tsx @@ -1,5 +1,5 @@ import styles from "./ContentViewer.module.css"; - +import Feedback from "../Feedback"; export default function ContentViewer({ children, }: { @@ -7,7 +7,9 @@ export default function ContentViewer({ }) { return (
-
{children}
+
+ {children} +
); } diff --git a/app/components/Feedback/Feedback.module.css b/app/components/Feedback/Feedback.module.css new file mode 100644 index 0000000..a191340 --- /dev/null +++ b/app/components/Feedback/Feedback.module.css @@ -0,0 +1,4 @@ +.feedbackSubmitted { + color: hsl(var(--text) / 0.5); + font-size: small; +} diff --git a/app/components/Feedback/Feedback.tsx b/app/components/Feedback/Feedback.tsx new file mode 100644 index 0000000..33222ea --- /dev/null +++ b/app/components/Feedback/Feedback.tsx @@ -0,0 +1,75 @@ +"use client"; + +import React, { useEffect, useState } from "react"; +import Like from "@/app/styles/icons/BiLike"; +import Dislike from "@/app/styles/icons/BiDislike"; +import { Flex } from "@chakra-ui/react"; +import { usePathname } from "next/navigation"; +import styles from "./Feedback.module.css"; + +export default function Feedback() { + const APIRoute = + "https://script.google.com/macros/s/AKfycbz0f87eDgEghSelILb3RSdHe-Rr7HKAdMxx8tvTq4fNAfJt0fZ7t-G-p1BrVEQM2Mws/exec"; + const [isSubmitted, setIsSubmitted] = useState(false); + const pathname = usePathname(); + const submitFeedback = async (feedback: string) => { + await fetch(APIRoute, { + method: "POST", + body: JSON.stringify({ + feedback: feedback, + path: pathname, + }), + }); + const feedbackStorage = localStorage.getItem("feedback"); + if (feedbackStorage) { + const feedbackData = JSON.parse(feedbackStorage); + feedbackData.push(pathname); + localStorage.setItem("feedback", JSON.stringify(feedbackData)); + } + }; + + useEffect(() => { + const feedbackStorage = localStorage.getItem("feedback"); + if (feedbackStorage) { + const feedbackData = JSON.parse(feedbackStorage); + if (feedbackData.includes(pathname)) { + setIsSubmitted(true); + } + } else { + localStorage.setItem("feedback", JSON.stringify([])); + } + }, []); + + if (isSubmitted) { + return ( + + Feedback submitted. Thank you! + + ); + } + return ( + + + + + ); +} diff --git a/app/components/Feedback/index.tsx b/app/components/Feedback/index.tsx new file mode 100644 index 0000000..74bd23e --- /dev/null +++ b/app/components/Feedback/index.tsx @@ -0,0 +1 @@ +export { default as default } from "./Feedback"; diff --git a/app/styles/icons/BiDislike.tsx b/app/styles/icons/BiDislike.tsx new file mode 100644 index 0000000..645b55e --- /dev/null +++ b/app/styles/icons/BiDislike.tsx @@ -0,0 +1,21 @@ +import React from "react"; +import styles from "./BiLikeDislike.module.css"; + +export default function Icon() { + return ( + + + + ); +} diff --git a/app/styles/icons/BiLike.tsx b/app/styles/icons/BiLike.tsx new file mode 100644 index 0000000..c61f3ee --- /dev/null +++ b/app/styles/icons/BiLike.tsx @@ -0,0 +1,21 @@ +import React from "react"; +import styles from "./BiLikeDislike.module.css"; + +export default function BiLike() { + return ( + + + + ); +} diff --git a/app/styles/icons/BiLikeDislike.module.css b/app/styles/icons/BiLikeDislike.module.css new file mode 100644 index 0000000..757954c --- /dev/null +++ b/app/styles/icons/BiLikeDislike.module.css @@ -0,0 +1,7 @@ +.main { + cursor: pointer; +} + +.main:hover .path { + fill: hsl(var(--text)); +}