DocSpace-client/packages/shared/utils/catalogIconHelper.ts

165 lines
9.3 KiB
TypeScript

// (c) Copyright Ascensio System SIA 2009-2024
//
// This program is a free software product.
// You can redistribute it and/or modify it under the terms
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
// any third-party rights.
//
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
//
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
//
// The interactive user interfaces in modified source and object code versions of the Program must
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
//
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
// trademark law for use of our trademarks.
//
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
import CatalogFolderReactSvgUrl from "PUBLIC_DIR/images/catalog.folder.react.svg?url";
// import CatalogUserReactSvgUrl from "PUBLIC_DIR/images/catalog.user.react.svg?url";
import CatalogDocumentsReactSvgUrl from "PUBLIC_DIR/images/catalog.documents.react.svg?url";
import CatalogRoomsReactSvgUrl from "PUBLIC_DIR/images/catalog.rooms.react.svg?url";
import CatalogArchiveReactSvgUrl from "PUBLIC_DIR/images/catalog.archive.react.svg?url";
import CatalogSharedReactSvgUrl from "PUBLIC_DIR/images/catalog.shared.react.svg?url";
import CatalogPortfolioReactSvgUrl from "PUBLIC_DIR/images/catalog.portfolio.react.svg?url";
import CatalogFavoritesReactSvgUrl from "PUBLIC_DIR/images/catalog.favorites.react.svg?url";
import CatalogRecentReactSvgUrl from "PUBLIC_DIR/images/catalog.recent.react.svg?url";
import CatalogPrivateReactSvgUrl from "PUBLIC_DIR/images/catalog.private.react.svg?url";
import CatalogTrashReactSvgUrl from "PUBLIC_DIR/images/catalog.trash.react.svg?url";
import CatalogAccountsReactSvgUrl from "PUBLIC_DIR/images/catalog.accounts.react.svg?url";
import CatalogSettingsCommonReactSvgUrl from "PUBLIC_DIR/images/icons/16/catalog-settings-common.svg?url";
import CatalogSettingsSecurityReactSvgUrl from "PUBLIC_DIR/images/icons/16/catalog-settings-security.svg?url";
import CatalogSettingsDataManagementReactSvgUrl from "PUBLIC_DIR/images/icons/16/catalog-settings-data-management.svg?url";
import CatalogSettingsRestoreReactSvgUrl from "PUBLIC_DIR/images/icons/16/catalog-settings-restore.svg?url";
import CatalogSettingsIntegrationReactSvgUrl from "PUBLIC_DIR/images/icons/16/catalog-settings-integration.svg?url";
import CatalogSettingsDataReactSvgUrl from "PUBLIC_DIR/images/catalog.import.react.svg?url";
import CatalogSettingsDeveloperReactSvgUrl from "PUBLIC_DIR/images/catalog.developer.react.svg?url";
import CatalogSettingsPaymentReactSvgUrl from "PUBLIC_DIR/images/icons/16/catalog-settings-payment.svg?url";
import CatalogSettingsGiftReactSvgUrl from "PUBLIC_DIR/images/gift.react.svg?url";
import CatalogSettingsStorageManagementReactSvgUrl from "PUBLIC_DIR/images/icons/16/catalog-settings-storage-management.svg?url";
import CatalogFolder20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog.folder.react.svg?url";
import CatalogDocuments20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog.documents.react.svg?url";
import CatalogRooms20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog.rooms.react.svg?url";
import CatalogArchive20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog.archive.react.svg?url";
import CatalogShared20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog.shared.react.svg?url";
import CatalogPortfolio20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog.portfolio.react.svg?url";
import CatalogFavorites20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog.favorites.react.svg?url";
import CatalogRecent20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog.recent.react.svg?url";
import CatalogPrivate20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog.private.react.svg?url";
import CatalogTrash20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog.trash.react.svg?url";
import CatalogAccounts20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog.accounts.react.svg?url";
import CatalogSettingsCommon20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog-settings-common.svg?url";
import CatalogSettingsSecurity20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog-settings-security.svg?url";
import CatalogSettingsDataManagement20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog-settings-data-management.svg?url";
import CatalogSettingsRestore20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog-settings-restore.svg?url";
import CatalogSettingsIntegration20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog-settings-integration.svg?url";
import CatalogSettingsData20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog-settings-import.svg?url";
import CatalogSettingsDeveloper20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog-settings-developer.svg?url";
import CatalogSettingsPayment20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog-settings-payment.svg?url";
import CatalogSettingsGift20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog-settings-gift.svg?url";
import CatalogSettingsStorageManagement20ReactSvgUrl from "PUBLIC_DIR/images/icons/20/catalog-settings-storage-management.svg?url";
import { FolderType, PageType } from "../enums";
import { isMobile, isTablet } from "./device";
type FolderUnionType = (typeof FolderType)[keyof typeof FolderType];
type SettingsPageUnionType = (typeof PageType)[keyof typeof PageType];
type PageUnionType = FolderUnionType | SettingsPageUnionType;
type SizeType = 16 | 20;
type OptionsType = {
[P in string]: string | boolean;
};
const defaultIcon: Record<SizeType, string> = {
16: CatalogFolderReactSvgUrl,
20: CatalogFolder20ReactSvgUrl,
};
const icons: Record<SizeType, Partial<Record<PageUnionType, string>>> = {
16: {
[FolderType.USER]: CatalogDocumentsReactSvgUrl,
[FolderType.Rooms]: CatalogRoomsReactSvgUrl,
[FolderType.Archive]: CatalogArchiveReactSvgUrl,
[FolderType.SHARE]: CatalogSharedReactSvgUrl,
[FolderType.COMMON]: CatalogPortfolioReactSvgUrl,
[FolderType.Favorites]: CatalogFavoritesReactSvgUrl,
[FolderType.Recent]: CatalogRecentReactSvgUrl,
[FolderType.Privacy]: CatalogPrivateReactSvgUrl,
[FolderType.TRASH]: CatalogTrashReactSvgUrl,
[PageType.account]: CatalogAccountsReactSvgUrl,
[PageType.customization]: CatalogSettingsCommonReactSvgUrl,
[PageType.security]: CatalogSettingsSecurityReactSvgUrl,
[PageType.backup]: CatalogSettingsDataManagementReactSvgUrl,
[PageType.restore]: CatalogSettingsRestoreReactSvgUrl,
[PageType.integration]: CatalogSettingsIntegrationReactSvgUrl,
[PageType.dataImport]: CatalogSettingsDataReactSvgUrl,
[PageType.developerTools]: CatalogSettingsDeveloperReactSvgUrl,
[PageType.portalDeletion]: CatalogTrashReactSvgUrl,
[PageType.payments]: CatalogSettingsPaymentReactSvgUrl,
[PageType.bonus]: CatalogSettingsGiftReactSvgUrl,
[PageType.storageManagement]: CatalogSettingsStorageManagementReactSvgUrl,
},
20: {
[FolderType.USER]: CatalogDocuments20ReactSvgUrl,
[FolderType.Rooms]: CatalogRooms20ReactSvgUrl,
[FolderType.Archive]: CatalogArchive20ReactSvgUrl,
[FolderType.SHARE]: CatalogShared20ReactSvgUrl,
[FolderType.COMMON]: CatalogPortfolio20ReactSvgUrl,
[FolderType.Favorites]: CatalogFavorites20ReactSvgUrl,
[FolderType.Recent]: CatalogRecent20ReactSvgUrl,
[FolderType.Privacy]: CatalogPrivate20ReactSvgUrl,
[FolderType.TRASH]: CatalogTrash20ReactSvgUrl,
[PageType.account]: CatalogAccounts20ReactSvgUrl,
[PageType.customization]: CatalogSettingsCommon20ReactSvgUrl,
[PageType.security]: CatalogSettingsSecurity20ReactSvgUrl,
[PageType.backup]: CatalogSettingsDataManagement20ReactSvgUrl,
[PageType.restore]: CatalogSettingsRestore20ReactSvgUrl,
[PageType.integration]: CatalogSettingsIntegration20ReactSvgUrl,
[PageType.dataImport]: CatalogSettingsData20ReactSvgUrl,
[PageType.developerTools]: CatalogSettingsDeveloper20ReactSvgUrl,
[PageType.portalDeletion]: CatalogTrash20ReactSvgUrl,
[PageType.payments]: CatalogSettingsPayment20ReactSvgUrl,
[PageType.bonus]: CatalogSettingsGift20ReactSvgUrl,
[PageType.storageManagement]: CatalogSettingsStorageManagement20ReactSvgUrl,
},
};
const MobileIconSize = 20;
const DesktopIconSize = 16;
const NullURL = "";
// const isSettingsCatalog = (
// pageType: PageUnionType
// ): pageType is SettingsPageUnionType => {
// return typeof pageType === "string";
// };
export const getCatalogIconUrlByType = (
pageType: PageUnionType,
options?: OptionsType,
): string => {
const size: SizeType =
isMobile() || isTablet() ? MobileIconSize : DesktopIconSize;
const defaultIconUrl = options?.isSettingsCatalog
? NullURL
: defaultIcon[size];
return icons[size]?.[pageType] ?? defaultIconUrl;
};