mirror of https://github.com/portainer/portainer
fix(sidebar): save sidebar state to local storage (#7207)
parent
762c664948
commit
ea60740d48
|
@ -1,5 +1,5 @@
|
||||||
import { useCurrentStateAndParams, useRouter } from '@uirouter/react';
|
import { useCurrentStateAndParams, useRouter } from '@uirouter/react';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { X, Slash } from 'react-feather';
|
import { X, Slash } from 'react-feather';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -9,6 +9,7 @@ import {
|
||||||
} from '@/portainer/environments/types';
|
} from '@/portainer/environments/types';
|
||||||
import { getPlatformType } from '@/portainer/environments/utils';
|
import { getPlatformType } from '@/portainer/environments/utils';
|
||||||
import { useEnvironment } from '@/portainer/environments/queries/useEnvironment';
|
import { useEnvironment } from '@/portainer/environments/queries/useEnvironment';
|
||||||
|
import { useLocalStorage } from '@/portainer/hooks/useLocalStorage';
|
||||||
|
|
||||||
import { getPlatformIcon } from '../portainer/environments/utils/get-platform-icon';
|
import { getPlatformIcon } from '../portainer/environments/utils/get-platform-icon';
|
||||||
|
|
||||||
|
@ -86,14 +87,16 @@ function Content({ environment, onClear }: ContentProps) {
|
||||||
function useCurrentEnvironment() {
|
function useCurrentEnvironment() {
|
||||||
const { params } = useCurrentStateAndParams();
|
const { params } = useCurrentStateAndParams();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [environmentId, setEnvironmentId] = useState<EnvironmentId>();
|
const [environmentId, setEnvironmentId] = useLocalStorage<
|
||||||
|
EnvironmentId | undefined
|
||||||
|
>('environmentId', undefined, sessionStorage);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const environmentId = parseInt(params.endpointId, 10);
|
const environmentId = parseInt(params.endpointId, 10);
|
||||||
if (params.endpointId && !Number.isNaN(environmentId)) {
|
if (params.endpointId && !Number.isNaN(environmentId)) {
|
||||||
setEnvironmentId(environmentId);
|
setEnvironmentId(environmentId);
|
||||||
}
|
}
|
||||||
}, [params.endpointId]);
|
}, [params.endpointId, setEnvironmentId]);
|
||||||
|
|
||||||
return { query: useEnvironment(environmentId), clearEnvironment };
|
return { query: useEnvironment(environmentId), clearEnvironment };
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue