mirror of
https://github.com/xuquan-nikkkki/FolderFile-Splitter-Plugin.git
synced 2026-07-22 12:00:27 +00:00
feat: disable sort files in search view mode
This commit is contained in:
parent
292c18952a
commit
dfd0c10660
3 changed files with 29 additions and 5 deletions
|
|
@ -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()}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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<HTMLDivElement>) => {
|
||||
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 (
|
||||
<div
|
||||
className="ffs__action-button-wrapper clickable-icon nav-action-button"
|
||||
onClick={onChangeSortRule}
|
||||
{...props}
|
||||
>
|
||||
<div className={getClassNames()} onClick={onChangeSortRule} {...props}>
|
||||
{renderIcon()}
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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<void>;
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue