Add git autosync functionality

This commit is contained in:
Alex Gleason committed 2025-12-29 16:00:23 -06:00
1 parent 0ee88f5968
commit 758e3ab261
7 files changed
+201 -51

No files matched your search

@@ -193,6 +193,13 @@ export function ConfigureRepoStep({
});
}
// Enable autosync by default after successfully setting up the remote
await git.setConfig({
dir,
path: 'shakespeare.autosync',
value: 'true',
});
// Refresh git status before showing success
await refetchGitStatus();
// Show success state
+57 -1
View File
@@ -1,8 +1,10 @@
import { useState, useCallback } from 'react';
import { useState, useCallback, useEffect } from 'react';
import { Zap, Copy, Check, RefreshCw, EllipsisVertical, CloudOff, ExternalLink, ChevronDown, ArrowDown, ArrowUp, LoaderCircle, History } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Switch } from '@/components/ui/switch';
import { useQueryClient } from '@tanstack/react-query';
import {
DropdownMenu,
DropdownMenuContent,
@@ -41,6 +43,8 @@ export function SyncStep({ projectId, remoteUrl }: SyncStepProps) {
const [showForcePullDialog, setShowForcePullDialog] = useState(false);
const [showForcePushDialog, setShowForcePushDialog] = useState(false);
const [gitHistoryOpen, setGitHistoryOpen] = useState(false);
const [autosync, setAutosync] = useState<boolean>(false);
const [isLoadingAutosync, setIsLoadingAutosync] = useState(true);
const { data: gitStatus } = useGitStatus(projectId);
const { settings } = useGitSettings();
@@ -55,6 +59,45 @@ export function SyncStep({ projectId, remoteUrl }: SyncStepProps) {
const commitsAhead = gitStatus?.ahead ?? 0;
const commitsBehind = gitStatus?.behind ?? 0;
// Load autosync config on mount
useEffect(() => {
const loadAutosync = async () => {
try {
const value = await git.getConfig({
dir,
path: 'shakespeare.autosync',
});
setAutosync(value === 'true');
} catch {
// Config not set, default to false
setAutosync(false);
} finally {
setIsLoadingAutosync(false);
}
};
loadAutosync();
}, [git, dir]);
// Handler to toggle autosync
const handleAutosyncToggle = async (checked: boolean) => {
try {
await git.setConfig({
dir,
path: 'shakespeare.autosync',
value: String(checked),
});
setAutosync(checked);
// If enabling autosync, trigger an immediate sync
if (checked) {
queryClient.invalidateQueries({ queryKey: ['git-sync', dir] });
}
} catch (error) {
console.error('Failed to set autosync config:', error);
}
};
// Generic git operation handler
const executeGitOperation = useCallback(async (
operation: GitOperation,
@@ -306,6 +349,19 @@ export function SyncStep({ projectId, remoteUrl }: SyncStepProps) {
</div>
</div>
<div className="flex items-center gap-1.5">
<Switch
id="autosync"
checked={autosync}
onCheckedChange={handleAutosyncToggle}
disabled={isLoadingAutosync}
className="scale-75"
/>
<Label htmlFor="autosync" className="text-xs cursor-pointer font-normal text-muted-foreground">
Automatic sync
</Label>
</div>
{error && (
<SyncStepError
error={error}