-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitSetupModal.tsx
More file actions
208 lines (189 loc) · 6.43 KB
/
Copy pathGitSetupModal.tsx
File metadata and controls
208 lines (189 loc) · 6.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { GitBranch, Terminal, CheckCircle2, AlertCircle, Loader2, FolderGit2 } from 'lucide-react';
import { Button } from './ui/button';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle
} from './ui/dialog';
import type { Project, GitStatus } from '../../shared/types';
interface GitSetupModalProps {
open: boolean;
onOpenChange: (open: boolean) => void;
project: Project | null;
gitStatus: GitStatus | null;
onGitInitialized: () => void;
onSkip?: () => void;
}
export function GitSetupModal({
open,
onOpenChange,
project,
gitStatus,
onGitInitialized,
onSkip
}: GitSetupModalProps) {
const { t } = useTranslation('dialogs');
const [isInitializing, setIsInitializing] = useState(false);
const [error, setError] = useState<string | null>(null);
const [step, setStep] = useState<'info' | 'initializing' | 'success'>('info');
const needsGitInit = gitStatus && !gitStatus.isGitRepo;
const _needsCommit = gitStatus?.isGitRepo && !gitStatus.hasCommits;
const handleInitializeGit = async () => {
if (!project) return;
setIsInitializing(true);
setError(null);
setStep('initializing');
try {
// Call the backend to initialize git
const result = await window.electronAPI.initializeGit(project.path);
if (result.success) {
setStep('success');
// Wait a moment to show success, then trigger callback
setTimeout(() => {
onGitInitialized();
onOpenChange(false);
setStep('info');
}, 1500);
} else {
setError(result.error || 'Failed to initialize git');
setStep('info');
}
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to initialize git');
setStep('info');
} finally {
setIsInitializing(false);
}
};
const handleSkip = () => {
onSkip?.();
onOpenChange(false);
};
const renderInfoStep = () => (
<>
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<FolderGit2 className="h-5 w-5 text-primary" />
{t('gitSetup.title')}
</DialogTitle>
<DialogDescription>
{t('gitSetup.description')}
</DialogDescription>
</DialogHeader>
<div className="py-4 space-y-4">
{/* Status indicator */}
<div className="rounded-lg bg-muted p-4">
<div className="flex items-start gap-3">
<AlertCircle className="h-5 w-5 text-warning mt-0.5 shrink-0" />
<div className="space-y-1">
<p className="font-medium text-sm">
{needsGitInit
? t('gitSetup.notGitRepo')
: t('gitSetup.noCommits')}
</p>
<p className="text-sm text-muted-foreground">
{needsGitInit
? t('gitSetup.needsInit')
: t('gitSetup.needsCommit')}
</p>
</div>
</div>
</div>
{/* What will happen */}
<div className="rounded-lg border border-border p-4">
<p className="font-medium text-sm mb-3">{t('gitSetup.willSetup')}</p>
<ul className="space-y-2">
{needsGitInit && (
<li className="flex items-center gap-2 text-sm text-muted-foreground">
<GitBranch className="h-4 w-4 text-primary" />
{t('gitSetup.initRepo')}
</li>
)}
<li className="flex items-center gap-2 text-sm text-muted-foreground">
<CheckCircle2 className="h-4 w-4 text-primary" />
{t('gitSetup.createCommit')}
</li>
</ul>
</div>
{/* Manual instructions for advanced users */}
<details className="text-sm">
<summary className="cursor-pointer text-muted-foreground hover:text-foreground">
{t('gitSetup.manual')}
</summary>
<div className="mt-3 rounded-lg bg-muted/50 p-3 font-mono text-xs space-y-1">
<p className="text-muted-foreground">Open a terminal in your project folder and run:</p>
{needsGitInit && <p>git init</p>}
<p>git add .</p>
<p>git commit -m "Initial commit"</p>
</div>
</details>
{error && (
<div className="rounded-lg bg-destructive/10 border border-destructive/20 p-3 text-sm text-destructive">
{error}
</div>
)}
</div>
<DialogFooter>
<Button variant="outline" onClick={handleSkip}>
Skip for now
</Button>
<Button onClick={handleInitializeGit} disabled={isInitializing}>
<GitBranch className="mr-2 h-4 w-4" />
Initialize Git
</Button>
</DialogFooter>
</>
);
const renderInitializingStep = () => (
<>
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<Loader2 className="h-5 w-5 animate-spin text-primary" />
{t('gitSetup.settingUp')}
</DialogTitle>
</DialogHeader>
<div className="py-8 flex flex-col items-center justify-center">
<div className="space-y-3 text-center">
<Terminal className="h-12 w-12 text-muted-foreground mx-auto" />
<p className="text-sm text-muted-foreground">
{t('gitSetup.initializingRepo')}
</p>
</div>
</div>
</>
);
const renderSuccessStep = () => (
<>
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<CheckCircle2 className="h-5 w-5 text-success" />
{t('gitSetup.success')}
</DialogTitle>
</DialogHeader>
<div className="py-8 flex flex-col items-center justify-center">
<div className="space-y-3 text-center">
<div className="h-16 w-16 rounded-full bg-success/10 flex items-center justify-center mx-auto">
<CheckCircle2 className="h-8 w-8 text-success" />
</div>
<p className="text-sm text-muted-foreground">
{t('gitSetup.readyToUse')}
</p>
</div>
</div>
</>
);
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-md">
{step === 'info' && renderInfoStep()}
{step === 'initializing' && renderInitializingStep()}
{step === 'success' && renderSuccessStep()}
</DialogContent>
</Dialog>
);
}