mirror of
https://github.com/toeverything/AFFiNE.git
synced 2025-01-09 01:09:49 +03:00
commit
8cc88395d7
@ -21,7 +21,7 @@ export function LigoVirgoRoutes() {
|
||||
/>
|
||||
<Route path="/ui" element={<UIPage />} />
|
||||
<Route
|
||||
path="/:workspace_id/*"
|
||||
path="/:workspaceId/*"
|
||||
element={
|
||||
<RoutePrivate>
|
||||
<WorkspaceContainer />
|
||||
|
@ -14,7 +14,7 @@ type EdgelessProps = {
|
||||
};
|
||||
|
||||
export const Edgeless = (props: EdgelessProps) => {
|
||||
const { page_id } = useParams();
|
||||
const { pageId } = useParams();
|
||||
const { user } = useUserAndSpaces();
|
||||
|
||||
useEffect(() => {
|
||||
@ -31,7 +31,5 @@ export const Edgeless = (props: EdgelessProps) => {
|
||||
update_recent_pages();
|
||||
}, [user, props.workspace]);
|
||||
|
||||
return (
|
||||
<MemoAffineBoard workspace={props.workspace} rootBlockId={page_id} />
|
||||
);
|
||||
return <MemoAffineBoard workspace={props.workspace} rootBlockId={pageId} />;
|
||||
};
|
||||
|
@ -5,22 +5,23 @@ import { useNavigate, useParams } from 'react-router-dom';
|
||||
|
||||
export function WorkspaceHome() {
|
||||
const navigate = useNavigate();
|
||||
const { workspace_id } = useParams();
|
||||
const { workspaceId } = useParams();
|
||||
const { user } = useUserAndSpaces();
|
||||
|
||||
useEffect(() => {
|
||||
const navigate_to_user_initial_page = async () => {
|
||||
const [recent_pages, user_initial_page_id] = await Promise.all([
|
||||
services.api.userConfig.getRecentPages(workspace_id, user.id),
|
||||
const navigateToUserInitialPage = async () => {
|
||||
const [recentPages, userInitialPageId] = await Promise.all([
|
||||
services.api.userConfig.getRecentPages(workspaceId, user.id),
|
||||
services.api.userConfig.getUserInitialPage(
|
||||
workspace_id,
|
||||
workspaceId,
|
||||
user.id
|
||||
),
|
||||
]);
|
||||
if (recent_pages.length === 0) {
|
||||
// if recent pages if null, run initialize task
|
||||
if (recentPages.length === 0) {
|
||||
await services.api.editorBlock.copyTemplateToPage(
|
||||
workspace_id,
|
||||
user_initial_page_id,
|
||||
workspaceId,
|
||||
userInitialPageId,
|
||||
TemplateFactory.generatePageTemplateByGroupKeys({
|
||||
name: '👋 Get Started with AFFiNE',
|
||||
groupKeys: [
|
||||
@ -31,11 +32,12 @@ export function WorkspaceHome() {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
navigate(`/${workspace_id}/${user_initial_page_id}`);
|
||||
if (userInitialPageId) {
|
||||
navigate(`/${workspaceId}/${userInitialPageId}`);
|
||||
}
|
||||
};
|
||||
navigate_to_user_initial_page();
|
||||
}, [navigate, user.id, workspace_id]);
|
||||
navigateToUserInitialPage();
|
||||
}, [navigate, user.id, workspaceId]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -7,27 +7,20 @@ import { WorkspaceHome } from './Home';
|
||||
import Pages from './pages';
|
||||
|
||||
export function WorkspaceContainer() {
|
||||
const { workspace_id } = useParams();
|
||||
const { workspaceId } = useParams();
|
||||
const { user, currentSpaceId } = useUserAndSpaces();
|
||||
|
||||
if (
|
||||
user &&
|
||||
![currentSpaceId, 'affine2vin277tcmafwq'].includes(workspace_id)
|
||||
) {
|
||||
// return <Navigate to={`/${currentSpaceId}`} replace={true} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Routes>
|
||||
<Route path="/" element={<WorkspaceRootContainer />}>
|
||||
<Route path="/pages" element={<Pages />} />
|
||||
<Route
|
||||
path="/:page_id/edgeless"
|
||||
element={<Edgeless workspace={workspace_id} />}
|
||||
path="/:pageId/edgeless"
|
||||
element={<Edgeless workspace={workspaceId} />}
|
||||
/>
|
||||
<Route
|
||||
path="/:page_id"
|
||||
element={<Page workspace={workspace_id} />}
|
||||
path="/:pageId"
|
||||
element={<Page workspace={workspaceId} />}
|
||||
/>
|
||||
<Route path="/" element={<WorkspaceHome />} />
|
||||
</Route>
|
||||
|
@ -34,7 +34,7 @@ export function Page(props: PageProps) {
|
||||
const [activeTab, setActiveTab] = useState(
|
||||
TabMap.get(TAB_TITLE.PAGES).value
|
||||
);
|
||||
const { page_id } = useParams();
|
||||
const { pageId } = useParams();
|
||||
const { showSpaceSidebar, fixedDisplay, setSpaceSidebarVisible } =
|
||||
useShowSpaceSidebar();
|
||||
const dailyNotesFlag = useFlag('BooleanDailyNotes', false);
|
||||
@ -79,7 +79,7 @@ export function Page(props: PageProps) {
|
||||
</div>
|
||||
<div>
|
||||
<CollapsiblePageTree title="PAGES">
|
||||
{page_id ? <PageTree /> : null}
|
||||
{pageId ? <PageTree /> : null}
|
||||
</CollapsiblePageTree>
|
||||
</div>
|
||||
</div>
|
||||
@ -91,7 +91,7 @@ export function Page(props: PageProps) {
|
||||
</WorkspaceSidebarContent>
|
||||
</WorkspaceSidebar>
|
||||
</LigoLeftContainer>
|
||||
<EditorContainer workspace={props.workspace} pageId={page_id} />
|
||||
<EditorContainer workspace={props.workspace} pageId={pageId} />
|
||||
</LigoApp>
|
||||
);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ export type CollapsiblePageTreeProps = {
|
||||
export function CollapsiblePageTree(props: CollapsiblePageTreeProps) {
|
||||
const { className, style, children, title, initialOpen = true } = props;
|
||||
const navigate = useNavigate();
|
||||
const { workspace_id, page_id } = useParams();
|
||||
const { workspaceId, pageId } = useParams();
|
||||
|
||||
const { handleAddPage } = usePageTree();
|
||||
const { addPageToday } = useCalendarHeatmap();
|
||||
@ -46,18 +46,18 @@ export function CollapsiblePageTree(props: CollapsiblePageTreeProps) {
|
||||
const [open, setOpen] = useState(initialOpen);
|
||||
|
||||
const create_page = useCallback(async () => {
|
||||
if (page_id) {
|
||||
if (pageId) {
|
||||
const newPage = await services.api.editorBlock.create({
|
||||
workspace: workspace_id,
|
||||
workspace: workspaceId,
|
||||
type: 'page' as const,
|
||||
});
|
||||
|
||||
await handleAddPage(newPage.id);
|
||||
addPageToday();
|
||||
|
||||
navigate(`/${workspace_id}/${newPage.id}`);
|
||||
navigate(`/${workspaceId}/${newPage.id}`);
|
||||
}
|
||||
}, [addPageToday, handleAddPage, navigate, page_id, workspace_id]);
|
||||
}, [addPageToday, handleAddPage, navigate, pageId, workspaceId]);
|
||||
|
||||
const [newPageBtnVisible, setNewPageBtnVisible] = useState<boolean>(false);
|
||||
|
||||
|
@ -116,7 +116,7 @@ const renderTOCContent = tocDataSource => {
|
||||
};
|
||||
|
||||
export const TOC = () => {
|
||||
const { page_id } = useParams();
|
||||
const { pageId } = useParams();
|
||||
const [tocDataSource, setTocDataSource] = useState<TOCType[]>([]);
|
||||
const [activeBlockId, setActiveBlockId] = useState('');
|
||||
|
||||
@ -124,7 +124,7 @@ export const TOC = () => {
|
||||
const listenerMapRef = useRef<ListenerMap>(new Map());
|
||||
|
||||
const { currentEditors } = useCurrentEditors();
|
||||
const editor = currentEditors[page_id] as Virgo;
|
||||
const editor = currentEditors[pageId] as Virgo;
|
||||
|
||||
const updateTocDataSource = useCallback(async () => {
|
||||
if (!editor) {
|
||||
@ -134,7 +134,7 @@ export const TOC = () => {
|
||||
const listenerMap = listenerMapRef.current;
|
||||
|
||||
/* page listener: trigger update-notice when add new group */
|
||||
const pageAsyncBlock = (await editor.getBlockByIds([page_id]))?.[0];
|
||||
const pageAsyncBlock = (await editor.getBlockByIds([pageId]))?.[0];
|
||||
if (!listenerMap.has(pageAsyncBlock.id)) {
|
||||
listenerMap.set(
|
||||
pageAsyncBlock.id,
|
||||
@ -144,7 +144,7 @@ export const TOC = () => {
|
||||
|
||||
/* block listener: trigger update-notice when change block content */
|
||||
const { children = [] } =
|
||||
(await editor.queryByPageId(page_id))?.[0] || {};
|
||||
(await editor.queryByPageId(pageId))?.[0] || {};
|
||||
const asyncBlocks = (await editor.getBlockByIds(children)) || [];
|
||||
const { tocContents } = await getContentByAsyncBlocks(
|
||||
asyncBlocks,
|
||||
@ -155,7 +155,7 @@ export const TOC = () => {
|
||||
/* toc: flat content */
|
||||
const tocDataSource = getPageTOC(asyncBlocks, tocContents);
|
||||
setTocDataSource(tocDataSource);
|
||||
}, [editor, page_id]);
|
||||
}, [editor, pageId]);
|
||||
|
||||
/* init toc and add page/block update-listener & unmount-listener */
|
||||
useEffect(() => {
|
||||
|
@ -2,8 +2,8 @@ import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { Descendant } from 'slate';
|
||||
|
||||
// eslint-disable-next-line @nrwl/nx/enforce-module-boundaries
|
||||
import { BlockSearchItem } from '@toeverything/datasource/jwt';
|
||||
import { styled } from '@toeverything/components/ui';
|
||||
import { BlockSearchItem } from '@toeverything/datasource/jwt';
|
||||
|
||||
import { BlockPreview } from '../../block-preview';
|
||||
|
||||
@ -26,14 +26,14 @@ type InlineRefLinkProps = {
|
||||
};
|
||||
|
||||
export const InlineRefLink = ({ block, pageId }: InlineRefLinkProps) => {
|
||||
const { workspace_id } = useParams();
|
||||
const { workspaceId } = useParams();
|
||||
const navigate = useNavigate();
|
||||
|
||||
if (block) {
|
||||
return (
|
||||
<BlockPreviewContainer
|
||||
block={block}
|
||||
onClick={() => navigate(`/${workspace_id}/${pageId}`)}
|
||||
onClick={() => navigate(`/${workspaceId}/${pageId}`)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
@ -164,9 +164,6 @@ export const CodeView = ({ block, editor }: CreateCodeView) => {
|
||||
};
|
||||
useEffect(() => {
|
||||
handleLangChange(langType ? langType : DEFAULT_LANG);
|
||||
// setTimeout(() => {
|
||||
// focusCode();
|
||||
// }, 100);
|
||||
}, []);
|
||||
|
||||
const copyCode = () => {
|
||||
|
@ -16,7 +16,7 @@ import {
|
||||
} from '../../components/text-manage';
|
||||
|
||||
export const PageView = ({ block, editor }: CreateView) => {
|
||||
const { workspace_id } = useParams();
|
||||
const { workspaceId } = useParams();
|
||||
const textRef = useRef<ExtendedTextUtils>(null);
|
||||
const [backLinks, setBackLinks] =
|
||||
useState<Awaited<ReturnType<typeof editor.search>>>();
|
||||
@ -100,7 +100,7 @@ export const PageView = ({ block, editor }: CreateView) => {
|
||||
className={style9(styles.content)}
|
||||
suppressContentEditableWarning
|
||||
> */}
|
||||
<BackLink blocks={backLinks} workspaceId={workspace_id} />
|
||||
<BackLink blocks={backLinks} workspaceId={workspaceId} />
|
||||
{/*{block.childrenIds.map(childId => (*/}
|
||||
{/* <RenderBlock key={childId} blockId={childId} />*/}
|
||||
{/*))}*/}
|
||||
|
@ -6,16 +6,16 @@ import { CreateView } from '@toeverything/framework/virgo';
|
||||
type RefLinkView = CreateView;
|
||||
|
||||
export const RefLinkView = ({ block, editor }: RefLinkView) => {
|
||||
const page_id = useMemo(() => block.getProperty('reference'), [block]);
|
||||
const pageId = useMemo(() => block.getProperty('reference'), [block]);
|
||||
|
||||
const [block_content, set_block] =
|
||||
useState<Awaited<ReturnType<typeof editor.search>>[number]>();
|
||||
|
||||
useEffect(() => {
|
||||
editor
|
||||
.search({ tag: `id:${page_id}` })
|
||||
.search({ tag: `id:${pageId}` })
|
||||
.then(block => set_block(block[0]));
|
||||
}, [editor, page_id]);
|
||||
}, [editor, pageId]);
|
||||
|
||||
return <InlineRefLink block={block_content} pageId={page_id} />;
|
||||
return <InlineRefLink block={block_content} pageId={pageId} />;
|
||||
};
|
||||
|
@ -90,7 +90,9 @@ export const TextView = ({
|
||||
await block.removeChildren();
|
||||
await block.after(nextBlock);
|
||||
|
||||
editor.selectionManager.activeNodeByNodeId(nextBlock.id);
|
||||
setTimeout(() => {
|
||||
editor.selectionManager.activeNodeByNodeId(nextBlock.id, 'start');
|
||||
});
|
||||
return true;
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { services } from '@toeverything/datasource/db-service';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { WithEditorSelectionType } from '../menu/inline-menu/types';
|
||||
|
||||
export const useAddComment = ({
|
||||
@ -8,7 +8,7 @@ export const useAddComment = ({
|
||||
selectionInfo,
|
||||
setShow,
|
||||
}: WithEditorSelectionType) => {
|
||||
const { workspace_id: workspaceId, page_id: pageId } = useParams();
|
||||
const { workspaceId, pageId } = useParams();
|
||||
const [currentComment, setCurrentComment] = useState('');
|
||||
|
||||
const createComment = useCallback(async (): Promise<{
|
||||
|
@ -44,7 +44,7 @@ export const DoubleLinkMenu = ({
|
||||
hooks,
|
||||
style,
|
||||
}: DoubleLinkMenuProps) => {
|
||||
const { page_id: curPageId } = useParams();
|
||||
const { pageId: curPageId } = useParams();
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [anchorEl, setAnchorEl] = useState(null);
|
||||
const dialogRef = useRef<HTMLDivElement>();
|
||||
|
@ -42,7 +42,7 @@ const normalizeUrl = (url: string) => {
|
||||
};
|
||||
|
||||
export const LinkMenu = ({ editor, hooks }: LinkMenuProps) => {
|
||||
const { page_id: curPageId } = useParams();
|
||||
const { pageId: curPageId } = useParams();
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [anchorEl, setAnchorEl] = useState(null);
|
||||
const dialogRef = useRef<HTMLDivElement>();
|
||||
|
@ -47,7 +47,7 @@ type SearchProps = {
|
||||
};
|
||||
|
||||
export const Search = (props: SearchProps) => {
|
||||
const { workspace_id: workspaceId } = useParams();
|
||||
const { workspaceId } = useParams();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
|
@ -16,7 +16,7 @@ export const Switcher = () => {
|
||||
if (targetViewMode === pageViewMode) {
|
||||
return;
|
||||
}
|
||||
const workspaceId = params['workspace_id'];
|
||||
const workspaceId = params['workspaceId'];
|
||||
/**
|
||||
* There are two possible modes:
|
||||
* Page mode: /{workspaceId}/{pageId}
|
||||
|
@ -46,7 +46,7 @@ export const AffineHeader = () => {
|
||||
useUserAndSpaces();
|
||||
|
||||
const showCenterTab =
|
||||
(params['workspace_id'] || pathname.includes('/space/')) && params['*'];
|
||||
(params['workspaceId'] || pathname.includes('/space/')) && params['*'];
|
||||
|
||||
if (hideAffineHeader(pathname)) {
|
||||
return null;
|
||||
@ -82,7 +82,7 @@ export const AffineHeader = () => {
|
||||
isEdgelessView
|
||||
? navigate(
|
||||
`/${
|
||||
params['workspace_id'] ||
|
||||
params['workspaceId'] ||
|
||||
'space'
|
||||
}/${params['*'].slice(0, -11)}`
|
||||
)
|
||||
@ -108,7 +108,7 @@ export const AffineHeader = () => {
|
||||
? null
|
||||
: navigate(
|
||||
`/${
|
||||
params['workspace_id'] ||
|
||||
params['workspaceId'] ||
|
||||
'space'
|
||||
}/${params['*']}` + '/edgeless'
|
||||
)
|
||||
|
@ -50,7 +50,7 @@ const MESSAGES = {
|
||||
|
||||
function PageSettingPortal() {
|
||||
const [alertOpen, setAlertOpen] = useState(false);
|
||||
const { workspace_id } = useParams();
|
||||
const { workspaceId } = useParams();
|
||||
const [pageBlock, setPageBlock] = useState<PageBlock>();
|
||||
|
||||
const params = useParams();
|
||||
@ -64,7 +64,7 @@ function PageSettingPortal() {
|
||||
|
||||
const fetchPageBlock = useCallback(async () => {
|
||||
const dbPageBlock = await services.api.editorBlock.getBlock(
|
||||
workspace_id,
|
||||
workspaceId,
|
||||
pageId
|
||||
);
|
||||
if (!dbPageBlock) return;
|
||||
@ -78,11 +78,11 @@ function PageSettingPortal() {
|
||||
//@ts-ignore
|
||||
text.value[0].text,
|
||||
});
|
||||
}, [workspace_id, pageId]);
|
||||
}, [workspaceId, pageId]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchPageBlock();
|
||||
}, [workspace_id, pageId, fetchPageBlock]);
|
||||
}, [workspaceId, pageId, fetchPageBlock]);
|
||||
const redirectToPage = (newWorkspaceId: string, newPageId: string) => {
|
||||
navigate('/' + newWorkspaceId + '/' + newPageId);
|
||||
};
|
||||
@ -90,23 +90,23 @@ function PageSettingPortal() {
|
||||
const handleDuplicatePage = async () => {
|
||||
//create page
|
||||
const newPage = await services.api.editorBlock.create({
|
||||
workspace: workspace_id,
|
||||
workspace: workspaceId,
|
||||
type: 'page' as const,
|
||||
});
|
||||
//add page to tree
|
||||
await services.api.pageTree.addNextPageToWorkspace(
|
||||
workspace_id,
|
||||
workspaceId,
|
||||
pageId,
|
||||
newPage.id
|
||||
);
|
||||
//copy source page to new page
|
||||
await services.api.editorBlock.copyPage(
|
||||
workspace_id,
|
||||
workspaceId,
|
||||
pageId,
|
||||
newPage.id
|
||||
);
|
||||
|
||||
redirectToPage(workspace_id, newPage.id);
|
||||
redirectToPage(workspaceId, newPage.id);
|
||||
};
|
||||
|
||||
const handleCopy = () => {
|
||||
@ -128,7 +128,7 @@ function PageSettingPortal() {
|
||||
.inspector()
|
||||
.load()
|
||||
.then(() => {
|
||||
window.location.href = `/${workspace_id}/`;
|
||||
window.location.href = `/${workspaceId}/`;
|
||||
});
|
||||
};
|
||||
|
||||
@ -145,7 +145,7 @@ function PageSettingPortal() {
|
||||
fullWidthChecked: checked,
|
||||
},
|
||||
id: pageId,
|
||||
workspace: workspace_id,
|
||||
workspace: workspaceId,
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -12,7 +12,7 @@ import { useUserAndSpaces } from '@toeverything/datasource/state';
|
||||
export const CurrentPageTitle = () => {
|
||||
const { user } = useUserAndSpaces();
|
||||
const params = useParams();
|
||||
const { workspace_id } = params;
|
||||
const { workspaceId } = params;
|
||||
const [pageId, setPageId] = useState<string>('');
|
||||
const [pageTitle, setPageTitle] = useState<string | undefined>();
|
||||
/* card.7 */
|
||||
@ -25,9 +25,9 @@ export const CurrentPageTitle = () => {
|
||||
}, [params]);
|
||||
|
||||
const fetchPageTitle = useCallback(async () => {
|
||||
if (!workspace_id || !pageId) return;
|
||||
if (!workspaceId || !pageId) return;
|
||||
const [pageEditorBlock] = await services.api.editorBlock.get({
|
||||
workspace: workspace_id,
|
||||
workspace: workspaceId,
|
||||
ids: [pageId],
|
||||
});
|
||||
/* card.7 */
|
||||
@ -39,21 +39,21 @@ export const CurrentPageTitle = () => {
|
||||
?.map(v => v.text)
|
||||
.join('') ?? 'Untitled'
|
||||
);
|
||||
}, [pageId, workspace_id]);
|
||||
}, [pageId, workspaceId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (user) fetchPageTitle();
|
||||
}, [fetchPageTitle, user]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!user || !workspace_id || !pageId || pageTitle === undefined)
|
||||
if (!user || !workspaceId || !pageId || pageTitle === undefined)
|
||||
return () => {};
|
||||
|
||||
let unobserve: () => void;
|
||||
const auto_update_title = async () => {
|
||||
// console.log(';; title registration auto update');
|
||||
unobserve = await services.api.editorBlock.observe(
|
||||
{ workspace: workspace_id, id: pageId },
|
||||
{ workspace: workspaceId, id: pageId },
|
||||
businessBlock => {
|
||||
// console.log(';; auto_update_title', businessBlock);
|
||||
fetchPageTitle();
|
||||
@ -65,7 +65,7 @@ export const CurrentPageTitle = () => {
|
||||
return () => {
|
||||
// unobserve?.();
|
||||
};
|
||||
}, [fetchPageTitle, pageId, pageTitle, user, workspace_id]);
|
||||
}, [fetchPageTitle, pageId, pageTitle, user, workspaceId]);
|
||||
|
||||
useEffect(() => {
|
||||
document.title = pageTitle || '';
|
||||
|
@ -9,7 +9,7 @@ import { useParams } from 'react-router-dom';
|
||||
import type { CommentInfo } from './type';
|
||||
|
||||
export const useComments = () => {
|
||||
const { workspace_id: workspaceId, page_id: pageId } = useParams();
|
||||
const { workspaceId, pageId } = useParams();
|
||||
|
||||
const [comments, setComments] = useState<CommentInfo[]>([]);
|
||||
const [observeIds, setObserveIds] = useState<string[]>([]);
|
||||
@ -71,7 +71,7 @@ export const useComments = () => {
|
||||
};
|
||||
|
||||
export const useActiveComment = () => {
|
||||
const { workspace_id: workspaceId, page_id: pageId } = useParams();
|
||||
const { workspaceId, pageId } = useParams();
|
||||
const { currentEditors } = useCurrentEditors();
|
||||
const editor = useMemo(() => {
|
||||
return currentEditors[pageId] as Virgo;
|
||||
|
@ -7,7 +7,7 @@ interface UseWorkspaceAndPageIdReturn {
|
||||
|
||||
export const useWorkspaceAndPageId = (): UseWorkspaceAndPageIdReturn => {
|
||||
const params = useParams();
|
||||
const workspaceId = params['workspace_id'];
|
||||
const workspaceId = params['workspaceId'];
|
||||
const pageId = params['*'].split('/')[0];
|
||||
return {
|
||||
workspaceId,
|
||||
|
@ -47,8 +47,8 @@ export async function fetchActivitiesHeatmap(
|
||||
// const pages = await db.getByType('page');
|
||||
const pages_with_ids = (await Promise.all(
|
||||
flattenedItems.map(async (page_item: any) => {
|
||||
const page_id = page_item.id;
|
||||
return [page_id, await db.get(page_id as 'page')];
|
||||
const pageId = page_item.id;
|
||||
return [pageId, await db.get(pageId as 'page')];
|
||||
})
|
||||
)) as [string, BlockImplInstance][];
|
||||
const pages = new Map(pages_with_ids);
|
||||
|
@ -57,7 +57,9 @@ export const TreeItem = forwardRef<HTMLDivElement, TreeItemProps>(
|
||||
},
|
||||
ref
|
||||
) => {
|
||||
const { workspace_id, page_id } = useParams();
|
||||
const params = useParams();
|
||||
const workspaceId = params['workspaceId'];
|
||||
const curPageId = params['pageId'];
|
||||
const BooleanPageTreeItemMoreActions = useFlag(
|
||||
'BooleanPageTreeItemMoreActions',
|
||||
true
|
||||
@ -71,7 +73,7 @@ export const TreeItem = forwardRef<HTMLDivElement, TreeItemProps>(
|
||||
disableSelection={disableSelection}
|
||||
disableInteraction={disableInteraction}
|
||||
spacing={`${indentationWidth * depth + 12}px`}
|
||||
active={pageId === page_id}
|
||||
active={pageId === curPageId}
|
||||
{...props}
|
||||
>
|
||||
{childCount !== 0 ? (
|
||||
@ -89,12 +91,12 @@ export const TreeItem = forwardRef<HTMLDivElement, TreeItemProps>(
|
||||
)}
|
||||
|
||||
<TreeItemContent {...handleProps}>
|
||||
<TextLink to={`/${workspace_id}/${pageId}`}>
|
||||
<TextLink to={`/${workspaceId}/${pageId}`}>
|
||||
{value}
|
||||
</TextLink>
|
||||
{BooleanPageTreeItemMoreActions && (
|
||||
<MoreActions
|
||||
workspaceId={workspace_id}
|
||||
workspaceId={workspaceId}
|
||||
pageId={pageId}
|
||||
onRemove={onRemove}
|
||||
/>
|
||||
|
@ -19,7 +19,7 @@ import {
|
||||
const page_tree_atom = atom<TreeItems | undefined>([]);
|
||||
|
||||
export const usePageTree = ({ indentationWidth = 16 }: DndTreeProps = {}) => {
|
||||
const { workspace_id, page_id } = useParams();
|
||||
const { workspaceId, pageId } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const [items] = useAtom(page_tree_atom);
|
||||
const [activeId, setActiveId] = useState<string | undefined>(undefined);
|
||||
@ -56,11 +56,11 @@ export const usePageTree = ({ indentationWidth = 16 }: DndTreeProps = {}) => {
|
||||
const savePageTreeData = useCallback(
|
||||
async (treeData?: TreeItem[]) => {
|
||||
await services.api.pageTree.setPageTree<TreeItem>(
|
||||
workspace_id,
|
||||
workspaceId,
|
||||
treeData || []
|
||||
);
|
||||
},
|
||||
[workspace_id]
|
||||
[workspaceId]
|
||||
);
|
||||
|
||||
const resetState = useCallback(() => {
|
||||
@ -129,19 +129,19 @@ export const usePageTree = ({ indentationWidth = 16 }: DndTreeProps = {}) => {
|
||||
const handleRemove = useCallback(
|
||||
async (id: string) => {
|
||||
await savePageTreeData(removeItem(items, id));
|
||||
await services.api.userConfig.removePage(workspace_id, id);
|
||||
await services.api.userConfig.removePage(workspaceId, id);
|
||||
//remove page from jwst
|
||||
await services.api.pageTree.removePage(workspace_id, id);
|
||||
if (id === page_id) {
|
||||
navigate(`/${workspace_id}`);
|
||||
await services.api.pageTree.removePage(workspaceId, id);
|
||||
if (id === pageId) {
|
||||
navigate(`/${workspaceId}`);
|
||||
}
|
||||
},
|
||||
[items, savePageTreeData, workspace_id]
|
||||
[items, savePageTreeData, workspaceId]
|
||||
);
|
||||
|
||||
const handleAddPage = useCallback(
|
||||
async (page_id?: string) => {
|
||||
await savePageTreeData([{ id: page_id, children: [] }, ...items]);
|
||||
async (pageId?: string) => {
|
||||
await savePageTreeData([{ id: pageId, children: [] }, ...items]);
|
||||
},
|
||||
[items, savePageTreeData]
|
||||
);
|
||||
@ -177,25 +177,25 @@ export const usePageTree = ({ indentationWidth = 16 }: DndTreeProps = {}) => {
|
||||
|
||||
export const useDndTreeAutoUpdate = () => {
|
||||
const [, set_items] = useAtom(page_tree_atom);
|
||||
const { workspace_id, page_id } = useParams();
|
||||
const { workspaceId, pageId } = useParams();
|
||||
|
||||
const fetch_page_tree_data = useCallback(async () => {
|
||||
const pages = await services.api.pageTree.getPageTree<TreeItem>(
|
||||
workspace_id
|
||||
workspaceId
|
||||
);
|
||||
set_items(pages);
|
||||
}, [set_items, workspace_id]);
|
||||
}, [set_items, workspaceId]);
|
||||
|
||||
useEffect(() => {
|
||||
fetch_page_tree_data();
|
||||
}, [fetch_page_tree_data]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!page_id) return () => {};
|
||||
if (!pageId) return () => {};
|
||||
let unobserve: () => void;
|
||||
const auto_update_page_tree = async () => {
|
||||
unobserve = await services.api.pageTree.observe(
|
||||
{ workspace: workspace_id, page: page_id },
|
||||
{ workspace: workspaceId, page: pageId },
|
||||
() => {
|
||||
fetch_page_tree_data();
|
||||
}
|
||||
@ -206,5 +206,5 @@ export const useDndTreeAutoUpdate = () => {
|
||||
return () => {
|
||||
unobserve?.();
|
||||
};
|
||||
}, [fetch_page_tree_data, page_id, workspace_id]);
|
||||
}, [fetch_page_tree_data, pageId, workspaceId]);
|
||||
};
|
||||
|
@ -265,37 +265,34 @@ export class EditorBlock extends ServiceBaseClass {
|
||||
}
|
||||
}
|
||||
async copyPage(
|
||||
workspace_id: string,
|
||||
source_page_id: string,
|
||||
new_page_id: string
|
||||
workspaceId: string,
|
||||
sourcePageId: string,
|
||||
newPageId: string
|
||||
): Promise<boolean> {
|
||||
const db = await this.database.getDatabase(workspace_id);
|
||||
const db = await this.database.getDatabase(workspaceId);
|
||||
|
||||
const source_page = await this.getBlock(
|
||||
workspace_id,
|
||||
source_page_id as 'block'
|
||||
const sourcePage = await this.getBlock(
|
||||
workspaceId,
|
||||
sourcePageId as 'block'
|
||||
);
|
||||
const new_page = await this.getBlock(
|
||||
workspace_id,
|
||||
new_page_id as 'block'
|
||||
);
|
||||
if (!source_page) {
|
||||
const newPage = await this.getBlock(workspaceId, newPageId as 'block');
|
||||
if (!sourcePage) {
|
||||
return false;
|
||||
}
|
||||
const source_page_children = source_page.children;
|
||||
const decorations = source_page.getDecorations();
|
||||
const sourcePageChildren = sourcePage.children;
|
||||
const decorations = sourcePage.getDecorations();
|
||||
Object.entries(decorations).forEach(([key, value]) => {
|
||||
new_page?.setDecoration(key, source_page.getDecoration(key));
|
||||
newPage?.setDecoration(key, sourcePage.getDecoration(key));
|
||||
});
|
||||
|
||||
//@ts-ignore
|
||||
this.decorate_page_title(new_page, 'copy from ');
|
||||
this.decorate_page_title(newPage, 'copy from ');
|
||||
|
||||
for (let i = 0; i < source_page_children.length; i++) {
|
||||
const source_page_child = await db.get(
|
||||
source_page_children[i] as 'block'
|
||||
for (let i = 0; i < sourcePageChildren.length; i++) {
|
||||
const sourcePageChild = await db.get(
|
||||
sourcePageChildren[i] as 'block'
|
||||
);
|
||||
new_page?.insertChildren(source_page_child);
|
||||
newPage?.insertChildren(sourcePageChild);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ export class YjsAdapter implements AsyncDatabaseAdapter<YjsContentOperation> {
|
||||
const [file] = (await fromEvent(handles)) as File[];
|
||||
const binary = await file?.arrayBuffer();
|
||||
console.log(this._provider.providers);
|
||||
let { indexeddb } = (
|
||||
const { indexeddb } = (
|
||||
this._provider.providers as any[]
|
||||
).find(p => p.indexeddb);
|
||||
await indexeddb?.idb?.clearData();
|
||||
@ -391,9 +391,9 @@ export class YjsAdapter implements AsyncDatabaseAdapter<YjsContentOperation> {
|
||||
},
|
||||
parse: () => this._doc.toJSON(),
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
parse_page: (page_id: string) => {
|
||||
parse_page: (pageId: string) => {
|
||||
const blocks = this._blocks.toJSON();
|
||||
return resolve_block(blocks, page_id);
|
||||
return resolve_block(blocks, pageId);
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
parse_pages: (resolve = false) => {
|
||||
|
@ -9,7 +9,7 @@ const _currentEditors = atom<EditorsMap>({} as EditorsMap);
|
||||
|
||||
/** hook for using editors outside page */
|
||||
export const useCurrentEditors = () => {
|
||||
const { workspace_id: workspaceId, page_id: pageId } = useParams();
|
||||
const { workspaceId, pageId } = useParams();
|
||||
const { pathname } = useLocation();
|
||||
const [currentEditors, setCurrentEditors] = useAtom(_currentEditors);
|
||||
|
||||
|
@ -5,7 +5,6 @@ import {
|
||||
} from 'firebase/auth';
|
||||
import { atom, useAtom } from 'jotai';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { useLocation, useNavigate } from 'react-router';
|
||||
|
||||
import { useIdentifyUser } from '@toeverything/datasource/feature-flags';
|
||||
import { UserInfo } from '@toeverything/utils';
|
||||
@ -63,15 +62,11 @@ const BRAND_ID = 'AFFiNE';
|
||||
|
||||
const _localTrigger = atom<boolean>(false);
|
||||
const _useUserAndSpacesForFreeLogin = () => {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const [user, setUser] = useAtom(_userAtom);
|
||||
const [loading, setLoading] = useAtom(_loadingAtom);
|
||||
const [localTrigger] = useAtom(_localTrigger);
|
||||
|
||||
useEffect(() => {
|
||||
if (loading) {
|
||||
navigate(`/${BRAND_ID}`);
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
@ -6,8 +6,8 @@ export function getUserDisplayName(user?: UserInfo) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page_id from URL
|
||||
* @returns page_id
|
||||
* Get pageId from URL
|
||||
* @returns pageId
|
||||
*/
|
||||
export function getPageId() {
|
||||
const path = window.location.pathname.match(/\/(\w+)\/(\w+)/);
|
||||
|
Loading…
Reference in New Issue
Block a user