diff --git a/src/assets/constants/className.ts b/src/assets/constants/className.ts new file mode 100644 index 0000000..b269a0f --- /dev/null +++ b/src/assets/constants/className.ts @@ -0,0 +1,10 @@ +export const ACTIONS_SECTION_CLASS_NAME = + "ffs__actions-section nav-buttons-container"; + +export const ACTION_BUTTON_WRAPPER_CLASS_NAME = + "ffs__action-button-wrapper clickable-icon nav-action-button"; + +export const CLICKABLE_TREE_ITEM_CLASS_NAME = "tree-item-self is-clickable"; + +export const TREE_ITEM_INNER_CLASS_NAME = + "tree-item-inner nav-file-title-content"; diff --git a/src/assets/constants.ts b/src/assets/constants/index.ts similarity index 98% rename from src/assets/constants.ts rename to src/assets/constants/index.ts index f32d2a7..19da92d 100644 --- a/src/assets/constants.ts +++ b/src/assets/constants/index.ts @@ -45,3 +45,5 @@ export const FFS_DRAG_FILE = "Drag_File"; export const FFS_SORT_FILE = "Sort_File"; export const FFS_DRAG_FOLDER = "Drag_Folder"; export const FFS_SORT_FOLDER = "Sort_Folder"; + +export * from './className' \ No newline at end of file diff --git a/src/components/File/Content.tsx b/src/components/File/Content.tsx index f1b9d51..6140f86 100644 --- a/src/components/File/Content.tsx +++ b/src/components/File/Content.tsx @@ -3,6 +3,7 @@ import { Menu, TFile } from "obsidian"; import { useRef } from "react"; import { useShallow } from "zustand/react/shallow"; +import { CLICKABLE_TREE_ITEM_CLASS_NAME } from "src/assets/constants"; import { useExplorer } from "src/hooks/useExplorer"; import { useShowFileItemDivider } from "src/hooks/useSettingsHandler"; import { FILE_OPERATION_COPY } from "src/locales"; @@ -137,7 +138,8 @@ const FileContent = ({ file }: FileProps) => { const getClassNames = () => { return classNames( - "ffs__file-content tree-item-self nav-file-title tappable is-clickable", + "ffs__file-content nav-file-title tappable", + CLICKABLE_TREE_ITEM_CLASS_NAME, { "is-active": isFocused, "ffs__file-content--divider": showFileItemDivider, diff --git a/src/components/File/ContentInner.tsx b/src/components/File/ContentInner.tsx index 21117ee..20e606b 100644 --- a/src/components/File/ContentInner.tsx +++ b/src/components/File/ContentInner.tsx @@ -2,6 +2,7 @@ import classNames from "classnames"; import { TFile } from "obsidian"; import { forwardRef, RefObject, useRef } from "react"; +import { TREE_ITEM_INNER_CLASS_NAME } from "src/assets/constants"; import { useExplorer } from "src/hooks/useExplorer"; import { useFileItemSpacing, @@ -37,7 +38,8 @@ const FileContentInner = forwardRef( const getClassNames = () => { return classNames( - "ffs__file-content-header tree-item-inner nav-file-title-content", + "ffs__file-content-header", + TREE_ITEM_INNER_CLASS_NAME, { "ffs__file-content-header--comfortable": fileItemSpacing === FILE_ITEM_SPACING.COMFORTABLE, diff --git a/src/components/File/index.tsx b/src/components/File/index.tsx index a0bf88a..a12ccaa 100644 --- a/src/components/File/index.tsx +++ b/src/components/File/index.tsx @@ -10,8 +10,8 @@ import { ExplorerStore } from "src/store"; import FileContent from "./Content"; import { getPopupInfo } from "./popupInfo"; -type Props = { - file: TFile +type Props = { + file: TFile; onOpenFoldersPane: () => void; disableDrag?: boolean; }; diff --git a/src/components/FileActions/CreateFile.tsx b/src/components/FileActions/CreateFile.tsx index cac059f..efc49fe 100644 --- a/src/components/FileActions/CreateFile.tsx +++ b/src/components/FileActions/CreateFile.tsx @@ -1,6 +1,7 @@ import classNames from "classnames"; import { useShallow } from "zustand/react/shallow"; +import { ACTION_BUTTON_WRAPPER_CLASS_NAME } from "src/assets/constants"; import { AddFileIcon } from "src/assets/icons"; import { useExplorer } from "src/hooks/useExplorer"; import { ExplorerStore } from "src/store"; @@ -29,12 +30,9 @@ const CreateFile = () => { }; const getClassNames = () => { - return classNames( - "ffs__action-button-wrapper clickable-icon nav-action-button", - { - "ffs__action-button-wrapper--disabled": !isCreateFileAbled(), - } - ); + return classNames(ACTION_BUTTON_WRAPPER_CLASS_NAME, { + "ffs__action-button-wrapper--disabled": !isCreateFileAbled(), + }); }; const getAriaLabel = () => { diff --git a/src/components/FileActions/SearchFiles.tsx b/src/components/FileActions/SearchFiles.tsx index e74e55c..bf1a9c9 100644 --- a/src/components/FileActions/SearchFiles.tsx +++ b/src/components/FileActions/SearchFiles.tsx @@ -1,6 +1,6 @@ -import classNames from "classnames"; import { useShallow } from "zustand/react/shallow"; +import { ACTION_BUTTON_WRAPPER_CLASS_NAME } from "src/assets/constants"; import { SearchIcon } from "src/assets/icons"; import { useExplorer } from "src/hooks/useExplorer"; import { ExplorerStore } from "src/store"; @@ -19,12 +19,6 @@ const SearchFiles = () => { })) ); - const getClassNames = () => { - return classNames( - "ffs__action-button-wrapper clickable-icon nav-action-button" - ); - }; - const onBeginSearch = () => { changeToSearchMode(); if (focusedFolder) { @@ -41,7 +35,10 @@ const SearchFiles = () => { }; return ( -
+
); diff --git a/src/components/Folder/DraggableContent.tsx b/src/components/Folder/DraggableContent.tsx index 613af77..00f86da 100644 --- a/src/components/Folder/DraggableContent.tsx +++ b/src/components/Folder/DraggableContent.tsx @@ -1,6 +1,10 @@ import { useDraggable } from "@dnd-kit/core"; +import classNames from "classnames"; -import { FFS_DRAG_FOLDER } from "src/assets/constants"; +import { + FFS_DRAG_FOLDER, + TREE_ITEM_INNER_CLASS_NAME, +} from "src/assets/constants"; import FolderContent, { FolderProps } from "./Content"; @@ -21,7 +25,10 @@ const FolderDraggableContent = ({ folder, disableDrag = false }: Props) => { return (
{ return classNames( - "ffs__folder-container tree-item-self nav-folder-title is-clickable", + "ffs__folder-container nav-folder-title", + CLICKABLE_TREE_ITEM_CLASS_NAME, { "mod-collapsible": hasSubFolder(folder), "is-active": isFocused, diff --git a/src/components/FolderAndTagActions/CreateFolder.tsx b/src/components/FolderAndTagActions/CreateFolder.tsx index d00fe43..6c9cb1e 100644 --- a/src/components/FolderAndTagActions/CreateFolder.tsx +++ b/src/components/FolderAndTagActions/CreateFolder.tsx @@ -1,6 +1,7 @@ import classNames from "classnames"; import { useShallow } from "zustand/react/shallow"; +import { ACTION_BUTTON_WRAPPER_CLASS_NAME } from "src/assets/constants"; import { AddFolderIcon } from "src/assets/icons"; import { useExplorer } from "src/hooks/useExplorer"; import { useShowFolderView } from "src/hooks/useSettingsHandler"; @@ -35,12 +36,9 @@ const CreateFolder = () => { }; const getClassNames = () => { - return classNames( - "ffs__action-button-wrapper clickable-icon nav-action-button", - { - "ffs__action-button-wrapper--disabled": !showFolderView, - } - ); + return classNames(ACTION_BUTTON_WRAPPER_CLASS_NAME, { + "ffs__action-button-wrapper--disabled": !showFolderView, + }); }; const getAriaLabel = () => { diff --git a/src/components/FolderAndTagActions/ToggleFolderAndTagView.tsx b/src/components/FolderAndTagActions/ToggleFolderAndTagView.tsx index 323fda6..e3d0958 100644 --- a/src/components/FolderAndTagActions/ToggleFolderAndTagView.tsx +++ b/src/components/FolderAndTagActions/ToggleFolderAndTagView.tsx @@ -1,5 +1,9 @@ import classNames from "classnames"; +import { + ACTION_BUTTON_WRAPPER_CLASS_NAME, + ACTIONS_SECTION_CLASS_NAME, +} from "src/assets/constants"; import { FolderIcon, TagIcon } from "src/assets/icons"; import { useExplorer } from "src/hooks/useExplorer"; import { @@ -20,12 +24,9 @@ const ToggleFolderAndTagMode = () => { const copy_lang = language === "zh" ? "zh" : "en"; const getButtonClassNames = (disabled: boolean) => - classNames( - "ffs__action-button-wrapper clickable-icon nav-action-button", - { - "ffs__action-button-wrapper--inactive": disabled, - } - ); + classNames(ACTION_BUTTON_WRAPPER_CLASS_NAME, { + "ffs__action-button-wrapper--inactive": disabled, + }); const renderFolderButton = () => { const copy = !showFolderView @@ -65,7 +66,7 @@ const ToggleFolderAndTagMode = () => { }; return ( -
+
{renderFolderButton()} {renderTagButton()}
diff --git a/src/components/FolderAndTagActions/ToggleFoldersAndTags.tsx b/src/components/FolderAndTagActions/ToggleFoldersAndTags.tsx index bde4955..ebcd6e2 100644 --- a/src/components/FolderAndTagActions/ToggleFoldersAndTags.tsx +++ b/src/components/FolderAndTagActions/ToggleFoldersAndTags.tsx @@ -1,6 +1,7 @@ import { useEffect, useState } from "react"; import { useShallow } from "zustand/react/shallow"; +import { ACTION_BUTTON_WRAPPER_CLASS_NAME } from "src/assets/constants"; import { ExpandIcon, CollapseIcon } from "src/assets/icons"; import { useExplorer } from "src/hooks/useExplorer"; import { TIPS_COPY } from "src/locales"; @@ -62,7 +63,7 @@ const ToggleFolders = () => { return (
{ if (!showSubfolders) return null; return (
{subFolders.map((folder) => ( diff --git a/src/components/SortAction.tsx b/src/components/SortAction.tsx index f999bcc..e3d7c13 100644 --- a/src/components/SortAction.tsx +++ b/src/components/SortAction.tsx @@ -1,6 +1,7 @@ import classNames from "classnames"; import { Menu } from "obsidian"; +import { ACTION_BUTTON_WRAPPER_CLASS_NAME } from "src/assets/constants"; import { ArrowUpDownIcon, AscendingSortIcon, @@ -70,12 +71,9 @@ const SortAction = ({ }; const getClassNames = () => { - return classNames( - "ffs__action-button-wrapper clickable-icon nav-action-button", - { - "ffs__action-button-wrapper--disabled": disabled, - } - ); + return classNames(ACTION_BUTTON_WRAPPER_CLASS_NAME, { + "ffs__action-button-wrapper--disabled": disabled, + }); }; return ( diff --git a/src/components/Tag/index.tsx b/src/components/Tag/index.tsx index edc4047..658dda2 100644 --- a/src/components/Tag/index.tsx +++ b/src/components/Tag/index.tsx @@ -1,6 +1,7 @@ import classNames from "classnames"; import { useShallow } from "zustand/react/shallow"; +import { CLICKABLE_TREE_ITEM_CLASS_NAME } from "src/assets/constants"; import { useExplorer } from "src/hooks/useExplorer"; import { ExplorerStore } from "src/store"; import { TagNode } from "src/store/tag"; @@ -58,7 +59,8 @@ const Tag = ({ const getClassNames = () => { return classNames( - "ffs__folder-container tree-item-self nav-folder-title is-clickable", + "ffs__folder-container nav-folder-title", + CLICKABLE_TREE_ITEM_CLASS_NAME, { "mod-collapsible": hasSubTag(tag), "is-active": isFocused, diff --git a/src/components/layout/Actions.tsx b/src/components/layout/Actions.tsx index 50587f9..52b30bd 100644 --- a/src/components/layout/Actions.tsx +++ b/src/components/layout/Actions.tsx @@ -1,5 +1,6 @@ import classNames from "classnames"; +import { ACTIONS_SECTION_CLASS_NAME } from "src/assets/constants"; import { useExplorer } from "src/hooks/useExplorer"; import { useAutoHideActionBar, @@ -15,7 +16,7 @@ import ToggleFolders from "../FolderAndTagActions/ToggleFoldersAndTags"; export const FolderAndTagActionSection = () => ( -
+
@@ -23,7 +24,7 @@ export const FolderAndTagActionSection = () => ( ); export const FileActionSection = () => ( -
+
diff --git a/src/components/layout/VerticalSplitFilesPane.tsx b/src/components/layout/VerticalSplitFilesPane.tsx index a060a2a..9da20cb 100644 --- a/src/components/layout/VerticalSplitFilesPane.tsx +++ b/src/components/layout/VerticalSplitFilesPane.tsx @@ -1,3 +1,6 @@ +import classNames from "classnames"; + +import { ACTIONS_SECTION_CLASS_NAME } from "src/assets/constants"; import { useExplorer } from "src/hooks/useExplorer"; import { VERTICAL_SPLIT_LAYOUT_OPERATION_COPY } from "src/locales"; @@ -22,10 +25,15 @@ const VerticalSplitFilesPane = ({ if (isFilesCollapsed) { return ( -
+
Files
-
+
setIsFilesCollapsed(false)} label={openFiles[language]} @@ -39,7 +47,7 @@ const VerticalSplitFilesPane = ({
-
+
setIsFilesCollapsed(true)} label={closeFiles[language]} diff --git a/src/components/layout/VerticalSplitFoldersAndTagsPane.tsx b/src/components/layout/VerticalSplitFoldersAndTagsPane.tsx index 6f3219d..ff9973c 100644 --- a/src/components/layout/VerticalSplitFoldersAndTagsPane.tsx +++ b/src/components/layout/VerticalSplitFoldersAndTagsPane.tsx @@ -1,3 +1,6 @@ +import classNames from "classnames"; + +import { ACTIONS_SECTION_CLASS_NAME } from "src/assets/constants"; import { useExplorer } from "src/hooks/useExplorer"; import { useShowFolderView, @@ -39,10 +42,10 @@ const VerticalSplitFoldersAndTagsPane = ({ if (isFoldersCollapsed) { return ( -
+
{copy}
-
+
setIsFoldersCollapsed(false)} label={openFoldersAndTags[language]} @@ -61,7 +64,7 @@ const VerticalSplitFoldersAndTagsPane = ({ > -
+
setIsFoldersCollapsed(true)} diff --git a/src/hooks/useVaultChangeHandler/useChangeFolder.tsx b/src/hooks/useVaultChangeHandler/useChangeFolder.tsx index bd829a6..8fbf566 100644 --- a/src/hooks/useVaultChangeHandler/useChangeFolder.tsx +++ b/src/hooks/useVaultChangeHandler/useChangeFolder.tsx @@ -20,7 +20,7 @@ const useChangeFolder = () => { unpinFolder, updatePinnedFolderPath, updateFolderPathInManualOrder, - sortFolders + sortFolders, } = useExplorerStore( useShallow((store: ExplorerStore) => ({ getTopLevelFolders: store.getTopLevelFolders, @@ -30,7 +30,7 @@ const useChangeFolder = () => { unpinFolder: store.unpinFolder, updatePinnedFolderPath: store.updatePinnedFolderPath, updateFolderPathInManualOrder: store.updateFolderPathInManualOrder, - sortFolders: store.sortFolders + sortFolders: store.sortFolders, })) ); diff --git a/src/hooks/useVaultChangeHandler/useChangeTag.tsx b/src/hooks/useVaultChangeHandler/useChangeTag.tsx index a90587f..d010fe8 100644 --- a/src/hooks/useVaultChangeHandler/useChangeTag.tsx +++ b/src/hooks/useVaultChangeHandler/useChangeTag.tsx @@ -13,10 +13,7 @@ import { useExplorer } from "../useExplorer"; const useChangeTag = () => { const { useExplorerStore } = useExplorer(); - const { - getTopLevelTags, - generateTagTree, - } = useExplorerStore( + const { getTopLevelTags, generateTagTree } = useExplorerStore( useShallow((store: ExplorerStore) => ({ getTopLevelTags: store.getTopLevelTags, generateTagTree: store.generateTagTree, diff --git a/src/store/common/viewMode.ts b/src/store/common/viewMode.ts index 5b612ca..7f75297 100644 --- a/src/store/common/viewMode.ts +++ b/src/store/common/viewMode.ts @@ -65,7 +65,11 @@ export const createViewModeSlice = key: "viewMode", transform: (mode: ViewMode) => { const { FOLDER, TAG } = VIEW_MODE; - if (![FOLDER, TAG].includes(mode as typeof FOLDER | typeof TAG)) { + if ( + ![FOLDER, TAG].includes( + mode as typeof FOLDER | typeof TAG + ) + ) { if (focusedFolder) { return FOLDER; } @@ -74,7 +78,7 @@ export const createViewModeSlice = } return FOLDER; } - return mode + return mode; }, }); },