Refactored fix

This commit is contained in:
2026-04-04 17:20:13 +02:00
parent 0f0e3a1c5d
commit 59a59273d8
2 changed files with 30 additions and 13 deletions
+27 -1
View File
@@ -1,4 +1,4 @@
import { useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
import Sidebar from "./components/layout/Sidebar"; import Sidebar from "./components/layout/Sidebar";
import TopBar from "./components/layout/TopBar"; import TopBar from "./components/layout/TopBar";
import PlaySection from "./components/PlaySection"; import PlaySection from "./components/PlaySection";
@@ -21,6 +21,32 @@ export default function App() {
const versionRef = useRef<HTMLDivElement | null>(null); const versionRef = useRef<HTMLDivElement | null>(null);
const accountRef = useRef<HTMLDivElement | null>(null); const accountRef = useRef<HTMLDivElement | null>(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 ( return (
<div className="flex h-screen"> <div className="flex h-screen">
<Sidebar active={active} setActive={setActive} /> <Sidebar active={active} setActive={setActive} />
+3 -12
View File
@@ -11,10 +11,10 @@ import {
import { import {
getInstalledMods, getInstalledMods,
discoverMods, discoverMods,
getVersions,
toggleMod, toggleMod,
installMod, installMod,
} from "../lib/saturn"; versions,
} from "@/lib/saturn";
import { clsx, type ClassValue } from "clsx"; import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge"; import { twMerge } from "tailwind-merge";
import { motion, AnimatePresence } from "framer-motion"; import { motion, AnimatePresence } from "framer-motion";
@@ -40,7 +40,6 @@ const ModsSection: React.FC<ModsSectionProps> = ({ version }) => {
const [selectedVersionsForInstall, setSelectedVersionsForInstall] = useState< const [selectedVersionsForInstall, setSelectedVersionsForInstall] = useState<
string[] string[]
>([]); >([]);
const [allVersions, setAllVersions] = useState<GameVersion[]>([]);
useEffect(() => { useEffect(() => {
const loadMods = async () => { const loadMods = async () => {
@@ -55,14 +54,6 @@ const ModsSection: React.FC<ModsSectionProps> = ({ version }) => {
loadMods(); loadMods();
}, [activeTab, version.id, searchQuery]); }, [activeTab, version.id, searchQuery]);
useEffect(() => {
const loadAllVersions = async () => {
const v = await getVersions();
setAllVersions(v);
};
loadAllVersions();
}, []);
const handleToggleMod = async (modId: string) => { const handleToggleMod = async (modId: string) => {
await toggleMod(modId); await toggleMod(modId);
const m = await getInstalledMods(version.id); const m = await getInstalledMods(version.id);
@@ -243,7 +234,7 @@ const ModsSection: React.FC<ModsSectionProps> = ({ version }) => {
</div> </div>
<div className="p-6 space-y-3 max-h-64 overflow-y-auto"> <div className="p-6 space-y-3 max-h-64 overflow-y-auto">
{allVersions.map((v) => { {versions.map((v) => {
const isSupported = const isSupported =
selectedModForInstall.supported_versions.includes(v.id); selectedModForInstall.supported_versions.includes(v.id);
const isSelected = selectedVersionsForInstall.includes(v.id); const isSelected = selectedVersionsForInstall.includes(v.id);