From 474821318ac085e41d32344fb104be9046f45c4c Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Sun, 22 Jun 2025 11:42:33 +0800 Subject: [PATCH] feat(treeview): add option to disable treeview auto expansion (https://github.com/cloudreve/cloudreve/issues/2545) --- package.json | 3 --- public/locales/en-US/application.json | 3 +++ public/locales/ja-JP/application.json | 5 ++++- public/locales/zh-CN/application.json | 3 +++ public/locales/zh-TW/application.json | 3 +++ .../FileManager/TreeView/TreeNavigation.tsx | 6 ++++-- src/component/Pages/Setting/PreferenceSetting.tsx | 15 +++++++++++++++ src/session/index.ts | 2 ++ 8 files changed, 34 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index e553605..12eeda1 100644 --- a/package.json +++ b/package.json @@ -110,9 +110,6 @@ "lint-staged": { "*.{js,jsx,ts,tsx,json,css,scss,md}": [ "prettier --write" - ], - "*.{js,jsx,ts,tsx}": [ - "eslint --fix" ] } } \ No newline at end of file diff --git a/public/locales/en-US/application.json b/public/locales/en-US/application.json index a56e04a..388f634 100644 --- a/public/locales/en-US/application.json +++ b/public/locales/en-US/application.json @@ -675,6 +675,9 @@ "createdAt": "Created at: " }, "setting": { + "treeView": "Tree view", + "autoExpandTreeView": "Auto expand tree view", + "autoExpandTreeViewDes": "When enabled, the file tree in the sidebar will follow the current directory and expand automatically.", "syncView": "View settings", "syncViewDes": "Remember the view settings of each directory and synchronize to the server.", "syncViewOn": "Sync to server", diff --git a/public/locales/ja-JP/application.json b/public/locales/ja-JP/application.json index 843ab0c..49477eb 100644 --- a/public/locales/ja-JP/application.json +++ b/public/locales/ja-JP/application.json @@ -676,6 +676,9 @@ "createdAt": "作成日:" }, "setting": { + "treeView": "ツリービュー", + "autoExpandTreeView": "ツリービューの自動展開", + "autoExpandTreeViewDes": "有効にすると、サイドバーのファイルツリーが現在のディレクトリに従って自動的に展開されます。", "syncView": "ビュー設定", "syncViewDes": "各ディレクトリのビュー設定を記憶し、サーバーに同期します。", "syncViewOn": "サーバーに同期", @@ -851,4 +854,4 @@ "used": "使用量 - {{size}}", "total": "合計容量 - {{size}}" } -} \ No newline at end of file +} diff --git a/public/locales/zh-CN/application.json b/public/locales/zh-CN/application.json index c0a4a35..647788d 100644 --- a/public/locales/zh-CN/application.json +++ b/public/locales/zh-CN/application.json @@ -679,6 +679,9 @@ "createdAt": "创建日期:" }, "setting": { + "treeView": "树视图", + "autoExpandTreeView": "自动展开树视图", + "autoExpandTreeViewDes": "开启后,侧边栏的文件树会跟随当前目录并自动展开。", "syncView": "视图设置", "syncViewDes": "是否记住各个目录的视图设置,并同步到服务器。", "syncViewOn": "同步到服务器", diff --git a/public/locales/zh-TW/application.json b/public/locales/zh-TW/application.json index 297e81b..7bf3c76 100644 --- a/public/locales/zh-TW/application.json +++ b/public/locales/zh-TW/application.json @@ -675,6 +675,9 @@ "createdAt": "建立日期:" }, "setting": { + "treeView": "樹視圖", + "autoExpandTreeView": "自動展開樹視圖", + "autoExpandTreeViewDes": "開啟後,側邊欄的文件樹會隨當前目錄自動展開。", "syncView": "視圖設置", "syncViewDes": "是否記住各個目錄的視圖設置,並同步到服務器。", "syncViewOn": "同步到服務器", diff --git a/src/component/FileManager/TreeView/TreeNavigation.tsx b/src/component/FileManager/TreeView/TreeNavigation.tsx index a4bb4d1..b57fbe2 100644 --- a/src/component/FileManager/TreeView/TreeNavigation.tsx +++ b/src/component/FileManager/TreeView/TreeNavigation.tsx @@ -6,7 +6,7 @@ import React, { useEffect } from "react"; import { TransitionGroup } from "react-transition-group"; import { defaultPath, defaultSharedWithMePath, defaultTrashPath } from "../../../hooks/useNavigation.tsx"; import { useAppSelector } from "../../../redux/hooks.ts"; -import SessionManager from "../../../session"; +import SessionManager, { UserSettings } from "../../../session"; import CrUri, { Filesystem } from "../../../util/uri.ts"; import { FileManagerIndex } from "../FileManager.tsx"; import { FmIndexContext } from "../FmIndexContext.tsx"; @@ -46,7 +46,9 @@ const TreeNavigation = React.memo( res.push(b.toString()); }); } - setExpanded((e) => [...new Set([...e, ...res])]); + if (SessionManager.getWithFallback(UserSettings.TreeViewAutoExpand)) { + setExpanded((e) => [...new Set([...e, ...res])]); + } }, [path, base, elements]); const pinned = usePinned(); diff --git a/src/component/Pages/Setting/PreferenceSetting.tsx b/src/component/Pages/Setting/PreferenceSetting.tsx index 79484ea..4954508 100644 --- a/src/component/Pages/Setting/PreferenceSetting.tsx +++ b/src/component/Pages/Setting/PreferenceSetting.tsx @@ -77,6 +77,9 @@ const PreferenceSetting = ({ setting, setSetting }: PreferenceSettingProps) => { const [versionRetentionMax, setVersionRetentionMax] = useState(setting.version_retention_max); const [versionRetentionExts, setVersionRetentionExts] = useState(setting.version_retention_ext); const [showSaveButton, setShowSaveButton] = useState(false); + const [autoExpandTreeView, setAutoExpandTreeView] = useState( + SessionManager.getWithFallback(UserSettings.TreeViewAutoExpand), + ); const onRetentionCheckChange = (e: React.ChangeEvent) => { setVersionRetentionEnabled(e.target.checked); @@ -170,6 +173,11 @@ const PreferenceSetting = ({ setting, setSetting }: PreferenceSettingProps) => { }); }; + const onAutoExpandTreeViewChange = (e: React.ChangeEvent) => { + setAutoExpandTreeView(e.target.checked); + SessionManager.set(UserSettings.TreeViewAutoExpand, e.target.checked); + }; + return ( @@ -326,6 +334,13 @@ const PreferenceSetting = ({ setting, setSetting }: PreferenceSettingProps) => { {t("setting.syncViewDes")} + + } + label={t("application:setting.autoExpandTreeView")} + /> + {t("setting.autoExpandTreeViewDes")} + ); }; diff --git a/src/session/index.ts b/src/session/index.ts index 48eb0f6..8efa685 100644 --- a/src/session/index.ts +++ b/src/session/index.ts @@ -32,6 +32,7 @@ export enum UserSettings { GalleryWidth = "gallery_width", UploadOverwrite = "upload_overwrite", TimeZone = "time_zone", + TreeViewAutoExpand = "tree_view_auto_expand", } export const UserSettingsDefault: { [key: string]: any } = { @@ -61,6 +62,7 @@ export const UserSettingsDefault: { [key: string]: any } = { [UserSettings.GalleryWidth]: 220, [UserSettings.UploadOverwrite]: false, [UserSettings.TimeZone]: "Asia/Shanghai", + [UserSettings.TreeViewAutoExpand]: true, }; export interface Session extends LoginResponse {