mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Add back a simple useGitFetch hook
This commit is contained in:
5 files changed
+43
-9
No files matched your search
@@ -376,9 +376,6 @@ export function SyncStep({ projectId, remoteUrl }: SyncStepProps) {
|
||||
)}
|
||||
Pull
|
||||
</Button>
|
||||
{commitsBehind > 0 && (
|
||||
<div className="absolute -top-1 -right-1 size-3 bg-yellow-500 rounded-full border-2 border-background" />
|
||||
)}
|
||||
</div>
|
||||
<div className="relative flex-1">
|
||||
<Button
|
||||
@@ -394,9 +391,6 @@ export function SyncStep({ projectId, remoteUrl }: SyncStepProps) {
|
||||
)}
|
||||
Push
|
||||
</Button>
|
||||
{commitsAhead > 0 && (
|
||||
<div className="absolute -top-1 -right-1 size-3 bg-yellow-500 rounded-full border-2 border-background" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CollapsibleContent>
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useGit } from './useGit';
|
||||
|
||||
export function useGitFetch(dir: string | undefined) {
|
||||
const { git } = useGit();
|
||||
|
||||
const query = useQuery({
|
||||
queryKey: ['git-fetch', dir],
|
||||
queryFn: async (): Promise<void> => {
|
||||
if (!dir) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
try {
|
||||
await git.fetch({
|
||||
dir,
|
||||
});
|
||||
} catch (error) {
|
||||
// Fetch failed, but don't throw - just log and return null
|
||||
console.warn('Git fetch failed:', error);
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error during git fetch:', error);
|
||||
return;
|
||||
}
|
||||
},
|
||||
enabled: !!dir,
|
||||
refetchInterval: 60000, // Fetch every 60 seconds
|
||||
staleTime: 30000, // Consider data stale after 30 seconds
|
||||
retry: false, // Don't retry on failure
|
||||
});
|
||||
|
||||
return query;
|
||||
}
|
||||
@@ -36,6 +36,7 @@ import { useAutoBuild } from '@/hooks/useAutoBuild';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { useFS } from '@/hooks/useFS';
|
||||
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||
import { useGitFetch } from '@/hooks/useGitFetch';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import JSZip from 'jszip';
|
||||
import { cn } from '@/lib/utils';
|
||||
@@ -72,6 +73,9 @@ export function ProjectView() {
|
||||
const build = useBuildProject(projectId!);
|
||||
const { data: isPreviewable = false } = useIsProjectPreviewable(projectId!);
|
||||
|
||||
// Automatically fetch from remote to keep git status updated
|
||||
useGitFetch(projectId ? `${projectsPath}/${projectId}` : undefined);
|
||||
|
||||
// Enable auto-build for previewable projects
|
||||
useAutoBuild({
|
||||
projectId: projectId!,
|
||||
|
||||
Reference in new issue
Block a user