Client: fixed the logic for determining the selected elements, refactoring

This commit is contained in:
Dmitry Sychugov 2024-05-23 21:13:03 +05:00
parent a0a4abadae
commit 131d99d84c
4 changed files with 29 additions and 18 deletions

View File

@ -412,7 +412,7 @@ export default function withFileActions(WrappedFileItem) {
(x) => x.id === item.id && x.fileExst === item.fileExst,
);
const isIndexUpdated = !!updateSelection.find((x) => x === item.id);
const isIndexUpdated = !!updateSelection.find((x) => x.id === item.id);
const isDisabledDropItem = item.security?.Create === false;

View File

@ -2729,7 +2729,7 @@ class FilesActionStore {
changeIndex = async (action, item) => {
const { filesList } = this.filesStore;
const { id } = this.selectedFolderStore;
const { updateSelection, setUpdateSelection } = this.indexingStore;
const { setUpdateItems } = this.indexingStore;
const index = filesList.findIndex((elem) => elem.id === item?.id);
const operationId = uniqueid("operation_");
@ -2748,19 +2748,9 @@ class FilesActionStore {
await changeIndex(item?.id, replaceable.order, item?.isFolder);
const newSelection = [...updateSelection];
const addedArray = [item.id, replaceable.id];
const items = [item, replaceable];
for (const id of addedArray) {
const exist = updateSelection.find(
(selectionItem) => selectionItem === id,
);
if (exist) continue;
newSelection.push(id);
}
setUpdateSelection(newSelection);
setUpdateItems(items);
this.updateCurrentFolder(null, [id], true, operationId);
};

View File

@ -27,20 +27,23 @@
import { makeAutoObservable } from "mobx";
class IndexingStore {
selectedFolderStore;
infoPanelStore;
isIndexEditingMode = false;
isIndexing = false;
updateSelection = [];
constructor(selectedFolderStore) {
this.selectedFolderStore = selectedFolderStore;
constructor(infoPanelStore) {
this.infoPanelStore = infoPanelStore;
makeAutoObservable(this);
}
setIsIndexing = (indexing) => {
// turn off the mode if we are no longer in indexed folders
const { setIsVisible } = this.infoPanelStore;
if (!indexing && this.isIndexEditingMode) this.setIsIndexEditingMode(false);
if (!indexing) setIsVisible(false);
this.isIndexing = indexing;
};
@ -48,10 +51,28 @@ class IndexingStore {
this.updateSelection = selection;
};
setUpdateItems = (items) => {
const newSelection = [...this.updateSelection];
for (const item of items) {
const exist = this.updateSelection.find(
(selectionItem) =>
selectionItem.id === item.id &&
selectionItem.fileExst === item.fileExst,
);
if (exist) continue;
newSelection.push(item);
}
this.setUpdateSelection(newSelection);
};
setIsIndexEditingMode = (mode) => {
if (!mode) {
this.setUpdateSelection([]);
}
const { setIsVisible } = this.infoPanelStore;
setIsVisible(false);
this.isIndexEditingMode = mode;
};
}

View File

@ -105,7 +105,6 @@ const setupStore = new SettingsSetupStore(
const confirmStore = new ConfirmStore();
const backupStore = new BackupStore();
const commonStore = new CommonStore(settingsStore);
const indexingStore = new IndexingStore(selectedFolderStore);
const ssoStore = new SsoFormStore();
@ -115,6 +114,7 @@ const clientLoadingStore = new ClientLoadingStore();
const publicRoomStore = new PublicRoomStore(clientLoadingStore);
const infoPanelStore = new InfoPanelStore(userStore);
const indexingStore = new IndexingStore(infoPanelStore);
const treeFoldersStore = new TreeFoldersStore(
selectedFolderStore,