|
@@ -1,40 +1,27 @@
|
|
import { WorkspaceUser } from '../WorkspaceUser';
|
|
import { WorkspaceUser } from '../WorkspaceUser';
|
|
import { AppLogo } from '../AppLogo';
|
|
import { AppLogo } from '../AppLogo';
|
|
-import { FolderItem } from './FolderItem';
|
|
|
|
import { TrashButton } from './TrashButton';
|
|
import { TrashButton } from './TrashButton';
|
|
-import { NewFolderButton } from './NewFolderButton';
|
|
|
|
|
|
+import { NewViewButton } from './NewViewButton';
|
|
import { NavigationResizer } from './NavigationResizer';
|
|
import { NavigationResizer } from './NavigationResizer';
|
|
-import { IFolder } from '$app_reducers/folders/slice';
|
|
|
|
import { IPage } from '$app_reducers/pages/slice';
|
|
import { IPage } from '$app_reducers/pages/slice';
|
|
import { useLocation, useNavigate } from 'react-router-dom';
|
|
import { useLocation, useNavigate } from 'react-router-dom';
|
|
import React, { useEffect, useRef, useState } from 'react';
|
|
import React, { useEffect, useRef, useState } from 'react';
|
|
import { useAppSelector } from '$app/stores/store';
|
|
import { useAppSelector } from '$app/stores/store';
|
|
-import {
|
|
|
|
- ANIMATION_DURATION,
|
|
|
|
- FOLDER_MARGIN,
|
|
|
|
- INITIAL_FOLDER_HEIGHT,
|
|
|
|
- NAV_PANEL_MINIMUM_WIDTH,
|
|
|
|
- PAGE_ITEM_HEIGHT,
|
|
|
|
-} from '../../_shared/constants';
|
|
|
|
|
|
+import { NavItem } from '$app/components/layout/NavigationPanel/NavItem';
|
|
|
|
+import { ANIMATION_DURATION, NAV_PANEL_MINIMUM_WIDTH, PAGE_ITEM_HEIGHT } from '../../_shared/constants';
|
|
|
|
|
|
export const NavigationPanel = ({
|
|
export const NavigationPanel = ({
|
|
onHideMenuClick,
|
|
onHideMenuClick,
|
|
menuHidden,
|
|
menuHidden,
|
|
width,
|
|
width,
|
|
- folders,
|
|
|
|
- pages,
|
|
|
|
- onPageClick,
|
|
|
|
}: {
|
|
}: {
|
|
onHideMenuClick: () => void;
|
|
onHideMenuClick: () => void;
|
|
menuHidden: boolean;
|
|
menuHidden: boolean;
|
|
width: number;
|
|
width: number;
|
|
- folders: IFolder[];
|
|
|
|
- pages: IPage[];
|
|
|
|
- onPageClick: (page: IPage) => void;
|
|
|
|
}) => {
|
|
}) => {
|
|
const el = useRef<HTMLDivElement>(null);
|
|
const el = useRef<HTMLDivElement>(null);
|
|
- const foldersStore = useAppSelector((state) => state.folders);
|
|
|
|
- const pagesStore = useAppSelector((state) => state.pages);
|
|
|
|
|
|
+ const pages = useAppSelector((state) => state.pages);
|
|
|
|
+ const workspace = useAppSelector((state) => state.workspace);
|
|
const [activePageId, setActivePageId] = useState<string>('');
|
|
const [activePageId, setActivePageId] = useState<string>('');
|
|
const currentLocation = useLocation();
|
|
const currentLocation = useLocation();
|
|
const [maxHeight, setMaxHeight] = useState(0);
|
|
const [maxHeight, setMaxHeight] = useState(0);
|
|
@@ -47,44 +34,8 @@ export const NavigationPanel = ({
|
|
}, [currentLocation]);
|
|
}, [currentLocation]);
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
- setTimeout(() => {
|
|
|
|
- if (!el.current) return;
|
|
|
|
- if (!activePageId?.length) return;
|
|
|
|
- const activePage = pagesStore.find((page) => page.id === activePageId);
|
|
|
|
- if (!activePage) return;
|
|
|
|
-
|
|
|
|
- const folderIndex = foldersStore.findIndex((folder) => folder.id === activePage.folderId);
|
|
|
|
- if (folderIndex === -1) return;
|
|
|
|
-
|
|
|
|
- let height = 0;
|
|
|
|
- for (let i = 0; i < folderIndex; i++) {
|
|
|
|
- height += INITIAL_FOLDER_HEIGHT + FOLDER_MARGIN;
|
|
|
|
- if (foldersStore[i].showPages) {
|
|
|
|
- height += pagesStore.filter((p) => p.folderId === foldersStore[i].id).length * PAGE_ITEM_HEIGHT;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- height += INITIAL_FOLDER_HEIGHT + FOLDER_MARGIN / 2;
|
|
|
|
-
|
|
|
|
- const pageIndex = pagesStore
|
|
|
|
- .filter((p) => p.folderId === foldersStore[folderIndex].id)
|
|
|
|
- .findIndex((p) => p.id === activePageId);
|
|
|
|
- for (let i = 0; i <= pageIndex; i++) {
|
|
|
|
- height += PAGE_ITEM_HEIGHT;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const elHeight = el.current.getBoundingClientRect().height;
|
|
|
|
- const scrollTop = el.current.scrollTop;
|
|
|
|
-
|
|
|
|
- if (scrollTop + elHeight < height || scrollTop > height) {
|
|
|
|
- el.current.scrollTo({ top: height - elHeight, behavior: 'smooth' });
|
|
|
|
- }
|
|
|
|
- }, ANIMATION_DURATION);
|
|
|
|
- }, [activePageId]);
|
|
|
|
-
|
|
|
|
- useEffect(() => {
|
|
|
|
- setMaxHeight(foldersStore.length * (INITIAL_FOLDER_HEIGHT + FOLDER_MARGIN) + pagesStore.length * PAGE_ITEM_HEIGHT);
|
|
|
|
- }, [foldersStore, pagesStore]);
|
|
|
|
|
|
+ setMaxHeight(pages.length * PAGE_ITEM_HEIGHT);
|
|
|
|
+ }, [pages]);
|
|
|
|
|
|
const scrollDown = () => {
|
|
const scrollDown = () => {
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
@@ -113,7 +64,7 @@ export const NavigationPanel = ({
|
|
}}
|
|
}}
|
|
ref={el}
|
|
ref={el}
|
|
>
|
|
>
|
|
- <WorkspaceApps folders={folders} pages={pages} onPageClick={onPageClick} />
|
|
|
|
|
|
+ <WorkspaceApps pages={pages.filter((p) => p.parentPageId === workspace.id)} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@@ -130,8 +81,8 @@ export const NavigationPanel = ({
|
|
<TrashButton></TrashButton>
|
|
<TrashButton></TrashButton>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
- {/*New Folder Button*/}
|
|
|
|
- <NewFolderButton scrollDown={scrollDown}></NewFolderButton>
|
|
|
|
|
|
+ {/*New Root View Button*/}
|
|
|
|
+ <NewViewButton scrollDown={scrollDown}></NewViewButton>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<NavigationResizer minWidth={NAV_PANEL_MINIMUM_WIDTH}></NavigationResizer>
|
|
<NavigationResizer minWidth={NAV_PANEL_MINIMUM_WIDTH}></NavigationResizer>
|
|
@@ -139,21 +90,10 @@ export const NavigationPanel = ({
|
|
);
|
|
);
|
|
};
|
|
};
|
|
|
|
|
|
-type AppsContext = {
|
|
|
|
- folders: IFolder[];
|
|
|
|
- pages: IPage[];
|
|
|
|
- onPageClick: (page: IPage) => void;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-const WorkspaceApps: React.FC<AppsContext> = ({ folders, pages, onPageClick }) => (
|
|
|
|
|
|
+const WorkspaceApps: React.FC<{ pages: IPage[] }> = ({ pages }) => (
|
|
<>
|
|
<>
|
|
- {folders.map((folder, index) => (
|
|
|
|
- <FolderItem
|
|
|
|
- key={index}
|
|
|
|
- folder={folder}
|
|
|
|
- pages={pages.filter((page) => page.folderId === folder.id)}
|
|
|
|
- onPageClick={onPageClick}
|
|
|
|
- ></FolderItem>
|
|
|
|
|
|
+ {pages.map((page, index) => (
|
|
|
|
+ <NavItem key={index} page={page}></NavItem>
|
|
))}
|
|
))}
|
|
</>
|
|
</>
|
|
);
|
|
);
|