From c3ae9e7ac62757aa33f1e1e9ea74627e1ce00699 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Tue, 25 Jun 2024 09:24:51 +0800 Subject: [PATCH] Dont revalidate shortcuts on focus to reduce flicker --- packages/web/components/nav-containers/HomeContainer.tsx | 2 -- packages/web/components/templates/navMenu/LibraryMenu.tsx | 2 ++ packages/web/components/templates/navMenu/NavigationMenu.tsx | 4 ++++ packages/web/lib/networking/queries/useGetHome.tsx | 3 --- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/web/components/nav-containers/HomeContainer.tsx b/packages/web/components/nav-containers/HomeContainer.tsx index 2dbd80152..caff8de2d 100644 --- a/packages/web/components/nav-containers/HomeContainer.tsx +++ b/packages/web/components/nav-containers/HomeContainer.tsx @@ -75,7 +75,6 @@ export function HomeContainer(): JSX.Element { > {homeData.sections?.map((homeSection, idx) => { if (homeSection.items.length < 1) { - console.log('empty home section: ', homeSection) return } switch (homeSection.layout) { @@ -224,7 +223,6 @@ const TopPicksHomeSection = (props: HomeSectionProps): JSX.Element => { items?: HomeItem[] } ) => { - console.log('handling action: ', action) switch (action.type) { case 'RESET': return action.items ?? [] diff --git a/packages/web/components/templates/navMenu/LibraryMenu.tsx b/packages/web/components/templates/navMenu/LibraryMenu.tsx index 6e4849bba..000507889 100644 --- a/packages/web/components/templates/navMenu/LibraryMenu.tsx +++ b/packages/web/components/templates/navMenu/LibraryMenu.tsx @@ -185,6 +185,8 @@ const Shortcuts = (props: LibraryFilterMenuProps): JSX.Element => { initialValue: [], }) + console.log('got shortcuts: ', shortcuts) + // const shortcuts: Shortcut[] = [ // { // id: '12asdfasdf', diff --git a/packages/web/components/templates/navMenu/NavigationMenu.tsx b/packages/web/components/templates/navMenu/NavigationMenu.tsx index eeef9c4c0..2f442c9b6 100644 --- a/packages/web/components/templates/navMenu/NavigationMenu.tsx +++ b/packages/web/components/templates/navMenu/NavigationMenu.tsx @@ -375,6 +375,7 @@ async function setShortcuts( async function resetShortcuts(path: string): Promise { const url = new URL(path, fetchEndpoint) + console.log('resetting shortcuts') try { const response = await fetch(url.toString(), { method: 'DELETE', @@ -399,10 +400,12 @@ async function resetShortcuts(path: string): Promise { const cachedShortcutsData = (): Shortcut[] | undefined => { if (typeof localStorage !== 'undefined') { const str = localStorage.getItem('/api/shortcuts') + console.log('cached shortcuts: ', str) if (str) { return JSON.parse(str) as Shortcut[] } } + console.log('undefined shortcuts') return undefined } @@ -411,6 +414,7 @@ const ShortcutsTree = (props: ShortcutsTreeProps): JSX.Element => { const { ref, width, height } = useResizeObserver() const { isValidating, data } = useSWR('/api/shortcuts', getShortcuts, { + revalidateOnFocus: false, fallbackData: cachedShortcutsData(), onSuccess(data) { localStorage.setItem('/api/shortcuts', JSON.stringify(data)) diff --git a/packages/web/lib/networking/queries/useGetHome.tsx b/packages/web/lib/networking/queries/useGetHome.tsx index 1c4d32839..4fbb19695 100644 --- a/packages/web/lib/networking/queries/useGetHome.tsx +++ b/packages/web/lib/networking/queries/useGetHome.tsx @@ -147,8 +147,6 @@ export function useGetHomeItems(): HomeItemResponse { } const result = data as HomeResult - console.log('result: ', result) - if (result && result.home.errorCodes) { const errorCodes = result.home.errorCodes return { @@ -159,7 +157,6 @@ export function useGetHomeItems(): HomeItemResponse { } if (result && result.home && result.home.edges) { - console.log('data', result.home) return { mutate, error: false,