From 56a73196fe8bfde1e13592b6d934e17c2e057b5c Mon Sep 17 00:00:00 2001 From: Nils Kolvenbach Date: Wed, 21 Aug 2024 21:41:33 +0200 Subject: [PATCH] Added refetching project changes button --- .../src/routes/projects/$projectId.tsx | 96 ++++++++++++------- 1 file changed, 61 insertions(+), 35 deletions(-) diff --git a/src/renderer/src/routes/projects/$projectId.tsx b/src/renderer/src/routes/projects/$projectId.tsx index 78a6bad1..51694e5a 100644 --- a/src/renderer/src/routes/projects/$projectId.tsx +++ b/src/renderer/src/routes/projects/$projectId.tsx @@ -20,6 +20,7 @@ import { TooltipTrigger, } from '@renderer/components/ui/tooltip'; import { NotificationIntent, useStore } from '@renderer/store'; +import { useQuery } from '@tanstack/react-query'; import { Link, Outlet, @@ -28,6 +29,8 @@ import { useRouter, } from '@tanstack/react-router'; import { + ArrowDownUp, + DownloadCloud, FolderGit2, FolderOutput, Image, @@ -37,6 +40,7 @@ import { RefreshCw, Search, Settings, + UploadCloud, } from 'lucide-react'; import { useEffect, useState } from 'react'; @@ -73,22 +77,6 @@ export const Route = createFileRoute('/projects/$projectId')({ id: params.projectId, }); - let currentProjectRemoteOriginUrl = null; - try { - currentProjectRemoteOriginUrl = - await context.core.projects.remotes.getOriginUrl({ - id: params.projectId, - }); - } catch (error) { - console.info(error); - } - - const changes = currentProjectRemoteOriginUrl - ? await context.core.projects.getChanges({ - id: params.projectId, - }) - : null; - const collections = await context.core.collections.list({ projectId: params.projectId, limit: 0, @@ -96,8 +84,6 @@ export const Route = createFileRoute('/projects/$projectId')({ return { currentProject, - currentProjectRemoteOriginUrl, - changes, collections, translate, }; @@ -167,6 +153,24 @@ function ProjectLayout(): JSX.Element { }); }, [context.collections]); + const { + status, + data: projectChanges, + error, + isFetching: isFetchingProjectChanges, + refetch: refetchProjectChanges, + } = useQuery({ + queryKey: ['projectChanges'], + queryFn: async () => { + const changes = await context.core.projects.getChanges({ + id: context.currentProject.id, + }); + return changes; + }, + // Refetch the data every 3 minutes + refetchInterval: 180000, + }); + async function onSearch(value: string): Promise { setSearchQuery(value); // @todo noop @@ -202,7 +206,8 @@ function ProjectLayout(): JSX.Element { title: 'Successfully synchronized Project', description: 'The Project was successfully synchronized.', }); - router.invalidate(); + await refetchProjectChanges(); + // router.invalidate(); } catch (error) { setIsSynchronizing(false); console.error(error); @@ -241,22 +246,43 @@ function ProjectLayout(): JSX.Element { {context.currentProjectRemoteOriginUrl && ( <> -
- +
+
+ + +
+

- Downloads {context.changes?.behind.length} and uploads{' '} - {context.changes?.ahead.length} changes + {isFetchingProjectChanges ? ( + 'Loading' + ) : ( +

+ + {projectChanges?.behind.length} + + {projectChanges?.ahead.length} +
+ )}

@@ -264,7 +290,7 @@ function ProjectLayout(): JSX.Element { )} - + {isProjectSidebarNarrow && (