From c13311343df996d62d5224f00f6cf0a5def8f6f6 Mon Sep 17 00:00:00 2001 From: Tom Chapman Date: Mon, 8 Jul 2024 15:25:04 -0700 Subject: [PATCH] fetch surveys concurrently in attempt to reduce load times --- .../components/survey/create/OptionsForm.tsx | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/met-web/src/components/survey/create/OptionsForm.tsx b/met-web/src/components/survey/create/OptionsForm.tsx index a81317896..a867895b5 100644 --- a/met-web/src/components/survey/create/OptionsForm.tsx +++ b/met-web/src/components/survey/create/OptionsForm.tsx @@ -26,17 +26,18 @@ const OptionsForm = () => { const handleFetchSurveys = async () => { try { - const fetchedLinkableSurveys = await fetchSurveys({ - is_unlinked: true, - exclude_hidden: true, - exclude_template: true, - }); - setAvailableLinkSurveys(fetchedLinkableSurveys); - - const fetchedClonableSurveys = await fetchSurveys({ - exclude_hidden: true, - }); + const [fetchedLinkableSurveys, fetchedClonableSurveys] = await Promise.all([ + fetchSurveys({ + is_unlinked: true, + exclude_hidden: true, + exclude_template: true, + }), + fetchSurveys({ + exclude_hidden: true, + }), + ]); + setAvailableLinkSurveys(fetchedLinkableSurveys); setAvailableCloneSurveys(fetchedClonableSurveys); setLoadingSurveys(false); } catch (error) {