mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-20 11:36:25 +08:00
init: the first public commit for AFFiNE
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { useLocation, useParams, useNavigate } from 'react-router-dom';
|
||||
import { styled } from '@toeverything/components/ui';
|
||||
import { StatusText } from './StatusText';
|
||||
import { StatusTrack } from './StatusTrack';
|
||||
import { DocMode } from './type';
|
||||
|
||||
const isBoard = (pathname: string): boolean => pathname.endsWith('/whiteboard');
|
||||
|
||||
export const Switcher = () => {
|
||||
const navigate = useNavigate();
|
||||
const params = useParams();
|
||||
const { pathname } = useLocation();
|
||||
const pageViewMode = isBoard(pathname) ? DocMode.board : DocMode.doc;
|
||||
|
||||
const switchToPageView = (targetViewMode: DocMode) => {
|
||||
if (targetViewMode === pageViewMode) {
|
||||
return;
|
||||
}
|
||||
const workspaceId = params['workspace_id'];
|
||||
/**
|
||||
* There are two possible modes:
|
||||
* Page mode: /{workspaceId}/{pageId}
|
||||
* Board mode: /{workspaceId}/{pageId}/whiteboard
|
||||
*/
|
||||
const pageId = params['*'].split('/')[0];
|
||||
const targetUrl = `/${workspaceId}/${pageId}${
|
||||
targetViewMode === DocMode.board ? '/whiteboard' : ''
|
||||
}`;
|
||||
navigate(targetUrl);
|
||||
};
|
||||
|
||||
return (
|
||||
<StyledContainerForSwitcher>
|
||||
<StatusText
|
||||
active={pageViewMode === DocMode.doc}
|
||||
onClick={() => switchToPageView(DocMode.doc)}
|
||||
>
|
||||
Doc
|
||||
</StatusText>
|
||||
<StatusTrack
|
||||
mode={pageViewMode}
|
||||
onClick={() => {
|
||||
switchToPageView(
|
||||
pageViewMode === DocMode.board
|
||||
? DocMode.doc
|
||||
: DocMode.board
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<StatusText
|
||||
active={pageViewMode === DocMode.board}
|
||||
onClick={() => switchToPageView(DocMode.board)}
|
||||
>
|
||||
Board
|
||||
</StatusText>
|
||||
</StyledContainerForSwitcher>
|
||||
);
|
||||
};
|
||||
|
||||
const StyledContainerForSwitcher = styled('div')({
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
});
|
||||
Reference in New Issue
Block a user