moved selection calculation logic to info panel store and added several selection helper methods
This commit is contained in:
parent
fced6f6ff1
commit
521d6f9250
@ -19,6 +19,7 @@ class InfoPanelStore {
|
||||
authStore = null;
|
||||
settingsStore = null;
|
||||
peopleStore = null;
|
||||
filesStore = null;
|
||||
selectedFolderStore = null;
|
||||
treeFoldersStore = null;
|
||||
|
||||
@ -26,6 +27,8 @@ class InfoPanelStore {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
// Setters
|
||||
|
||||
setIsVisible = (bool) => (this.isVisible = bool);
|
||||
|
||||
setSelection = (selection) => (this.selection = selection);
|
||||
@ -36,18 +39,79 @@ class InfoPanelStore {
|
||||
this.fileView = view === "members" ? "history" : view;
|
||||
};
|
||||
|
||||
// Selection helpers //
|
||||
|
||||
getSelectedItems = () => {
|
||||
const { selection: filesStoreSelection } = this.filesStore;
|
||||
const {
|
||||
selection: peopleStoreSelection,
|
||||
bufferSelection: peopleStoreBufferSelection,
|
||||
} = this.peopleStore.selectionStore;
|
||||
|
||||
return this.getIsAccounts()
|
||||
? peopleStoreSelection.length
|
||||
? [...peopleStoreSelection]
|
||||
: peopleStoreBufferSelection
|
||||
? [peopleStoreBufferSelection]
|
||||
: []
|
||||
: filesStoreSelection?.length > 0
|
||||
? [...filesStoreSelection]
|
||||
: [];
|
||||
};
|
||||
|
||||
getSelectedFolder = () => {
|
||||
const selectedFolderStore = { ...this.selectedFolderStore };
|
||||
return {
|
||||
selectedFolderStore,
|
||||
isFolder: true,
|
||||
isRoom: !!this.selectedFolderStore.roomType,
|
||||
};
|
||||
};
|
||||
|
||||
calculateSelection = (
|
||||
props = { selectedItems: [], selectedFolder: null }
|
||||
) => {
|
||||
const selectedItems = props.selectedItems.length
|
||||
? props.selectedItems
|
||||
: this.getSelectedItems();
|
||||
|
||||
const selectedFolder = props.selectedFolder
|
||||
? props.selectedFolder
|
||||
: this.getSelectedFolder();
|
||||
|
||||
return selectedItems.length === 0
|
||||
? this.normalizeSelection({
|
||||
...selectedFolder,
|
||||
isSelectedFolder: true,
|
||||
isSelectedItem: false,
|
||||
})
|
||||
: selectedItems.length === 1
|
||||
? this.normalizeSelection({
|
||||
...selectedItems[0],
|
||||
isSelectedFolder: false,
|
||||
isSelectedItem: true,
|
||||
})
|
||||
: [...Array(selectedItems.length).keys()];
|
||||
};
|
||||
|
||||
normalizeSelection = (selection) => {
|
||||
const isContextMenuSelection = selection.isContextMenuSelection;
|
||||
return {
|
||||
...selection,
|
||||
isRoom: selection.isRoom || !!selection.roomType,
|
||||
icon: this.getItemIcon(selection, 32),
|
||||
icon: this.getInfoPanelItemIcon(selection, 32),
|
||||
isContextMenuSelection: false,
|
||||
wasContextMenuSelection: !!isContextMenuSelection,
|
||||
};
|
||||
};
|
||||
|
||||
getItemIcon = (item, size) => {
|
||||
reloadSelection = () => {
|
||||
this.setSelection(this.calculateSelection());
|
||||
};
|
||||
|
||||
// Icon helpers //
|
||||
|
||||
getInfoPanelItemIcon = (item, size) => {
|
||||
return item.isRoom || !!item.roomType
|
||||
? item.logo && item.logo.medium
|
||||
? item.logo.medium
|
||||
@ -59,6 +123,18 @@ class InfoPanelStore {
|
||||
: this.settingsStore.getIcon(size, item.fileExst || ".file");
|
||||
};
|
||||
|
||||
// User link actions //
|
||||
|
||||
openUser = async (userId, history) => {
|
||||
if (userId === this.authStore.userStore.user.id) {
|
||||
this.openSelfProfile(history);
|
||||
return;
|
||||
}
|
||||
|
||||
const fetchedUser = await this.fetchUser(userId);
|
||||
this.openAccountsWithSelectedUser(fetchedUser, history);
|
||||
};
|
||||
|
||||
openSelfProfile = (history) => {
|
||||
const path = [
|
||||
AppServerConfig.proxyURL,
|
||||
@ -109,18 +185,15 @@ class InfoPanelStore {
|
||||
return fetchedUser;
|
||||
};
|
||||
|
||||
openUser = async (userId, history) => {
|
||||
if (userId === this.authStore.userStore.user.id) {
|
||||
this.openSelfProfile(history);
|
||||
return;
|
||||
}
|
||||
// Routing helpers //
|
||||
|
||||
const fetchedUser = await this.fetchUser(userId);
|
||||
this.openAccountsWithSelectedUser(fetchedUser, history);
|
||||
};
|
||||
|
||||
getItemNoThumbnail = (item) => {
|
||||
this.getItemIcon(item, 96);
|
||||
getCanDisplay = () => {
|
||||
const pathname = window.location.pathname.toLowerCase();
|
||||
const isFiles = this.getIsFiles(pathname);
|
||||
const isRooms = this.getIsRooms(pathname);
|
||||
const isAccounts = this.getIsAccounts(pathname);
|
||||
const isGallery = this.getIsGallery(pathname);
|
||||
return isRooms || isFiles || isGallery || isAccounts;
|
||||
};
|
||||
|
||||
getIsFiles = (givenPathName) => {
|
||||
@ -148,15 +221,6 @@ class InfoPanelStore {
|
||||
const pathname = givenPathName || window.location.pathname.toLowerCase();
|
||||
return pathname.indexOf("form-gallery") !== -1;
|
||||
};
|
||||
|
||||
getCanDisplay = () => {
|
||||
const pathname = window.location.pathname.toLowerCase();
|
||||
const isFiles = this.getIsFiles(pathname);
|
||||
const isRooms = this.getIsRooms(pathname);
|
||||
const isAccounts = this.getIsAccounts(pathname);
|
||||
const isGallery = this.getIsGallery(pathname);
|
||||
return isRooms || isFiles || isGallery || isAccounts;
|
||||
};
|
||||
}
|
||||
|
||||
export default InfoPanelStore;
|
||||
|
Loading…
Reference in New Issue
Block a user