From 59a59273d8917c610a0b94f35e91d4c0b61ea89b Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Sat, 4 Apr 2026 17:20:13 +0200 Subject: [PATCH] Refactored fix --- src/App.tsx | 28 +++++++++++++++++++++++++++- src/components/ModsSection.tsx | 15 +++------------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 7fcc1c7..731907a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import { useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import Sidebar from "./components/layout/Sidebar"; import TopBar from "./components/layout/TopBar"; import PlaySection from "./components/PlaySection"; @@ -21,6 +21,32 @@ export default function App() { const versionRef = useRef(null); const accountRef = useRef(null); + useEffect(() => { + function handleClickOutside(event: MouseEvent) { + const target = event.target as Node; + + // Close version dropdown if clicked outside + if (versionRef.current && !versionRef.current.contains(target)) { + setIsVersionDropdownOpen(false); + } + + // Close account dropdown if clicked outside + if (accountRef.current && !accountRef.current.contains(target)) { + setIsAccountDropdownOpen(false); + } + } + + document.addEventListener("mousedown", handleClickOutside); + + return () => { + document.removeEventListener("mousedown", handleClickOutside); + }; + }, []); + + useEffect(() => { + setSelectedVersion(versions[0]); + }, []); + return (
diff --git a/src/components/ModsSection.tsx b/src/components/ModsSection.tsx index c2419f5..41ffeb4 100644 --- a/src/components/ModsSection.tsx +++ b/src/components/ModsSection.tsx @@ -11,10 +11,10 @@ import { import { getInstalledMods, discoverMods, - getVersions, toggleMod, installMod, -} from "../lib/saturn"; + versions, +} from "@/lib/saturn"; import { clsx, type ClassValue } from "clsx"; import { twMerge } from "tailwind-merge"; import { motion, AnimatePresence } from "framer-motion"; @@ -40,7 +40,6 @@ const ModsSection: React.FC = ({ version }) => { const [selectedVersionsForInstall, setSelectedVersionsForInstall] = useState< string[] >([]); - const [allVersions, setAllVersions] = useState([]); useEffect(() => { const loadMods = async () => { @@ -55,14 +54,6 @@ const ModsSection: React.FC = ({ version }) => { loadMods(); }, [activeTab, version.id, searchQuery]); - useEffect(() => { - const loadAllVersions = async () => { - const v = await getVersions(); - setAllVersions(v); - }; - loadAllVersions(); - }, []); - const handleToggleMod = async (modId: string) => { await toggleMod(modId); const m = await getInstalledMods(version.id); @@ -243,7 +234,7 @@ const ModsSection: React.FC = ({ version }) => {
- {allVersions.map((v) => { + {versions.map((v) => { const isSupported = selectedModForInstall.supported_versions.includes(v.id); const isSelected = selectedVersionsForInstall.includes(v.id);