Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: add some placeholder for deleted and not found (#6470)
Kilu.Hecaa882dc37d3
diff --git a/frontend/appflowy_web_app/src/components/app/MainLayout.tsx b/frontend/appflowy_web_app/src/components/app/MainLayout.tsxindex 9ef62f1dca..2ac32f89d7 100644--- a/frontend/appflowy_web_app/src/components/app/MainLayout.tsx+++ b/frontend/appflowy_web_app/src/components/app/MainLayout.tsx@@ -1,8 +1,11 @@import { useOutlineDrawer } from '@/components/_shared/outline/outline.hooks';import { AFScroller } from '@/components/_shared/scroller';+import { useViewErrorStatus } from '@/components/app/app.hooks';import { AppHeader } from '@/components/app/header';import Main from '@/components/app/Main';import SideBar from '@/components/app/SideBar';+import DeletedPageComponent from '@/components/error/PageHasBeenDeleted';+import RecordNotFound from '@/components/error/RecordNotFound';import SomethingError from '@/components/error/SomethingError';import React, { useMemo } from 'react';import { ErrorBoundary } from 'react-error-boundary';@@ -15,9 +18,15 @@ function MainLayout () {toggleOpenDrawer,} = useOutlineDrawer();+ const { notFound, deleted } = useViewErrorStatus();+const main = useMemo(() => {- return <Main />;- }, []);+ if (deleted) {+ return <DeletedPageComponent />;+ }++ return notFound ? <RecordNotFound isViewNotFound /> : <Main />;+ }, [deleted, notFound]);return (<div className={'h-screen w-screen'}>diff --git a/frontend/appflowy_web_app/src/components/app/SideBar.tsx b/frontend/appflowy_web_app/src/components/app/SideBar.tsxindex 4723639047..14e9572752 100644--- a/frontend/appflowy_web_app/src/components/app/SideBar.tsx+++ b/frontend/appflowy_web_app/src/components/app/SideBar.tsx@@ -2,7 +2,7 @@ import { UIVariant } from '@/application/types';import { OutlineDrawer } from '@/components/_shared/outline';import Outline from '@/components/_shared/outline/Outline';import { AppContext, useAppOutline, useAppViewId } from '@/components/app/app.hooks';-import React, { Suspense, useContext, lazy } from 'react';+import React, { useContext, lazy } from 'react';import { Favorite } from '@/components/app/favorite';import { Workspaces } from '@/components/app/workspaces';@@ -25,7 +25,6 @@ function SideBar ({const viewId = useAppViewId();const navigateToView = useContext(AppContext)?.toView;- const rendered = useContext(AppContext)?.rendered;return (<OutlineDrawer@@ -44,7 +43,7 @@ function SideBar ({width={drawerWidth}outline={outline}/>- {(rendered || !viewId) && <Suspense><SideBarBottom /></Suspense>}+ <SideBarBottom /></div></OutlineDrawer>diff --git a/frontend/appflowy_web_app/src/components/app/app.hooks.tsx b/frontend/appflowy_web_app/src/components/app/app.hooks.tsxindex 55e7487612..d064b192ed 100644--- a/frontend/appflowy_web_app/src/components/app/app.hooks.tsx+++ b/frontend/appflowy_web_app/src/components/app/app.hooks.tsx@@ -13,7 +13,7 @@ import { findAncestors, findView, findViewByLayout } from '@/components/_shared/import RequestAccess from '@/components/app/landing-pages/RequestAccess';import { AFConfigContext, useService } from '@/components/main/app.hooks';import { uniqBy } from 'lodash-es';-import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';+import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';import { useNavigate, useParams } from 'react-router-dom';import { validate as uuidValidate } from 'uuid';@@ -31,10 +31,14 @@ export interface AppContextType {appendBreadcrumb?: AppendBreadcrumb;loadFavoriteViews?: () => Promise<void>;loadRecentViews?: () => Promise<void>;+ loadTrash?: (workspaceId: string) => Promise<void>;favoriteViews?: View[];recentViews?: View[];+ trashList?: View[];rendered?: boolean;onRendered?: () => void;+ notFound?: boolean;+ viewHasBeenDeleted?: boolean;}const USER_NO_ACCESS_CODE = [1024, 1012];@@ -56,6 +60,16 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {const [outline, setOutline] = useState<View[]>();const [favoriteViews, setFavoriteViews] = useState<View[]>();const [recentViews, setRecentViews] = useState<View[]>();+ const [trashList, setTrashList] = React.useState<View[]>();+ const viewHasBeenDeleted = useMemo(() => {+ if (!viewId) return false;+ return trashList?.some((v) => v.view_id === viewId);+ }, [trashList, viewId]);+ const viewNotFound = useMemo(() => {+ if (!viewId) return false;+ return !findView(outline || [], viewId);+ }, [outline, viewId]);+const createdRowKeys = useRef<string[]>([]);const [requestAccessOpened, setRequestAccessOpened] = useState(false);const [rendered, setRendered] = useState(false);@@ -244,7 +258,9 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {}// skip /app/:workspaceId/:pageId- if (pageId && uuidValidate(pageId) && wId && uuidValidate(wId) && wId === workspaceId) return;+ if (pageId && uuidValidate(pageId) && wId && uuidValidate(wId) && wId === workspaceId) {+ return;+ }const lastViewId = localStorage.getItem('last_view_id');@@ -304,11 +320,33 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {}}, [currentWorkspaceId, service]);+ const loadTrash = useCallback(async (currentWorkspaceId: string) => {++ if (!service) return;+ try {+ const res = await service?.getAppTrash(currentWorkspaceId);++ if (!res) {+ throw new Error('App trash not found');+ }++ setTrashList(res);+ } catch (e) {+ return Promise.reject('App trash not found');+ }+ }, [service]);+useEffect(() => {if (!currentWorkspaceId) return;void loadOutline(currentWorkspaceId);-- }, [loadOutline, currentWorkspaceId]);+ void (async () => {+ try {+ await loadTrash(currentWorkspaceId);+ } catch (e) {+ console.error(e);+ }+ })();+ }, [loadOutline, currentWorkspaceId, loadTrash]);useEffect(() => {void loadUserWorkspaceInfo().then(res => {@@ -340,20 +378,37 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {loadView,loadFavoriteViews,loadRecentViews,+ loadTrash,favoriteViews,recentViews,+ trashList,appendBreadcrumb,breadcrumbs,userWorkspaceInfo,onChangeWorkspace,rendered,onRendered,+ notFound: viewNotFound,+ viewHasBeenDeleted,}}>{requestAccessOpened ? <RequestAccess /> : children}</AppContext.Provider>;};+export function useViewErrorStatus () {+ const context = useContext(AppContext);++ if (!context) {+ throw new Error('useBreadcrumb must be used within an AppProvider');+ }++ return {+ notFound: context.notFound,+ deleted: context.viewHasBeenDeleted,+ };+}+export function useBreadcrumb () {const context = useContext(AppContext);@@ -458,4 +513,17 @@ export function useAppRecent () {loadRecentViews: context.loadRecentViews,recentViews: context.recentViews,};+}++export function useAppTrash () {+ const context = useContext(AppContext);++ if (!context) {+ throw new Error('useAppTrash must be used within an AppProvider');+ }++ return {+ loadTrash: context.loadTrash,+ trashList: context.trashList,+ };}\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/components/editor/Editable.tsx b/frontend/appflowy_web_app/src/components/editor/Editable.tsxindex a3d2c35ee9..fe9ffed384 100644--- a/frontend/appflowy_web_app/src/components/editor/Editable.tsx+++ b/frontend/appflowy_web_app/src/components/editor/Editable.tsx@@ -1,5 +1,3 @@-import { YjsEditor } from '@/application/slate-yjs';-import { CustomEditor } from '@/application/slate-yjs/command';import { useDecorate } from '@/components/editor/components/blocks/code/useDecorate';import { Leaf } from '@/components/editor/components/leaf';import { useEditorContext } from '@/components/editor/EditorContext';@@ -26,7 +24,7 @@ const EditorEditable = () => {if (!selection) return;if (Range.isExpanded(selection)) {- CustomEditor.deleteBlockBackward(editor as YjsEditor, selection);+ editor.delete();}}, [editor]);diff --git a/frontend/appflowy_web_app/src/components/error/PageHasBeenDeleted.tsx b/frontend/appflowy_web_app/src/components/error/PageHasBeenDeleted.tsxnew file mode 100644index 0000000000..2fb7467a66--- /dev/null+++ b/frontend/appflowy_web_app/src/components/error/PageHasBeenDeleted.tsx@@ -0,0 +1,29 @@+import React from 'react';+import { ReactComponent as TrashIcon } from '@/assets/trash.svg';+import emptyImageSrc from '@/assets/images/empty.png';++const DeletedPageComponent = () => {++ return (+ <div className={'flex h-full w-full flex-col items-center justify-center'}>+ <div className={'text-2xl font-bold text-function-error flex items-center gap-4'}>+ <TrashIcon className={'w-12 h-12 opacity-70'} />+ Page Deleted+ </div>+ <div className={'text-base text-center text-text-title opacity-80 mt-4 whitespace-pre'}>+ You can restore it from the trash or create a new page+ </div>+ <div className={'mt-6 flex gap-4'}>+ {/*<button className={'px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition'}>*/}+ {/* Restore Page*/}+ {/*</button>*/}+ {/*<button className={'px-4 py-2 bg-gray-200 text-gray-700 rounded hover:bg-gray-300 transition'}>*/}+ {/* Create New Page*/}+ {/*</button>*/}+ </div>+ <img src={emptyImageSrc} alt={'Empty state'} className={'mt-8'} />+ </div>+ );+};++export default DeletedPageComponent;\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/components/error/RecordNotFound.tsx b/frontend/appflowy_web_app/src/components/error/RecordNotFound.tsxindex 7aa5309cf1..c8b9feeef8 100644--- a/frontend/appflowy_web_app/src/components/error/RecordNotFound.tsx+++ b/frontend/appflowy_web_app/src/components/error/RecordNotFound.tsx@@ -4,15 +4,18 @@ import { ReactComponent as WarningIcon } from '@/assets/warning.svg';function RecordNotFound ({noContent,+ isViewNotFound,}: {noContent?: boolean;+ isViewNotFound?: boolean;}) {return (<div className={'flex h-full w-full flex-col items-center justify-center'}>{!noContent && <><div className={'text-2xl font-bold text-text-title opacity-70 flex items-center gap-4'}><WarningIcon className={'w-12 h-12'} />- RecordNotFound+ {isViewNotFound ? 'Page Not Found' :+ 'Record Not Found'}</div><div className={'text-lg text-center text-text-title opacity-50 mt-4 whitespace-pre'}>{`We're sorry for inconvenience\n`}diff --git a/frontend/appflowy_web_app/src/pages/TrashPage.tsx b/frontend/appflowy_web_app/src/pages/TrashPage.tsxindex 9e44228d46..3ad3a31c8e 100644--- a/frontend/appflowy_web_app/src/pages/TrashPage.tsx+++ b/frontend/appflowy_web_app/src/pages/TrashPage.tsx@@ -1,11 +1,9 @@-import { View } from '@/application/types';import { notify } from '@/components/_shared/notify';import TableSkeleton from '@/components/_shared/skeleton/TableSkeleton';-import { useCurrentWorkspaceId } from '@/components/app/app.hooks';-import { useService } from '@/components/main/app.hooks';+import { useAppTrash, useCurrentWorkspaceId } from '@/components/app/app.hooks';import { TableContainer } from '@mui/material';import dayjs from 'dayjs';-import React, { useCallback, useEffect, useMemo } from 'react';+import React, { useEffect, useMemo } from 'react';import { useTranslation } from 'react-i18next';import Table from '@mui/material/Table';import TableBody from '@mui/material/TableBody';@@ -15,29 +13,20 @@ import TableRow from '@mui/material/TableRow';function TrashPage () {const { t } = useTranslation();- const [trashList, setTrashList] = React.useState<View[]>();- const service = useService();- const currentWorkspaceId = useCurrentWorkspaceId();-- const loadOutline = useCallback(async () => {- if (!service || !currentWorkspaceId) return;- try {- const res = await service?.getAppTrash(currentWorkspaceId);-- if (!res) {- throw new Error('App trash not found');- }-- setTrashList(res);- } catch (e) {- notify.error('App trash not found');- }- }, [currentWorkspaceId, service]);+ const currentWorkspaceId = useCurrentWorkspaceId();+ const { trashList, loadTrash } = useAppTrash();useEffect(() => {- void loadOutline();- }, [loadOutline]);+ void (async () => {+ if (!currentWorkspaceId) return;+ try {+ await loadTrash?.(currentWorkspaceId);+ } catch (e) {+ notify.error('Failed to load trash');+ }+ })();+ }, [loadTrash, currentWorkspaceId]);const columns = useMemo(() => {return [@@ -49,9 +38,10 @@ function TrashPage () {}, [t]);return (- <div style={{- height: 'calc(100vh - 48px)',- }} className={'flex-1 h-full flex-col flex w-full items-center'}+ <div+ style={{+ height: 'calc(100vh - 48px)',+ }} className={'flex-1 h-full flex-col flex w-full items-center'}><div className={'w-[964px] flex flex-col min-w-0 max-w-full px-6 py-10 h-full'}><div