From 535c82246460e2015641b5fb095a61a9f71279fe Mon Sep 17 00:00:00 2001 From: Bakhtiyor Ganijon Date: Tue, 7 Nov 2023 18:02:04 +0900 Subject: [PATCH] Add session prop to TagsDialog and implement follow functionality. --- app/(Main)/get-started/page.tsx | 2 +- components/get-started/tags.tsx | 38 ++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/app/(Main)/get-started/page.tsx b/app/(Main)/get-started/page.tsx index e741e4d1..a027de14 100644 --- a/app/(Main)/get-started/page.tsx +++ b/app/(Main)/get-started/page.tsx @@ -8,7 +8,7 @@ export default async function GetStartedPage() { console.log(tags); return ( <> - + ) } \ No newline at end of file diff --git a/components/get-started/tags.tsx b/components/get-started/tags.tsx index 5c3573e4..e4afb222 100644 --- a/components/get-started/tags.tsx +++ b/components/get-started/tags.tsx @@ -1,3 +1,4 @@ +'use client' import { Icons } from "@/components/icon" import { AlertDialog, @@ -13,9 +14,34 @@ import { import Link from "next/link" import TagBadge from "../tags/tag" import { Button } from "../ui/button" -import { Plus } from "lucide-react" +import { Check, Plus } from "lucide-react" +import { useEffect, useState } from "react" +import { useRouter } from "next/navigation" +import { useSession } from "next-auth/react" -export default function TagsDialog({ tags, ...props }: React.ComponentPropsWithoutRef & { tags: any }) { +export default function TagsDialog({ tags, session, ...props }: React.ComponentPropsWithoutRef & { tags: any, session: any }) { + const router = useRouter(); + + const { status: sessionStatus } = useSession(); + + const [followingTags, setFollowingTags] = useState([]); + + const handleFollow = async (tag: any) => { + if (sessionStatus === "authenticated") { + try { + const response = await fetch(`/api/follow/tag?tagId=${tag.id}&userId=${session.id}`, { + method: "GET", + }); + } catch (error) { + console.error(error); + } + await fetch(`/api/revalidate?path=/tag/${tag.name}`, { + method: "GET", + }); + router.refresh(); + } + + } return ( @@ -27,10 +53,16 @@ export default function TagsDialog({ tags, ...props }: React.ComponentPropsWitho
+ {followingTags.map((tag: any) => ( + + + {tag.name.replace(/-/g, ' ')} + + ))} {tags.map((tag: any) => ( + {tag.name.replace(/-/g, ' ')} - ))}