From ff23eb369c15be52e8a3a8f524b011ccab5dcf2a Mon Sep 17 00:00:00 2001 From: Oscar Beaumont Date: Mon, 30 Oct 2023 11:42:21 +1100 Subject: [PATCH] [ENG-1379] Library showing up twice in switcher after onboarding (#1700) optimistic UI bug --- .../mobile/src/components/modal/CreateLibraryModal.tsx | 10 ++++++---- interface/app/onboarding/context.tsx | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/mobile/src/components/modal/CreateLibraryModal.tsx b/apps/mobile/src/components/modal/CreateLibraryModal.tsx index 7a2b25084..15d47706f 100644 --- a/apps/mobile/src/components/modal/CreateLibraryModal.tsx +++ b/apps/mobile/src/components/modal/CreateLibraryModal.tsx @@ -25,10 +25,12 @@ const CreateLibraryModal = forwardRef((_, ref) => { setLibName(''); // We do this instead of invalidating the query because it triggers a full app re-render?? - queryClient.setQueryData(['library.list'], (libraries: any) => [ - ...(libraries || []), - lib - ]); + queryClient.setQueryData(['library.list'], (libraries: any) => { + // The invalidation system beat us to it + if (libraries.find((l: any) => l.uuid === lib.uuid)) return libraries; + + return [...(libraries || []), lib]; + }); // Switch to the new library currentLibraryStore.id = lib.uuid; diff --git a/interface/app/onboarding/context.tsx b/interface/app/onboarding/context.tsx index 9741ee63c..e09a3af8c 100644 --- a/interface/app/onboarding/context.tsx +++ b/interface/app/onboarding/context.tsx @@ -114,10 +114,12 @@ const useFormState = () => { new Promise((res) => setTimeout(res, 500)) ]); - queryClient.setQueryData(['library.list'], (libraries: any) => [ - ...(libraries ?? []), - library - ]); + queryClient.setQueryData(['library.list'], (libraries: any) => { + // The invalidation system beat us to it + if (libraries.find((l: any) => l.uuid === library.uuid)) return libraries; + + return [...(libraries || []), library]; + }); platform.refreshMenuBar && platform.refreshMenuBar();