DocSpace-client/packages/common/store/InfoPanelStore.js

93 lines
2.7 KiB
JavaScript
Raw Normal View History

2022-02-08 12:11:31 +00:00
import { makeAutoObservable } from "mobx";
import { Events } from "@docspace/common/constants";
2022-02-08 12:11:31 +00:00
import { getCategoryType } from "@docspace/client/src/helpers/utils";
import { CategoryType } from "@docspace/client/src/helpers/constants";
2022-02-08 12:11:31 +00:00
2022-02-11 14:35:18 +00:00
class InfoPanelStore {
isVisible = false;
selection = null;
selectionParentRoom = null;
roomsView = "members";
fileView = "history";
settingsStore = null;
2022-02-08 12:11:31 +00:00
constructor() {
makeAutoObservable(this);
}
2022-02-08 12:11:31 +00:00
setSelection = (selection) => (this.selection = selection);
setSelectionParentRoom = (obj) => (this.selectionParentRoom = obj);
setIsVisible = (bool) => (this.isVisible = bool);
setSettingsStore = (settingsStore) => (this.settingsStore = settingsStore);
setView = (view) => {
this.roomsView = view;
this.fileView = view === "members" ? "history" : view;
};
normalizeSelection = (selection) => {
return {
...selection,
isRoom: selection.isRoom || !!selection.roomType,
icon: this.getItemIcon(selection, 32),
hasCustonThumbnail: !!selection.thumbnailUrl,
thumbnailUrl: selection.thumbnailUrl || this.getItemIcon(selection, 96),
isContextMenuSelection: false,
};
2022-08-09 16:05:36 +00:00
};
getItemIcon = (item, size) => {
return item.isRoom || !!item.roomType
? item.logo && item.logo.big
? item.logo.big
: item.icon
? item.icon
: this.settingsStore.getIcon(size, null, null, null, item.roomType)
: item.isFolder
? this.settingsStore.getFolderIcon(item.providerKey, size)
: this.settingsStore.getIcon(size, item.fileExst || ".file");
};
getIsFileCategory = () => {
const categoryType = getCategoryType(location);
return (
categoryType == CategoryType.Personal ||
categoryType == CategoryType.Favorite ||
categoryType == CategoryType.Recent ||
categoryType == CategoryType.Trash
);
};
getIsRoomCategory = () => {
const categoryType = getCategoryType(location);
return (
categoryType == CategoryType.Shared ||
categoryType == CategoryType.SharedRoom ||
categoryType == CategoryType.Archive ||
categoryType == CategoryType.ArchivedRoom
);
};
getIsGallery = () => {
const pathname = window.location.pathname.toLowerCase();
return pathname.indexOf("form-gallery") !== -1;
};
getCanDisplay = () => {
const pathname = window.location.pathname.toLowerCase();
const isRooms = pathname.indexOf("rooms") !== -1;
const isFiles = pathname.indexOf("files") !== -1;
const isGallery = pathname.indexOf("form-gallery") !== -1;
const isAccountsHome =
pathname.indexOf("accounts") !== -1 && !(pathname.indexOf("view") !== -1);
return isRooms || isFiles || isGallery || isAccountsHome;
};
2022-02-08 12:11:31 +00:00
}
2022-02-11 14:35:18 +00:00
export default InfoPanelStore;