mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: breadcrumbs
This commit is contained in:
parent
7e3273c708
commit
da8c39d0b6
@ -1,6 +1,45 @@
|
|||||||
import { ShowMenuSvg } from '../../_shared/svg/ShowMenuSvg';
|
import { ShowMenuSvg } from '../../_shared/svg/ShowMenuSvg';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useAppSelector } from '../../../stores/store';
|
||||||
|
import { useLocation } from 'react-router-dom';
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
|
import { activePageIdActions } from '../../../stores/reducers/activePageId/slice';
|
||||||
|
|
||||||
export const Breadcrumbs = ({ menuHidden, onShowMenuClick }: { menuHidden: boolean; onShowMenuClick: () => void }) => {
|
export const Breadcrumbs = ({ menuHidden, onShowMenuClick }: { menuHidden: boolean; onShowMenuClick: () => void }) => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const [folderName, setFolderName] = useState('');
|
||||||
|
const [pageName, setPageName] = useState('');
|
||||||
|
const activePageId = useAppSelector((state) => state.activePageId);
|
||||||
|
const pagesStore = useAppSelector((state) => state.pages);
|
||||||
|
const foldersStore = useAppSelector((state) => state.folders);
|
||||||
|
const [pageHistory, setPageHistory] = useState<string[]>([]);
|
||||||
|
const [historyIndex, setHistoryIndex] = useState(0);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const page = pagesStore.find((p) => p.id === activePageId);
|
||||||
|
const folder = foldersStore.find((f) => f.id === page?.folderId);
|
||||||
|
setFolderName(folder?.title || '');
|
||||||
|
setPageName(page?.title || '');
|
||||||
|
setPageHistory([...pageHistory, activePageId]);
|
||||||
|
}, [pagesStore, foldersStore, activePageId]);
|
||||||
|
|
||||||
|
const currentLocation = useLocation();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// if there is no active page, we should try to get the page id from the url
|
||||||
|
if (!activePageId?.length) {
|
||||||
|
const { pathname } = currentLocation;
|
||||||
|
const parts = pathname.split('/');
|
||||||
|
// `/"page"/{pageType}/{pageId}`
|
||||||
|
if (parts.length !== 4) return;
|
||||||
|
|
||||||
|
const pageId = parts[parts.length - 1];
|
||||||
|
// const pageType = parts[parts.length - 2];
|
||||||
|
|
||||||
|
dispatch(activePageIdActions.setActivePageId(pageId));
|
||||||
|
}
|
||||||
|
}, [activePageId, currentLocation]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'flex items-center'}>
|
<div className={'flex items-center'}>
|
||||||
<div className={'mr-4 flex items-center'}>
|
<div className={'mr-4 flex items-center'}>
|
||||||
@ -13,14 +52,14 @@ export const Breadcrumbs = ({ menuHidden, onShowMenuClick }: { menuHidden: boole
|
|||||||
<button className={'p-1'} onClick={() => history.back()}>
|
<button className={'p-1'} onClick={() => history.back()}>
|
||||||
<img src={'/images/home/arrow_left.svg'} />
|
<img src={'/images/home/arrow_left.svg'} />
|
||||||
</button>
|
</button>
|
||||||
<button className={'p-1'}>
|
<button className={'p-1'} onClick={() => history.forward()}>
|
||||||
<img src={'/images/home/arrow_right.svg'} />
|
<img src={'/images/home/arrow_right.svg'} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className={'flex items-center'}>
|
<div className={'mr-8 flex items-center gap-4'}>
|
||||||
<span className={'mr-8'}>Getting Started</span>
|
<span>{folderName}</span>
|
||||||
<span className={'mr-8'}>/</span>
|
<span>/</span>
|
||||||
<span className={'mr-8'}>Read Me</span>
|
<span>{pageName}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -70,8 +70,6 @@ export const NavigationPanel = ({
|
|||||||
const elHeight = el.current.getBoundingClientRect().height;
|
const elHeight = el.current.getBoundingClientRect().height;
|
||||||
const scrollTop = el.current.scrollTop;
|
const scrollTop = el.current.scrollTop;
|
||||||
|
|
||||||
console.log(`scrollTop: ${scrollTop}, elHeight: ${elHeight.toFixed(0)}, height: ${height}`);
|
|
||||||
|
|
||||||
if (scrollTop + elHeight < height) {
|
if (scrollTop + elHeight < height) {
|
||||||
el.current.scrollTo({ top: height - elHeight, behavior: 'smooth' });
|
el.current.scrollTo({ top: height - elHeight, behavior: 'smooth' });
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user