Add back a simple useGitFetch hook

This commit is contained in:
Alex Gleason committed 2025-12-24 21:38:57 -06:00
1 parent a9c1922e51
commit e599f76787
5 files changed
+43 -9

No files matched your search

+2 -2
View File
@@ -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
-1
View File
@@ -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",
@@ -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>
+37
View File
@@ -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;
}
+4
View File
@@ -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!,