From c97c201af679339c9e217be6b8ff8a0860357aeb Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Thu, 26 Aug 2021 16:49:27 -0300 Subject: [PATCH] fix: fix getting listed extensions logic --- src/screens/Notes/NoteBottomSheet.tsx | 38 +++++++++++---------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/src/screens/Notes/NoteBottomSheet.tsx b/src/screens/Notes/NoteBottomSheet.tsx index 2df2f048..03a71ac4 100644 --- a/src/screens/Notes/NoteBottomSheet.tsx +++ b/src/screens/Notes/NoteBottomSheet.tsx @@ -152,7 +152,7 @@ export const NoteBottomSheet: React.FC = ({ [executeAction] ); - const getListedExpandableSection = useCallback( + const getListedSection = useCallback( (extension: SNActionsExtension, updatedExtension?: SNActionsExtension) => { const key = updatedExtension ? `listed-${updatedExtension.uuid}-section` @@ -186,20 +186,7 @@ export const NoteBottomSheet: React.FC = ({ [getListedActionItem] ); - const getReloadedListedSection = useCallback( - async ( - extension: SNActionsExtension, - extensionToReloadUuid?: UuidString - ) => { - const extensionInContext = extensionToReloadUuid - ? await loadListedExtension(extension) - : extension; - return getListedExpandableSection(extension, extensionInContext); - }, - [getListedExpandableSection, loadListedExtension] - ); - - const getReloadedListedSections = useCallback( + const getListedSections = useCallback( async (extensionToReloadUuid?: UuidString) => { const extensions = listedExtensions; return await Promise.all( @@ -213,20 +200,25 @@ export const NoteBottomSheet: React.FC = ({ return a.name > b.name ? 1 : -1; } }) - .map(async extension => - getReloadedListedSection(extension, extensionToReloadUuid) - ) + .map(async extension => { + let extensionInContext: SNActionsExtension | undefined = extension; + if ( + extensionToReloadUuid && + extension.uuid === extensionToReloadUuid + ) { + extensionInContext = await loadListedExtension(extension); + } + return getListedSection(extension, extensionInContext); + }) ); }, - [getReloadedListedSection, listedExtensions] + [getListedSection, loadListedExtension, listedExtensions] ); useEffect(() => { let mounted = true; const reloadListedSections = async () => { - const newSections = await getReloadedListedSections( - reloadListedExtensionUuid - ); + const newSections = await getListedSections(reloadListedExtensionUuid); if (mounted) { setListedSections(newSections); } @@ -235,7 +227,7 @@ export const NoteBottomSheet: React.FC = ({ return () => { mounted = false; }; - }, [getReloadedListedSections, reloadListedExtensionUuid]); + }, [getListedSections, reloadListedExtensionUuid]); const historyAction: BottomSheetAction = { text: 'Note history',