Repository navigation
Expand file tree
/
Copy pathSidebar.jsx
More file actions
134 lines (122 loc) Β· 5.72 KB
/
Copy pathSidebar.jsx
File metadata and controls
134 lines (122 loc) Β· 5.72 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
import { useEffect, useState } from 'react';
import api from '../lib/api.js';
const ICO = { js: 'π¨', ts: 'π¦', py: 'π', java: 'β', html: 'π', css: 'π¨', json: 'π§Ύ', md: 'π', sh: 'π₯οΈ' };
export default function CodePanel({ provider, project, onProjectLoaded, onToast }) {
const [active, setActive] = useState(null);
const [content, setContent] = useState('');
const [review, setReview] = useState(null);
const [reviewBusy, setReviewBusy] = useState(false);
const [fixBusy, setFixBusy] = useState(false);
const [missingBusy, setMissingBusy] = useState(false);
useEffect(() => {
if (project && project.files?.length && !active) {
const first = project.files.find(f => f.isText);
if (first) openFile(first.path);
}
}, [project]);
async function openFile(path) {
setActive(path);
try { const r = await api.readFile(project.id, path); setContent(r.content); }
catch (e) { setContent('// ' + e.message); }
}
function langIcon(path) {
const ext = path.split('.').pop();
return ICO[ext] || 'π';
}
async function doReview() {
if (!project) return;
setReviewBusy(true); setReview(null);
try { setReview(await api.review(project.id, provider)); onToast('Review complete'); }
catch (e) { onToast('β ' + e.message); } finally { setReviewBusy(false); }
}
async function doFix() {
if (!project) return;
setFixBusy(true);
try {
await api.fix(project.id, provider);
const pr = await api.project(project.id);
onProjectLoaded({ id: project.id, name: project.name, files: pr.files });
if (active) { const r = await api.readFile(project.id, active); setContent(r.content); }
onToast('β
Fixed & applied');
} catch (e) { onToast('β ' + e.message); } finally { setFixBusy(false); }
}
async function doMissing() {
if (!project) return;
setMissingBusy(true);
try {
const r = await api.addMissing(project.id, project.name, provider);
const pr = await api.project(project.id);
onProjectLoaded({ id: project.id, name: project.name, files: pr.files });
onToast(`β
Added missing files: ${(r.added || []).map(a => a.path).join(', ') || 'none needed'}`);
} catch (e) { onToast('β ' + e.message); } finally { setMissingBusy(false); }
}
const score = review?.score;
return (
<div className="panel">
<div className="tabs">
<button className="tab active">Files</button>
</div>
<div className="row" style={{ marginBottom: 16, justifyContent: 'space-between' }}>
<div className="row">
<button className="btn" onClick={doReview} disabled={!project || reviewBusy}>{reviewBusy ? 'β¦' : 'π Review & Score'}</button>
<button className="btn" onClick={doFix} disabled={!project || fixBusy}>{fixBusy ? 'β¦' : 'π οΈ Fix code'}</button>
<button className="btn" onClick={doMissing} disabled={!project || missingBusy}>{missingBusy ? 'β¦' : 'β Add missing files'}</button>
</div>
{score !== undefined && (
<div className="row" style={{ gap: 12 }}>
<div className="score-ring" style={{ '--v': score }}><span>{score}</span></div>
<div className="small muted">
<b style={{ color: score >= 90 ? 'var(--ok)' : score >= 70 ? 'var(--warn)' : 'var(--err)' }}>
{score >= 90 ? 'Perfect / Ready' : score >= 70 ? 'Good' : 'Needs work'}
</b><br />
quality score
</div>
</div>
)}
</div>
{review && (
<div className="card">
<h3>π Review results</h3>
{(review.files || []).filter(f => (f.issues || []).length).length === 0 && <p className="muted">No issues found. Looks clean! π</p>}
{(review.files || []).filter(f => (f.issues || []).length).map(f => (
<div className="fileblock" key={f.path}>
<h4>π {f.path}</h4>
{(f.issues || []).map((iss, i) => (
<div className="issue" key={i}>
<span className={`sev ${iss.severity}`}>{iss.severity}</span>
<div><div className="path">line {iss.line}</div>{iss.message}</div>
</div>
))}
</div>
))}
</div>
)}
{project ? (
<div className="card" style={{ padding: 12 }}>
<div className="row" style={{ alignItems: 'flex-start', gap: 16 }}>
<div className="tree" style={{ width: 240, flexShrink: 0 }}>
<div className="small muted" style={{ margin: '4px 8px 8px' }}>π {project.name} β {project.files?.length} files</div>
{(project.files || []).map(f => (
<div key={f.path} className={`tree-item ${active === f.path ? 'selected' : ''}`} onClick={() => openFile(f.path)}>
<span>{langIcon(f.path)}</span>
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{f.path}</span>
<span className="muted">{f.size < 1024 ? `${f.size}B` : `${(f.size / 1024).toFixed(1)}KB`}</span>
</div>
))}
</div>
<div style={{ flex: 1, minWidth: 0 }}>
{active ? (
<>
<div className="small muted" style={{ marginBottom: 6 }}>π {active}</div>
<pre className="term mono" style={{ padding: 12, whiteSpace: 'pre-wrap', minHeight: 200 }}>{content}</pre>
</>
) : <p className="muted">Select a file to view its code.</p>}
</div>
</div>
</div>
) : (
<div className="empty-state"><h2>No project yet</h2><p>Upload a zip on the Home tab or generate code from text.</p></div>
)}
</div>
);
}