From e599f76787fc012194fca56f988cb3f1aa166012 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 24 Dec 2025 21:38:57 -0600 Subject: [PATCH] Add back a simple useGitFetch hook --- AGENTS.md | 4 +-- package-lock.json | 1 - src/components/git-sync/steps/SyncStep.tsx | 6 ---- src/hooks/useGitFetch.ts | 37 ++++++++++++++++++++++ src/pages/ProjectView.tsx | 4 +++ 5 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 src/hooks/useGitFetch.ts diff --git a/AGENTS.md b/AGENTS.md index 4c86b836..5d8bac80 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -89,7 +89,7 @@ Shakespeare provides full Git functionality in the browser using `isomorphic-git - **LightningFSAdapter**: Adapts LightningFS to the unified JSRuntimeFS interface - **GitCommitTool**: AI tool for automated commits with staging and validation - **useGitStatus Hook**: Real-time Git status monitoring (updates every 5 seconds) -- **useGitFetch Hook**: Automatic remote fetch with change detection (updates every 60 seconds, shows toast notifications) +- **useGitFetch Hook**: Automatic remote fetch - **ProjectsManager**: Handles project creation, Git initialization, and template cloning #### Core Features @@ -218,7 +218,7 @@ This project is a Nostr client application built with React 18.x, TailwindCSS 3. - `useGitSettings`: Manage Git credentials and repository settings - `useSessionManager`: Access session management for AI chat sessions - `useGitStatus`: Real-time Git repository status monitoring - - `useGitFetch`: Automatic remote fetch with change detection and toast notifications + - `useGitFetch`: Automatic remote fetch - `useProjects`: Project management and CRUD operations - `useProjectsManager`: Advanced project operations (creation, cloning, building, ZIP import) - `useTheme`: Theme management diff --git a/package-lock.json b/package-lock.json index f4009f9c..1b87c549 100644 --- a/package-lock.json +++ b/package-lock.json @@ -117,7 +117,6 @@ "@types/uri-templates": "^0.1.34", "@vitejs/plugin-react-swc": "^3.5.0", "autoprefixer": "^10.4.20", - "baseline-browser-mapping": "^2.9.11", "electron": "^39.0.0", "eslint": "^9.9.0", "eslint-plugin-react-hooks": "^5.1.0-rc.0", diff --git a/src/components/git-sync/steps/SyncStep.tsx b/src/components/git-sync/steps/SyncStep.tsx index 4bd63e6f..cdff2d18 100644 --- a/src/components/git-sync/steps/SyncStep.tsx +++ b/src/components/git-sync/steps/SyncStep.tsx @@ -376,9 +376,6 @@ export function SyncStep({ projectId, remoteUrl }: SyncStepProps) { )} Pull - {commitsBehind > 0 && ( -
- )}
diff --git a/src/hooks/useGitFetch.ts b/src/hooks/useGitFetch.ts new file mode 100644 index 00000000..60831ff3 --- /dev/null +++ b/src/hooks/useGitFetch.ts @@ -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 => { + 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; +} diff --git a/src/pages/ProjectView.tsx b/src/pages/ProjectView.tsx index d4d5222b..bbba5077 100644 --- a/src/pages/ProjectView.tsx +++ b/src/pages/ProjectView.tsx @@ -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!,