diff --git a/packages/insomnia/src/ui/index.tsx b/packages/insomnia/src/ui/index.tsx index 975e1fb6e..aac9b0582 100644 --- a/packages/insomnia/src/ui/index.tsx +++ b/packages/insomnia/src/ui/index.tsx @@ -176,7 +176,7 @@ async function renderApp() { action: async (...args) => (await import('./routes/organization')).syncOrganizationsAction(...args), }, { - path: 'syncOrgsAndProjectsAction', + path: 'sync-orgs-and-projects', action: async (...args) => (await import('./routes/organization')).syncOrgsAndProjectsAction(...args), }, { diff --git a/packages/insomnia/src/ui/routes/organization.tsx b/packages/insomnia/src/ui/routes/organization.tsx index 31fb8ec14..97d3a077b 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; + + submit({ + organizationId, + projectId: projectId || '', + asyncTaskList, + }, { + action: '/organization/sync-orgs-and-projects', + 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'} + + + ) : ( +