From 1d9927d7f834e46953bf0bcc21bb5eccb4f3010a Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Mon, 2 Aug 2021 12:19:18 -0600 Subject: [PATCH] ui(admin): persist sidebar collapsed state --- resources/scripts/components/server/Console.tsx | 2 +- resources/scripts/routers/AdminRouter.tsx | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/resources/scripts/components/server/Console.tsx b/resources/scripts/components/server/Console.tsx index c0f0d825a..ef772f806 100644 --- a/resources/scripts/components/server/Console.tsx +++ b/resources/scripts/components/server/Console.tsx @@ -76,7 +76,7 @@ export default () => { const scrollDownHelperAddon = new ScrollDownHelperAddon(); const { connected, instance } = ServerContext.useStoreState(state => state.socket); const [ canSendCommands ] = usePermissions([ 'control.console' ]); - const serverId = ServerContext.useStoreState(state => state.server.data!.id); + const serverId = ServerContext.useStoreState(state => state.server.data!.uuid); const isTransferring = ServerContext.useStoreState(state => state.server.data!.isTransferring); const [ history, setHistory ] = usePersistedState(`${serverId}:command_history`, []); const [ historyIndex, setHistoryIndex ] = useState(-1); diff --git a/resources/scripts/routers/AdminRouter.tsx b/resources/scripts/routers/AdminRouter.tsx index e22d0a91c..7f34bde32 100644 --- a/resources/scripts/routers/AdminRouter.tsx +++ b/resources/scripts/routers/AdminRouter.tsx @@ -1,5 +1,5 @@ import { State, useStoreState } from 'easy-peasy'; -import React, { useState } from 'react'; +import React from 'react'; import { NavLink, Route, RouteComponentProps, Switch } from 'react-router-dom'; import tw, { styled } from 'twin.macro'; import { ApplicationStore } from '@/state'; @@ -29,6 +29,7 @@ import MountEditContainer from '@/components/admin/mounts/MountEditContainer'; import EggRouter from '@/components/admin/nests/eggs/EggRouter'; import ServerRouter from '@/components/admin/servers/ServerRouter'; import { NotFound } from '@/components/elements/ScreenBlock'; +import { usePersistedState } from '@/plugins/usePersistedState'; const Sidebar = styled.div<{ collapsed?: boolean }>` ${tw`fixed h-screen hidden md:flex flex-col items-center flex-shrink-0 bg-neutral-900 overflow-x-hidden transition-all duration-250 ease-linear`}; @@ -99,7 +100,8 @@ const AdminRouter = ({ location, match }: RouteComponentProps) => { const user = useStoreState((state: State) => state.user.data); const applicationName = useStoreState((state: ApplicationStore) => state.settings.data!.name); - const [ collapsed, setCollapsed ] = useState(); + const uuid = useStoreState(state => state.user.data!.uuid); + const [ collapsed, setCollapsed ] = usePersistedState(`${uuid}:admin_sidebar_collapsed`, false); return (