diff --git a/src/components/FileActions/SortFiles.tsx b/src/components/FileActions/SortFiles.tsx index dbd4188..aa42579 100644 --- a/src/components/FileActions/SortFiles.tsx +++ b/src/components/FileActions/SortFiles.tsx @@ -19,6 +19,7 @@ const SortFiles = () => { filesSortRulesGroup, changeFileSortRuleAndUpdateOrder, isFileSortRuleAbled, + isFileSortDisabled } = useExplorerStore( useShallow((store: ExplorerStore) => ({ fileSortRule: store.fileSortRule, @@ -27,6 +28,7 @@ const SortFiles = () => { changeFileSortRuleAndUpdateOrder: store.changeFileSortRuleAndUpdateOrder, isFileSortRuleAbled: store.isFileSortRuleAbled, + isFileSortDisabled: store.isFileSortDisabled })) ); @@ -59,6 +61,7 @@ const SortFiles = () => { currentSortRule={fileSortRule} data-tooltip-position="bottom" aria-label={SORT_TIPS_COPY.sortFiles[language]} + disabled={isFileSortDisabled()} /> ); }; diff --git a/src/components/SortAction.tsx b/src/components/SortAction.tsx index 91ed3bc..f999bcc 100644 --- a/src/components/SortAction.tsx +++ b/src/components/SortAction.tsx @@ -1,3 +1,4 @@ +import classNames from "classnames"; import { Menu } from "obsidian"; import { @@ -26,17 +27,21 @@ type Props = { menuName: string; changeSortRule: (rule: string) => void; currentSortRule: SortRule; + disabled?: boolean; }; const SortAction = ({ ruleGroups, menuName, changeSortRule, currentSortRule, + disabled = false, ...props }: Props) => { const { plugin } = useExplorer(); const onChangeSortRule = (e: React.MouseEvent) => { + if (disabled) return; + const menu = new Menu(); ruleGroups.forEach((rules) => { rules.forEach(({ text, rule, disabled }) => { @@ -64,12 +69,17 @@ const SortAction = ({ ); }; + const getClassNames = () => { + return classNames( + "ffs__action-button-wrapper clickable-icon nav-action-button", + { + "ffs__action-button-wrapper--disabled": disabled, + } + ); + }; + return ( -
+
{renderIcon()}
); diff --git a/src/store/file/sort.ts b/src/store/file/sort.ts index a318f9c..1dcf76f 100644 --- a/src/store/file/sort.ts +++ b/src/store/file/sort.ts @@ -33,7 +33,9 @@ export interface SortFileSlice { filesSortRulesGroup: FileSortRule[][]; canManualSortViewModes: ViewMode[]; + sortDisabledViewModes: ViewMode[]; + isFileSortDisabled: () => boolean; isFileSortRuleAbled: (rule: FileSortRule) => boolean; sortFiles: (files: TFile[]) => TFile[]; restoreFileSortRule: () => Promise; @@ -61,6 +63,15 @@ export const createSortFileSlice = return [VIEW_MODE.FOLDER]; }, + get sortDisabledViewModes(): ViewMode[] { + return [VIEW_MODE.SEARCH]; + }, + + isFileSortDisabled(): boolean { + const { sortDisabledViewModes, viewMode } = get(); + return sortDisabledViewModes.includes(viewMode); + }, + isFileSortRuleAbled: (rule: FileSortRule) => { const { canManualSortViewModes, viewMode } = get(); return rule === FILE_MANUAL_SORT_RULE