diff --git a/web/components/routes/globalTopic/globalTopic.tsx b/web/components/routes/globalTopic/globalTopic.tsx index f0a021c4..e19a2790 100644 --- a/web/components/routes/globalTopic/globalTopic.tsx +++ b/web/components/routes/globalTopic/globalTopic.tsx @@ -1,5 +1,5 @@ "use client" -import React, { useState } from "react" +import { useState, useEffect, useRef } from "react" import { ContentHeader } from "@/components/custom/content-header" import { PiLinkSimple } from "react-icons/pi" import { Bookmark, GraduationCap, Check } from "lucide-react" @@ -55,8 +55,21 @@ export default function GlobalTopic({ topic }: { topic: string }) { const [showOptions, setShowOptions] = useState(false) const [selectedOption, setSelectedOption] = useState(null) const [activeTab, setActiveTab] = useState("Guide") - const decodedTopic = decodeURIComponent(topic) + const learningStatusRef = useRef(null) + + useEffect(() => { + function handleClickOutside(event: MouseEvent) { + if (learningStatusRef.current && !learningStatusRef.current.contains(event.target as Node)) { + setShowOptions(false) + } + } + + document.addEventListener("mousedown", handleClickOutside) + return () => { + document.removeEventListener("mousedown", handleClickOutside) + } + }, []) const learningOptions = [ { text: "To Learn", icon: }, @@ -123,7 +136,10 @@ export default function GlobalTopic({ topic }: { topic: string }) { {selectedOption || "Add to my profile"} {showOptions && ( -
+
{learningOptions.map(option => (