fix: page list all, favorite, trash

This commit is contained in:
alt0
2022-12-20 02:01:53 +08:00
parent 49f4c49426
commit f3644385a8
11 changed files with 135 additions and 36 deletions
@@ -19,13 +19,16 @@ import React from 'react';
import DateCell from '@/components/page-list/date-cell';
import { IconButton } from '@/ui/button';
import { Tooltip } from '@/ui/tooltip';
import { router } from 'next/client';
import { useRouter } from 'next/router';
import { useAppState } from '@/providers/app-state-provider/context';
import { toast } from '@/components/toast';
const FavoriteTag = ({
pageMeta: { favorite, id },
}: {
pageMeta: PageMeta;
}) => {
const { toggleFavoritePage } = useEditor();
const { toggleFavoritePage } = useAppState();
return (
<Tooltip
content={favorite ? 'Favourited' : 'Favourite'}
@@ -37,6 +40,7 @@ const FavoriteTag = ({
onClick={e => {
e.stopPropagation();
toggleFavoritePage(id);
toast(!favorite ? 'Removed to Favourites' : 'Added to Favourites');
}}
>
{favorite ? <FavouritedIcon /> : <FavouritesIcon />}
@@ -54,6 +58,8 @@ export const PageList = ({
showFavoriteTag?: boolean;
isTrash?: boolean;
}) => {
const router = useRouter();
const { currentWorkspaceId } = useAppState();
if (pageList.length === 0) {
return <Empty />;
}
@@ -77,10 +83,9 @@ export const PageList = ({
<StyledTableRow
key={`${pageMeta.id}-${index}`}
onClick={() => {
router.push({
pathname: '/',
query: { pageId: pageMeta.id },
});
router.push(
`/workspace/${currentWorkspaceId}/${pageMeta.id}`
);
}}
>
<TableCell>
@@ -20,7 +20,7 @@ import { toast } from '@/components/toast';
export const OperationCell = ({ pageMeta }: { pageMeta: PageMeta }) => {
const { id, favorite } = pageMeta;
const goToPage = useGoToPage();
const { toggleFavoritePage, toggleDeletePage } = useEditor();
const { toggleFavoritePage, toggleDeletePage } = useAppState();
const { confirm } = useConfirm();
const OperationMenu = (
@@ -28,6 +28,7 @@ export const OperationCell = ({ pageMeta }: { pageMeta: PageMeta }) => {
<MenuItem
onClick={() => {
toggleFavoritePage(id);
toast(!favorite ? 'Removed to Favourites' : 'Added to Favourites');
}}
icon={favorite ? <FavouritedIcon /> : <FavouritesIcon />}
>
@@ -73,8 +74,8 @@ export const OperationCell = ({ pageMeta }: { pageMeta: PageMeta }) => {
export const TrashOperationCell = ({ pageMeta }: { pageMeta: PageMeta }) => {
const { id } = pageMeta;
const goToPage = useGoToPage();
const { getPageMeta } = useAppState();
const { permanentlyDeletePage, toggleDeletePage } = useEditor();
const { getPageMeta, toggleDeletePage } = useAppState();
const { permanentlyDeletePage } = useEditor();
const { confirm } = useConfirm();
return (