From 9dc3f24c82b9b249165fc1ac020a5c52533b1875 Mon Sep 17 00:00:00 2001 From: Curry Yang <1019yanglu@gmail.com> Date: Thu, 11 Jul 2024 11:47:46 +0800 Subject: [PATCH 1/2] sync status indicator --- .../insomnia/src/ui/routes/organization.tsx | 59 +++++++++++++++---- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/packages/insomnia/src/ui/routes/organization.tsx b/packages/insomnia/src/ui/routes/organization.tsx index 31fb8ec14ea..5ec0ead2816 100644 --- a/packages/insomnia/src/ui/routes/organization.tsx +++ b/packages/insomnia/src/ui/routes/organization.tsx @@ -1,4 +1,4 @@ -import React, { Fragment, useEffect, useState } from 'react'; +import React, { Fragment, useCallback, useEffect, useState } from 'react'; import { Button, Link, @@ -461,24 +461,31 @@ const OrganizationRoute = () => { const syncOrgsAndProjectsFetcher = useFetcher(); - useEffect(() => { + const asyncTaskStatus = syncOrgsAndProjectsFetcher.data?.error ? 'error' : syncOrgsAndProjectsFetcher.state; + + const syncOrgsAndProjects = useCallback(() => { const submit = syncOrgsAndProjectsFetcher.submit; + console.log('asyncTaskList', asyncTaskList); + submit({ + organizationId, + projectId: projectId || '', + asyncTaskList, + }, { + action: '/organization/syncOrgsAndProjectsAction', + method: 'POST', + encType: 'application/json', + }); + }, [asyncTaskList, organizationId, syncOrgsAndProjectsFetcher.submit, projectId]); + + useEffect(() => { // each route navigation will change history state, only submit this action when the asyncTaskList state is not empty // currently we have 2 cases that will set the asyncTaskList state // 1. first entry // 2. when user switch to another organization if (asyncTaskList?.length) { - submit({ - organizationId, - projectId: projectId || '', - asyncTaskList, - }, { - action: '/organization/syncOrgsAndProjectsAction', - method: 'POST', - encType: 'application/json', - }); + syncOrgsAndProjects(); } - }, [userSession.id, organizationId, userSession.accountId, syncOrgsAndProjectsFetcher.submit, asyncTaskList, projectId]); + }, [organizationId, asyncTaskList, syncOrgsAndProjects]); useEffect(() => { const isIdleAndUninitialized = untrackedProjectsFetcher.state === 'idle' && !untrackedProjectsFetcher.data; @@ -883,7 +890,32 @@ const OrganizationRoute = () => { )} )} - + {/* The sync indicator only show when network status is online */} + {/* use for show sync organization and projects status(1. first enter app 2. switch organization) */} + {status === 'online' && asyncTaskStatus !== 'idle' ? ( + + + + {asyncTaskStatus !== 'error' ? 'Syncing' : 'Sync error: click to retry'} + + + ) : ( +