From 6ac624e73a113947c6963f233fc8302d71e50ee7 Mon Sep 17 00:00:00 2001 From: Poseidon281 Date: Fri, 7 Jun 2024 19:06:31 +0200 Subject: [PATCH] Fix TODO 1 --- lang/en/dashboard/index.php | 1 + .../dashboard/DashboardContainer.tsx | 23 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lang/en/dashboard/index.php b/lang/en/dashboard/index.php index be5e8ac527..320746b1b8 100644 --- a/lang/en/dashboard/index.php +++ b/lang/en/dashboard/index.php @@ -13,6 +13,7 @@ 'add_group' => 'Add Group', 'delete_group' => 'Delete Current Group', 'move_server' => 'Move Server', + 'all_servers' => "All Servers", 'content_tabs' => 'Content tabs', 'overview' => 'Overview', diff --git a/resources/scripts/components/dashboard/DashboardContainer.tsx b/resources/scripts/components/dashboard/DashboardContainer.tsx index e881408c63..9f3f2f20c5 100644 --- a/resources/scripts/components/dashboard/DashboardContainer.tsx +++ b/resources/scripts/components/dashboard/DashboardContainer.tsx @@ -64,6 +64,15 @@ export default () => { if (!error) clearFlashes('dashboard'); }, [error]); + useEffect(() => { + const storedCurrentGroup = localStorage.getItem(`currentGroup:${uuid}`); + if (storedCurrentGroup && groups[storedCurrentGroup]) { + setCurrentGroup(storedCurrentGroup); + } else { + setCurrentGroup('default'); + } + }, [uuid, groups]); + useEffect(() => { const savedGroups = localStorage.getItem(`groups:${uuid}`); if (savedGroups) { @@ -72,8 +81,8 @@ export default () => { }, [uuid]); useEffect(() => { - localStorage.setItem(`groups:${uuid}`, JSON.stringify(groups)); - }, [groups]); + localStorage.setItem(`currentGroup:${uuid}`, currentGroup); + }, [uuid, currentGroup]); const addGroup = () => { if (newGroupName && !groups[newGroupName]) { @@ -102,7 +111,11 @@ export default () => { if (currentGroup) { updatedGroups[currentGroup] = updatedGroups[currentGroup].filter((uuid) => uuid !== serverUuid); } - updatedGroups[targetGroup].push(serverUuid); + if (!updatedGroups[targetGroup].includes(serverUuid)) { + if (currentGroup !== targetGroup) { + updatedGroups[targetGroup].push(serverUuid); + } + } setGroups(updatedGroups); setShowMoveOptions((prevState) => ({ ...prevState, [serverUuid]: false })); }; @@ -158,7 +171,7 @@ export default () => { > {Object.keys(groups).map((group) => ( ))} @@ -229,7 +242,7 @@ export default () => { > {Object.keys(groups).map((group) => ( ))}