From 19774deb976ea4b96083cef4ff9b90c88a46592e Mon Sep 17 00:00:00 2001 From: Horacio Herrera Date: Sat, 2 Sep 2023 03:26:13 +0200 Subject: [PATCH] frontend: improve rendering perf. prefetch drafts and publications --- frontend/apps/desktop/src/root.tsx | 70 +++++----- frontend/packages/app/src/app-context.tsx | 7 +- .../packages/app/src/components/list-item.tsx | 20 ++- .../src/components/publication-list-item.tsx | 8 +- .../app/src/components/quick-switcher.tsx | 6 +- frontend/packages/app/src/editor/editor.tsx | 6 +- frontend/packages/app/src/models/documents.ts | 52 ++++---- .../packages/app/src/node-status-context.tsx | 2 - .../app/src/pages/draft-list-page.tsx | 80 +++++++++--- frontend/packages/app/src/pages/draft.tsx | 90 +++++++++---- frontend/packages/app/src/pages/main.tsx | 15 ++- .../packages/app/src/pages/onboarding.tsx | 18 ++- .../app/src/pages/publication-list-page.tsx | 121 +++++++++++------- .../packages/app/src/pages/publication.tsx | 104 ++++----------- frontend/packages/app/src/pages/settings.tsx | 4 +- frontend/packages/app/src/pages/site-page.tsx | 19 +-- .../packages/app/src/utils/navigation.tsx | 46 +++---- 17 files changed, 359 insertions(+), 309 deletions(-) diff --git a/frontend/apps/desktop/src/root.tsx b/frontend/apps/desktop/src/root.tsx index 1a1b91a974..dbf0924cc2 100644 --- a/frontend/apps/desktop/src/root.tsx +++ b/frontend/apps/desktop/src/root.tsx @@ -1,7 +1,9 @@ +import {ErrorBoundary} from 'react-error-boundary' +import {Suspense} from 'react' import {Interceptor, createGrpcWebTransport} from '@bufbuild/connect-web' import {AppContextProvider, StyleProvider} from '@mintter/app/app-context' import {AppIPC} from '@mintter/app/app-ipc' -import {AppErrorPage} from '@mintter/app/components/app-error' +import {AppError, AppErrorPage} from '@mintter/app/components/app-error' import {BACKEND_HTTP_URL} from '@mintter/app/constants' import {DaemonStatusProvider} from '@mintter/app/node-status-context' import Main from '@mintter/app/pages/main' @@ -143,6 +145,7 @@ function MainApp({ queryClient: AppQueryClient ipc: AppIPC }) { + console.log('== RENDERING MAINAPP') const daemonState = useGoDaemonState() const grpcClient = useMemo(() => createGRPCClient(transport), []) const windowUtils = useWindowUtils(ipc) @@ -155,51 +158,44 @@ function MainApp({ lastAction: null, } }, [initRoute]) - if (!daemonState) return null - if (daemonState?.t === 'error') { + + if (daemonState?.t == 'ready') { return ( - - - + { + toast.error('Not implemented open: ' + url) + }} + saveCidAsFile={async (cid: string, name: string) => { + ipc.send?.('save-file', {cid, name}) + }} + windowUtils={windowUtils} + > + + +
+ + + + ) } - if (daemonState?.t !== 'ready') { + + if (daemonState?.t === 'error') { return ( - - - + ) } - return ( - { - toast.error('Not implemented open: ' + url) - }} - saveCidAsFile={async (cid: string, name: string) => { - ipc.send?.('save-file', {cid, name}) - }} - windowUtils={windowUtils} - > - - -
- - - - - ) + return null } function ElectronApp() { diff --git a/frontend/packages/app/src/app-context.tsx b/frontend/packages/app/src/app-context.tsx index fe20422f3b..22ef260011 100644 --- a/frontend/packages/app/src/app-context.tsx +++ b/frontend/packages/app/src/app-context.tsx @@ -48,6 +48,7 @@ export function AppContextProvider({ windowUtils: WindowUtils saveCidAsFile: (cid: string, name: string) => Promise }) { + console.log('== RENDERING APP CONTEXT PROVIDER') if (!queryClient) throw new Error('queryClient is required for AppContextProvider') return ( @@ -63,11 +64,7 @@ export function AppContextProvider({ }} > - - - {children} - - + {children} diff --git a/frontend/packages/app/src/components/list-item.tsx b/frontend/packages/app/src/components/list-item.tsx index 93f0aed191..caee0c6e92 100644 --- a/frontend/packages/app/src/components/list-item.tsx +++ b/frontend/packages/app/src/components/list-item.tsx @@ -1,5 +1,5 @@ -import {FC, ReactElement, useState} from 'react' -import {usePopoverState} from '../use-popover-state' +import {Timestamp} from '@bufbuild/protobuf' +import {formattedDate} from '@mintter/shared' import { Button, ButtonText, @@ -8,10 +8,10 @@ import { Separator, YGroup, } from '@mintter/ui' -import {GestureResponderEvent, GestureResponderHandlers} from 'react-native' +import {FC, ReactElement} from 'react' +import {GestureResponderEvent} from 'react-native' +import {usePopoverState} from '../use-popover-state' import {MenuItem} from './dropdown' -import {formattedDate} from '@mintter/shared' -import {Timestamp} from '@bufbuild/protobuf' export type MenuItem = { key: string @@ -24,24 +24,22 @@ export function ListItem({ accessory, title, onPress, - onPrefetch, + onPointerEnter, menuItems = [], }: { accessory: ReactElement title: string onPress: (e: GestureResponderEvent) => void - onPrefetch?: () => void + onPointerEnter?: () => void menuItems?: MenuItem[] }) { // const [isHovering, setIsHovering] = useState(false) const popoverState = usePopoverState() + return ( <> + -