From d9c50d2568355f1c91e0d2dd127027bf5d9c4052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=9B=BD=E7=92=87?= Date: Wed, 8 Jan 2025 16:12:22 +0800 Subject: [PATCH 1/2] fix: search repo change --- frontend/src/metadata/hooks/metadata.js | 3 ++- frontend/src/pages/lib-content-view/lib-content-view.js | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/frontend/src/metadata/hooks/metadata.js b/frontend/src/metadata/hooks/metadata.js index 8c8131556e7..8bf2bd22f38 100644 --- a/frontend/src/metadata/hooks/metadata.js +++ b/frontend/src/metadata/hooks/metadata.js @@ -88,7 +88,8 @@ export const MetadataProvider = ({ repoID, currentPath, repoInfo, selectMetadata const errorMsg = Utils.getErrorMsg(error); toaster.danger(errorMsg); }); - }, [repoID, enableMetadata]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [enableMetadata]); const getFirstView = useCallback(() => { const firstViewNav = navigation.find(item => item.type === VIEWS_TYPE_VIEW); 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 ba90c75833c..cd20952d466 100644 --- a/frontend/src/pages/lib-content-view/lib-content-view.js +++ b/frontend/src/pages/lib-content-view/lib-content-view.js @@ -160,7 +160,9 @@ class LibContentView extends React.Component { UNSAFE_componentWillReceiveProps(nextProps) { if (nextProps.repoID !== this.props.repoID) { - this.calculatePara(nextProps); + this.setState({ path: '/', viewId: '', tagID: '', currentMode: cookie.load('seafile_view_mode') || LIST_MODE }, () => { + this.calculatePara(nextProps); + }); } } From 6133db43a08b25506a5ff8320713c9923d7efd9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=9B=BD=E7=92=87?= Date: Wed, 8 Jan 2025 16:46:55 +0800 Subject: [PATCH 2/2] fix: reback --- .../lib-content-view/lib-content-view.js | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) 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 cd20952d466..f79bf5744cf 100644 --- a/frontend/src/pages/lib-content-view/lib-content-view.js +++ b/frontend/src/pages/lib-content-view/lib-content-view.js @@ -169,7 +169,10 @@ class LibContentView extends React.Component { calculatePara = async (props) => { const { repoID } = props; - const path = this.getPathFromLocation(repoID); + const { path, viewId, tagId } = this.getInfoFromLocation(repoID); + let currentMode = cookie.load('seafile_view_mode') || LIST_MODE; + if (viewId) currentMode = METADATA_MODE; + if (tagId) currentMode = TAGS_MODE; try { const repoInfo = await this.fetchRepoInfo(repoID); @@ -181,8 +184,11 @@ class LibContentView extends React.Component { repoName: repoInfo.repo_name, libNeedDecrypt: repoInfo.lib_need_decrypt, repoEncrypted: repoInfo.encrypted, - isGroupOwnedRepo: isGroupOwnedRepo, - path: path + isGroupOwnedRepo, + path, + viewId, + tagId, + currentMode, }); if (this.state.isTreePanelShown) { @@ -203,13 +209,13 @@ class LibContentView extends React.Component { } }; - getPathFromLocation = (repoID) => { + getInfoFromLocation = (repoID) => { const urlParams = new URLSearchParams(window.location.search); - const viewID = urlParams.get('view'); - if (viewID) return `/${PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES}`; + const viewId = urlParams.get('view'); + if (viewId) return { path: `/${PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES}`, viewId }; - const tagID = urlParams.get('tag'); - if (tagID) return `/${PRIVATE_FILE_TYPE.TAGS_PROPERTIES}`; + const tagId = urlParams.get('tag'); + if (tagId) return { path: `/${PRIVATE_FILE_TYPE.TAGS_PROPERTIES}`, tagId }; let location = window.location.href.split('?')[0]; location = decodeURIComponent(location); @@ -218,7 +224,7 @@ class LibContentView extends React.Component { if (path.length > 1 && path.endsWith('/')) { path = path.slice(0, -1); } - return path; + return { path }; }; fetchRepoInfo = async (repoID) => { @@ -520,9 +526,10 @@ class LibContentView extends React.Component { hideMetadataView = (isSetRoot = false) => { const { repoID } = this.props; + const { path } = this.getInfoFromLocation(repoID); this.setState({ currentMode: cookie.load('seafile_view_mode') || LIST_MODE, - path: isSetRoot ? '/' : this.getPathFromLocation(repoID), + path: isSetRoot ? '/' : path, viewId: '', tagId: '', currentDirent: isSetRoot ? null : this.state.currentDirent,