refactor(page): rename pageId

This commit is contained in:
tzhangchi
2022-09-08 19:20:37 +08:00
parent 9442c023e5
commit 281c3f6c44
17 changed files with 58 additions and 61 deletions
@@ -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} />;
};
@@ -8,7 +8,7 @@ export const useAddComment = ({
selectionInfo,
setShow,
}: WithEditorSelectionType) => {
const { 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>();
@@ -9,7 +9,7 @@ import { useParams } from 'react-router-dom';
import type { CommentInfo } from './type';
export const useComments = () => {
const { 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 { workspaceId, page_id: pageId } = useParams();
const { workspaceId, pageId } = useParams();
const { currentEditors } = useCurrentEditors();
const editor = useMemo(() => {
return currentEditors[pageId] as Virgo;
@@ -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 { workspaceId, 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 ? (
@@ -19,7 +19,7 @@ import {
const page_tree_atom = atom<TreeItems | undefined>([]);
export const usePageTree = ({ indentationWidth = 16 }: DndTreeProps = {}) => {
const { workspaceId, page_id } = useParams();
const { workspaceId, pageId } = useParams();
const navigate = useNavigate();
const [items] = useAtom(page_tree_atom);
const [activeId, setActiveId] = useState<string | undefined>(undefined);
@@ -132,7 +132,7 @@ export const usePageTree = ({ indentationWidth = 16 }: DndTreeProps = {}) => {
await services.api.userConfig.removePage(workspaceId, id);
//remove page from jwst
await services.api.pageTree.removePage(workspaceId, id);
if (id === page_id) {
if (id === pageId) {
navigate(`/${workspaceId}`);
}
},
@@ -140,8 +140,8 @@ export const usePageTree = ({ indentationWidth = 16 }: DndTreeProps = {}) => {
);
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,7 +177,7 @@ export const usePageTree = ({ indentationWidth = 16 }: DndTreeProps = {}) => {
export const useDndTreeAutoUpdate = () => {
const [, set_items] = useAtom(page_tree_atom);
const { workspaceId, page_id } = useParams();
const { workspaceId, pageId } = useParams();
const fetch_page_tree_data = useCallback(async () => {
const pages = await services.api.pageTree.getPageTree<TreeItem>(
@@ -191,11 +191,11 @@ export const useDndTreeAutoUpdate = () => {
}, [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: workspaceId, 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, workspaceId]);
}, [fetch_page_tree_data, pageId, workspaceId]);
};