diff --git a/packages/client/src/Shell.jsx b/packages/client/src/Shell.jsx index c85c87d213..cfaa62d4a9 100644 --- a/packages/client/src/Shell.jsx +++ b/packages/client/src/Shell.jsx @@ -63,7 +63,7 @@ import DialogsWrapper from "./components/dialogs/DialogsWrapper"; const Payments = React.lazy(() => import("./pages/Payments")); const Error404 = React.lazy(() => import("studio/Error404")); const Error401 = React.lazy(() => import("studio/Error401")); -const Home = React.lazy(() => import("./pages/Files")); //import("./components/pages/Home")); +const Files = React.lazy(() => import("./pages/Files")); //import("./components/pages/Home")); const About = React.lazy(() => import("./pages/About")); const Wizard = React.lazy(() => import("./pages/Wizard")); @@ -75,6 +75,8 @@ const EnterCode = !IS_PERSONAL && React.lazy(() => import("login/codeLogin")); const InvalidError = React.lazy(() => import("./pages/Errors/Invalid")); const PreparationPortal = React.lazy(() => import("./pages/PreparationPortal")); +const FormGallery = React.lazy(() => import("./pages/FormGallery")); + const PortalSettingsRoute = (props) => ( }> @@ -105,10 +107,10 @@ const Error401Route = (props) => ( ); -const HomeRoute = (props) => ( +const FilesRoute = (props) => ( }> - + ); @@ -147,13 +149,13 @@ const WizardRoute = (props) => ( ); -const MyProfileRoute = (props) => ( - }> - - - - -); +// const MyProfileRoute = (props) => ( +// }> +// +// +// +// +// ); const EnterCodeRoute = !IS_PERSONAL && @@ -173,7 +175,15 @@ const InvalidRoute = (props) => ( ); -const RedirectToHome = () => ; +const FormGalleryRoute = (props) => ( + }> + + + + +); + +// const RedirectToHome = () => ; const Shell = ({ items = [], page = "home", ...rest }) => { const { @@ -484,27 +494,50 @@ const Shell = ({ items = [], page = "home", ...rest }) => { exact path={[ "/", - "/filter", - "/rooms", - "/settings", - "/settings/common", - "/settings/admin", - "/settings/connected-clouds", - "/form-gallery/:folderId", - ]} - component={HomeRoute} - /> - + + + {loginRoutes} diff --git a/packages/client/src/components/Article/Body/index.js b/packages/client/src/components/Article/Body/index.js index 6783eb357e..a1a9251458 100644 --- a/packages/client/src/components/Article/Body/index.js +++ b/packages/client/src/components/Article/Body/index.js @@ -21,6 +21,8 @@ import Loaders from "@docspace/common/components/Loaders"; import withLoader from "../../../HOCs/withLoader"; import { withTranslation } from "react-i18next"; import toastr from "studio/toastr"; +import { getCategoryUrl } from "SRC_DIR/helpers/utils"; +import { CategoryType } from "SRC_DIR/helpers/constants"; const StyledBlock = styled.div` padding: 0 20px; @@ -78,13 +80,19 @@ const ArticleBodyContent = (props) => { if (filesSection) { const filter = RoomsFilter.getDefault(); - const urlFilter = filter.toUrlParams(); + const url = getCategoryUrl( + data === archiveFolderId + ? CategoryType.Archive + : CategoryType.Shared + ); + + const filterParamsStr = filter.toUrlParams(); history.push( combineUrl( AppServerConfig.proxyURL, homepage, - `/rooms?${urlFilter}` + `${url}?${filterParamsStr}` ) ); } diff --git a/packages/client/src/helpers/constants.js b/packages/client/src/helpers/constants.js index 82131c60ec..b4e1b8b96d 100644 --- a/packages/client/src/helpers/constants.js +++ b/packages/client/src/helpers/constants.js @@ -34,4 +34,19 @@ export const ValidationResult = Object.freeze({ export const GUID_EMPTY = "00000000-0000-0000-0000-000000000000"; export const ID_NO_GROUP_MANAGER = "4a515a15-d4d6-4b8e-828e-e0586f18f3a3"; -export const ADS_TIMEOUT = 300000; // 5 min \ No newline at end of file +export const ADS_TIMEOUT = 300000; // 5 min + +/** + * Enum for type of confirm link. + * @readonly + */ +export const CategoryType = Object.freeze({ + Personal: 0, + Shared: 1, + SharedRoom: 2, + Archive: 3, + ArchivedRoom: 4, + Favorite: 5, + Recent: 6, + Trash: 7, +}); diff --git a/packages/client/src/helpers/utils.js b/packages/client/src/helpers/utils.js index 09f7ed3b15..c46602ce54 100644 --- a/packages/client/src/helpers/utils.js +++ b/packages/client/src/helpers/utils.js @@ -2,6 +2,8 @@ import authStore from "@docspace/common/store/AuthStore"; import { toCommunityHostname } from "@docspace/common/utils"; import history from "@docspace/common/history"; import { useEffect, useState } from "react"; +import { CategoryType } from "./constants"; +import { FolderType } from "@docspace/common/constants"; export const setDocumentTitle = (subTitle = null) => { const { isAuthenticated, settingsStore, product: currentModule } = authStore; @@ -110,3 +112,84 @@ export const useThemeDetector = () => { return systemTheme; }; + +export const getCategoryType = (location) => { + let categoryType = CategoryType.Personal; + const { pathname } = location; + + if (pathname.startsWith("/rooms")) { + if (pathname.indexOf("personal") > -1) { + categoryType = CategoryType.Personal; + } else if (pathname.indexOf("shared") > -1) { + categoryType = + pathname.indexOf("shared/filter") > -1 + ? CategoryType.Shared + : CategoryType.SharedRoom; + } else if (pathname.indexOf("archive") > -1) { + categoryType = CategoryType.Archive; + } + } else if (pathname.startsWith("/favorite") > -1) { + categoryType = CategoryType.Favorite; + } else if (pathname.startsWith("/recent") > -1) { + categoryType = CategoryType.Recent; + } else if (pathname.startsWith("/trash") > -1) { + categoryType = CategoryType.Trash; + } + + return categoryType; +}; + +export const getCategoryTypeByFolderType = (folderType, parentId) => { + switch (folderType) { + case FolderType.Rooms: + return parentId > 0 ? CategoryType.SharedRoom : CategoryType.Shared; + + case FolderType.Archive: + return CategoryType.Archive; + + case FolderType.Favorites: + return CategoryType.Favorite; + + case FolderType.Recent: + return CategoryType.Recent; + + case FolderType.TRASH: + return CategoryType.Trash; + + default: + return CategoryType.Personal; + } +}; + +export const getCategoryUrl = (categoryType, folderId = null) => { + const cType = categoryType; + + switch (cType) { + case CategoryType.Personal: + return "/rooms/personal/filter"; + + case CategoryType.Shared: + return "/rooms/shared/filter"; + + case CategoryType.SharedRoom: + return `/rooms/shared/${folderId}/filter`; + + case CategoryType.Archive: + return "/rooms/archived/filter"; + + case CategoryType.ArchivedRoom: + return "/rooms/archived/${folderId}/filter"; + + case CategoryType.Favorite: + return "/files/favorite/filter"; + + case CategoryType.Recent: + return "/files/recent/filter"; + + case CategoryType.Trash: + return "/files/trash/filter"; + + default: + throw new Error("Unknown category type"); + } +}; diff --git a/packages/client/src/pages/Files.jsx b/packages/client/src/pages/Files.jsx index cffd731271..56b7d1ad10 100644 --- a/packages/client/src/pages/Files.jsx +++ b/packages/client/src/pages/Files.jsx @@ -1,7 +1,7 @@ import React from "react"; //import { Provider as FilesProvider } from "mobx-react"; import { inject, observer } from "mobx-react"; -import { Switch, withRouter } from "react-router-dom"; +import { Switch, withRouter, Redirect } from "react-router-dom"; //import config from "PACKAGE_FILE"; import PrivateRoute from "@docspace/common/components/PrivateRoute"; import AppLoader from "@docspace/common/components/AppLoader"; @@ -28,7 +28,7 @@ import { ArticleHeaderContent, ArticleMainButtonContent, } from "../components/Article"; -import FormGallery from "./FormGallery"; + import GlobalEvents from "../components/GlobalEvents"; import Accounts from "./Accounts"; @@ -76,11 +76,44 @@ const FilesArticle = React.memo(({ history }) => { const FilesSection = React.memo(() => { return ( + {/**/} + {/* */} + } /> + + {/* */} + {/* */} + {/* */} + {/* */} { ]} component={Accounts} /> - {/**/} - - - - - - - {/* */} + ); diff --git a/packages/client/src/pages/Home/Section/Header/index.js b/packages/client/src/pages/Home/Section/Header/index.js index 857dddbb08..aa257b4a08 100644 --- a/packages/client/src/pages/Home/Section/Header/index.js +++ b/packages/client/src/pages/Home/Section/Header/index.js @@ -22,6 +22,7 @@ import { Events } from "@docspace/client/src/helpers/filesConstants"; import config from "PACKAGE_FILE"; import { combineUrl } from "@docspace/common/utils"; import RoomsFilter from "@docspace/common/api/rooms/filter"; +import { getCategoryUrl } from "SRC_DIR/helpers/utils"; const StyledContainer = styled.div` .table-container_group-menu { @@ -387,6 +388,8 @@ class SectionHeaderContent extends React.Component { history, setAlreadyFetchingRooms, + + categoryType, } = this.props; setIsLoading(true); @@ -397,14 +400,14 @@ class SectionHeaderContent extends React.Component { .then(() => { const filter = RoomsFilter.getDefault(); - const urlFilter = filter.toUrlParams(); + const filterParamsStr = filter.toUrlParams(); + + const url = getCategoryUrl(this.categoryType, filter.folder); + + const pathname = `${url}?${filterParamsStr}`; history.push( - combineUrl( - AppServerConfig.proxyURL, - config.homepage, - `/rooms?${urlFilter}` - ) + combineUrl(AppServerConfig.proxyURL, config.homepage, pathname) ); }) .finally(() => { @@ -538,6 +541,8 @@ export default inject( activeFolders, setAlreadyFetchingRooms, + + categoryType, } = filesStore; const { @@ -633,6 +638,8 @@ export default inject( isArchiveFolder, setAlreadyFetchingRooms, + + categoryType, }; } )( diff --git a/packages/client/src/pages/Home/index.js b/packages/client/src/pages/Home/index.js index 2f61f6d277..040b5f8f31 100644 --- a/packages/client/src/pages/Home/index.js +++ b/packages/client/src/pages/Home/index.js @@ -28,10 +28,12 @@ import { createTreeFolders } from "../../helpers/files-helpers"; import MediaViewer from "./MediaViewer"; import DragTooltip from "../../components/DragTooltip"; import { observer, inject } from "mobx-react"; -import config from "PACKAGE_FILE"; +//import config from "PACKAGE_FILE"; import { Consumer } from "@docspace/components/utils/context"; import { Events } from "@docspace/client/src/helpers/filesConstants"; import RoomsFilter from "@docspace/common/api/rooms/filter"; +import { getCategoryType } from "SRC_DIR/helpers/utils"; +import { CategoryType } from "SRC_DIR/helpers/constants"; class PureHome extends React.Component { componentDidMount() { @@ -40,7 +42,7 @@ class PureHome extends React.Component { fetchRooms, alreadyFetchingRooms, setAlreadyFetchingRooms, - homepage, + //homepage, setIsLoading, setFirstLoad, expandedKeys, @@ -57,19 +59,12 @@ class PureHome extends React.Component { localStorage.removeItem("isFirstUrl"); } - const reg = new RegExp(`${homepage}((/?)$|/filter)`, "gmi"); //TODO: Always find? - const roomsReg = new RegExp(`${homepage}((/?)$|/rooms)`, "gmi"); - - const match = window.location.pathname.match(reg); - const roomsMatch = window.location.pathname.match(roomsReg); + const categoryType = getCategoryType(location); let filterObj = null; let isRooms = false; - if ( - window.location.href.indexOf("/files/#preview") > 1 && - playlist.length < 1 - ) { + if (window.location.href.indexOf("/#preview") > 1 && playlist.length < 1) { const pathname = window.location.href; const fileId = pathname.slice(pathname.indexOf("#preview") + 9); @@ -89,11 +84,21 @@ class PureHome extends React.Component { return; } - if (match && match.length > 0) { - if (window.location.href.includes("#preview")) { + if ( + categoryType == CategoryType.Shared || + categoryType == CategoryType.Archive + ) { + filterObj = RoomsFilter.getFilter(window.location); + + isRooms = true; + + if (!filterObj) { + setIsLoading(true); + this.fetchDefaultRooms(); + return; } - + } else { filterObj = FilesFilter.getFilter(window.location); if (!filterObj) { @@ -104,23 +109,6 @@ class PureHome extends React.Component { } } - if (roomsMatch && roomsMatch.length > 0) { - if (window.location.href.includes("#preview")) { - return; - } - - isRooms = true; - - filterObj = RoomsFilter.getFilter(window.location); - - if (!filterObj) { - setIsLoading(true); - this.fetchDefaultRooms(); - - return; - } - } - if (!filterObj) return; if (isRooms && alreadyFetchingRooms) return setAlreadyFetchingRooms(false); @@ -257,9 +245,9 @@ class PureHome extends React.Component { } fetchDefaultFiles = () => { - const { isVisitor, fetchFiles, setIsLoading, setFirstLoad } = this.props; + const { fetchFiles, setIsLoading, setFirstLoad } = this.props; const filterObj = FilesFilter.getDefault(); - const folderId = isVisitor ? "@common" : filterObj.folder; + const folderId = filterObj.folder; fetchFiles(folderId).finally(() => { setIsLoading(false); @@ -555,7 +543,7 @@ export default inject( } return { - homepage: config.homepage, + //homepage: config.homepage, firstLoad, dragging, viewAs, diff --git a/packages/client/src/store/FilesStore.js b/packages/client/src/store/FilesStore.js index 30401e48ce..4630ffd262 100644 --- a/packages/client/src/store/FilesStore.js +++ b/packages/client/src/store/FilesStore.js @@ -19,6 +19,12 @@ import config from "PACKAGE_FILE"; import { thumbnailStatuses } from "@docspace/client/src/helpers/filesConstants"; import { loopTreeFolders } from "../helpers/files-helpers"; import { openDocEditor as openEditor } from "@docspace/client/src/helpers/filesUtils"; +import { getCategoryUrl } from "SRC_DIR/helpers/utils"; +import { CategoryType } from "SRC_DIR/helpers/constants"; +import { + getCategoryType, + getCategoryTypeByFolderType, +} from "SRC_DIR/helpers/utils"; const { FilesFilter, RoomsFilter } = api; const storageViewAs = localStorage.getItem("viewAs"); @@ -62,6 +68,8 @@ class FilesStore { filter = FilesFilter.getDefault(); //TODO: FILTER roomsFilter = RoomsFilter.getDefault(); + categoryType = getCategoryType(window.location); + loadTimeout = null; hotkeyCaret = null; hotkeyCaretStart = null; @@ -583,12 +591,22 @@ class FilesStore { return api.files.setFileOwner(folderIds, fileIds, ownerId); }; - setFilterUrl = (filter, isRooms = false) => { - const urlFilter = filter.toUrlParams(); + setFilterUrl = (filter) => { + const filterParamsStr = filter.toUrlParams(); - const str = isRooms ? `/rooms?${urlFilter}` : `/filter?${urlFilter}`; + const url = getCategoryUrl(this.categoryType, filter.folder); - history.push(combineUrl(AppServerConfig.proxyURL, config.homepage, str)); + const pathname = `${url}?${filterParamsStr}`; + + console.log("setFilterUrl", { + categoryType: this.categoryType, + url, + filterParamsStr, + }); + + history.push( + combineUrl(AppServerConfig.proxyURL, config.homepage, pathname) + ); }; isEmptyLastPageAfterOperation = (newSelection) => { @@ -697,6 +715,19 @@ class FilesStore { const isPrivacyFolder = data.current.rootFolderType === FolderType.Privacy; + runInAction(() => { + this.categoryType = getCategoryTypeByFolderType( + data.current.rootFolderType, + data.current.parentId + ); + }); + + console.log("fetchFiles", { + categoryType: this.categoryType, + rootFolderType: data.current.rootFolderType, + parentId: data.current.parentId, + }); + this.setFilesFilter(filterData); //TODO: FILTER runInAction(() => { @@ -837,6 +868,19 @@ class FilesStore { } } + runInAction(() => { + this.categoryType = getCategoryTypeByFolderType( + data.current.rootFolderType, + data.current.parentId + ); + }); + + console.log("fetchRooms", { + categoryType: this.categoryType, + rootFolderType: data.current.rootFolderType, + parentId: data.current.parentId, + }); + this.setRoomsFilter(filterData); runInAction(() => {