diff --git a/frontend/src/components/dir-view-mode/dir-column-view.js b/frontend/src/components/dir-view-mode/dir-column-view.js index 27ab62f09f..90f2ed4510 100644 --- a/frontend/src/components/dir-view-mode/dir-column-view.js +++ b/frontend/src/components/dir-view-mode/dir-column-view.js @@ -224,7 +224,7 @@ class DirColumnView extends React.Component { updateCurrentDirent={this.props.updateCurrentDirent} /> )} - {currentMode === LIST_MODE && + {currentMode === LIST_MODE && ( - } - {currentMode === GRID_MODE && + )} + {currentMode === GRID_MODE && ( - } + )} ); diff --git a/frontend/src/components/dir-view-mode/dir-files.js b/frontend/src/components/dir-view-mode/dir-files.js index 9d87310410..9a7697ce01 100644 --- a/frontend/src/components/dir-view-mode/dir-files.js +++ b/frontend/src/components/dir-view-mode/dir-files.js @@ -367,6 +367,8 @@ class DirFiles extends React.Component { return ( <> diff --git a/frontend/src/components/dir-view-mode/dir-tags/index.js b/frontend/src/components/dir-view-mode/dir-tags/index.js index 8aa51fc6e8..a3ea26e1a8 100644 --- a/frontend/src/components/dir-view-mode/dir-tags/index.js +++ b/frontend/src/components/dir-view-mode/dir-tags/index.js @@ -21,7 +21,7 @@ const DirTags = ({ userPerm, repoID, currentPath, currentRepoInfo }) => { if (!enableMetadata || !enableTags) return null; return ( - + {!isLoading && ()} ); diff --git a/frontend/src/components/dir-view-mode/dir-views/index.js b/frontend/src/components/dir-view-mode/dir-views/index.js index cb95ef0871..d1f1ca5df3 100644 --- a/frontend/src/components/dir-view-mode/dir-views/index.js +++ b/frontend/src/components/dir-view-mode/dir-views/index.js @@ -51,6 +51,8 @@ const DirViews = ({ userPerm, repoID, currentPath, currentRepoInfo }) => { return ( <> diff --git a/frontend/src/components/tree-section/index.js b/frontend/src/components/tree-section/index.js index 55f2661a43..b8e7af65c2 100644 --- a/frontend/src/components/tree-section/index.js +++ b/frontend/src/components/tree-section/index.js @@ -1,19 +1,37 @@ -import React, { useCallback, useState } from 'react'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; +import { TREE_PANEL_SECTION_STATE_KEY } from '../../constants'; import './index.css'; -const TreeSection = ({ title, children, renderHeaderOperations, className }) => { +const TreeSection = ({ repoID, stateStorageKey, title, children, renderHeaderOperations, className }) => { const [showChildren, setShowChildren] = useState(true); const [highlight, setHighlight] = useState(false); const [freeze, setFreeze] = useState(false); + const storageKey = useMemo(() => `${TREE_PANEL_SECTION_STATE_KEY}_${repoID}`, [repoID]); + + useEffect(() => { + if (!stateStorageKey) return; + const stateString = window.localStorage.getItem(storageKey, '{}'); + const state = JSON.parse(stateString) || {}; + const currentValue = state[stateStorageKey] === false ? false : true; + setShowChildren(currentValue); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + const toggleShowChildren = useCallback((event) => { event.stopPropagation(); event.nativeEvent.stopImmediatePropagation(); - setShowChildren(!showChildren); - }, [showChildren]); + const newValue = !showChildren; + setShowChildren(newValue); + if (!stateStorageKey) return; + const stateString = window.localStorage.getItem(storageKey, '{}'); + const stateOldValue = JSON.parse(stateString); + const newState = { ...stateOldValue, [stateStorageKey]: newValue }; + window.localStorage.setItem(storageKey, JSON.stringify(newState)); + }, [showChildren, storageKey, stateStorageKey]); const onMouseEnter = useCallback(() => { if (freeze) return; @@ -76,6 +94,8 @@ const TreeSection = ({ title, children, renderHeaderOperations, className }) => }; TreeSection.propTypes = { + repoID: PropTypes.string, + stateStorageKey: PropTypes.string, title: PropTypes.any.isRequired, children: PropTypes.any, className: PropTypes.string, diff --git a/frontend/src/constants/index.js b/frontend/src/constants/index.js index f93b961765..dd5e8eb017 100644 --- a/frontend/src/constants/index.js +++ b/frontend/src/constants/index.js @@ -45,3 +45,7 @@ export const SYSTEM_FOLDERS = [ ]; export const DIRENT_DETAIL_SHOW_KEY = 'sf_dirent_detail_show'; + +export const TREE_PANEL_STATE_KEY = 'sf_dir_view_tree_panel_open'; + +export const TREE_PANEL_SECTION_STATE_KEY = 'sf_dir_view_tree_panel_section_state'; diff --git a/frontend/src/pages/lib-content-view/lib-content-view.js b/frontend/src/pages/lib-content-view/lib-content-view.js index ad15add546..646785f436 100644 --- a/frontend/src/pages/lib-content-view/lib-content-view.js +++ b/frontend/src/pages/lib-content-view/lib-content-view.js @@ -21,7 +21,7 @@ import FileUploader from '../../components/file-uploader/file-uploader'; import CopyMoveDirentProgressDialog from '../../components/dialog/copy-move-dirent-progress-dialog'; import DeleteFolderDialog from '../../components/dialog/delete-folder-dialog'; import { EVENT_BUS_TYPE } from '../../components/common/event-bus-type'; -import { PRIVATE_FILE_TYPE, DIRENT_DETAIL_SHOW_KEY } from '../../constants'; +import { PRIVATE_FILE_TYPE, DIRENT_DETAIL_SHOW_KEY, TREE_PANEL_STATE_KEY } from '../../constants'; import { MetadataStatusProvider } from '../../hooks'; import { MetadataProvider, CollaboratorsProvider } from '../../metadata/hooks'; import { TagsProvider } from '../../tag/hooks'; @@ -50,7 +50,7 @@ class LibContentView extends React.Component { super(props); let isTreePanelShown = true; - const storedTreePanelState = localStorage.getItem('sf_dir_view_tree_panel_open'); + const storedTreePanelState = localStorage.getItem(TREE_PANEL_STATE_KEY); if (storedTreePanelState != undefined) { isTreePanelShown = storedTreePanelState === 'true'; } @@ -2140,7 +2140,7 @@ class LibContentView extends React.Component { if (this.state.isTreePanelShown) { this.loadSidePanel(this.state.path); } - localStorage.setItem('sf_dir_view_tree_panel_open', String(this.state.isTreePanelShown)); + localStorage.setItem(TREE_PANEL_STATE_KEY, String(this.state.isTreePanelShown)); }); };