fix up git

This commit is contained in:
2026-06-30 15:06:12 +07:00
parent 11e5a76977
commit 38e22b3390
13 changed files with 883 additions and 18 deletions

View File

@@ -53,6 +53,7 @@ export const ExamRoomWorkspace: React.FC<Props> = ({ examId, onBack }) => {
const [gitPublishUrl, setGitPublishUrl] = useState('');
const [bundlingSubs, setBundlingSubs] = useState(false);
const [publishingGit, setPublishingGit] = useState(false);
const [publishingGitStudents, setPublishingGitStudents] = useState(false);
const gh = useGitHubConnection();
const [editable, setEditable] = useState(false);
const [prepEditable, setPrepEditable] = useState(false);
@@ -269,6 +270,26 @@ export const ExamRoomWorkspace: React.FC<Props> = ({ examId, onBack }) => {
}
};
const publishToGitStudents = async () => {
if (!gh.connected) {
setErr('Kết nối GitHub trong Tài khoản của tôi trước khi đẩy.');
return;
}
setErr(''); setMsg('');
setPublishingGitStudents(true);
try {
const res = await apiExam.publishSubmissionsGitStudents(examId);
setMsg(res.message || 'Đã tạo repo từng sinh viên');
if (res.openUrl) window.open(res.openUrl, '_blank', 'noopener,noreferrer');
const subs = await apiExam.listSubmissions(examId);
setSubmissions(subs.data);
} catch (e: any) {
setErr(e?.message || 'Đẩy Git thất bại');
} finally {
setPublishingGitStudents(false);
}
};
const handlePublish = async () => {
setErr(''); setMsg('');
try {
@@ -845,9 +866,18 @@ export const ExamRoomWorkspace: React.FC<Props> = ({ examId, onBack }) => {
className="btn btn-secondary btn-sm"
disabled={publishingGit || !gh.connected}
onClick={publishToGit}
title={gh.connected ? 'Tạo repo + đẩy từng folder sinh viên lên GitHub' : 'Kết nối GitHub trong Tài khoản trước'}
title="1 repo — mỗi sinh viên một folder"
>
{publishingGit ? 'Đang đẩy Git...' : '🔗 Đẩy lên Git'}
{publishingGit ? 'Đang đẩy...' : '🔗 Git gộp (1 repo)'}
</button>
<button
type="button"
className="btn btn-secondary btn-sm"
disabled={publishingGitStudents || !gh.connected}
onClick={publishToGitStudents}
title="Mỗi sinh viên một repo GitHub riêng"
>
{publishingGitStudents ? 'Đang tạo repo...' : '👤 Git từng SV'}
</button>
{!gh.connected && (
<span className="exam-submissions-toolbar-hint">
@@ -858,7 +888,7 @@ export const ExamRoomWorkspace: React.FC<Props> = ({ examId, onBack }) => {
</span>
)}
<span className="exam-submissions-toolbar-hint">
ZIP gộp: mỗi sinh viên một folder giải nén chấm ngay.
<strong>Git gộp</strong>: 1 repo, folder từng SV · <strong>Git từng SV</strong>: mỗi người 1 repo.
</span>
</div>
)}
@@ -875,6 +905,7 @@ export const ExamRoomWorkspace: React.FC<Props> = ({ examId, onBack }) => {
<tr>
<th>Sinh viên</th>
<th>File</th>
<th>Git</th>
<th>Thời gian</th>
<th style={{ textAlign: 'right' }}>Tải</th>
</tr>
@@ -887,6 +918,11 @@ export const ExamRoomWorkspace: React.FC<Props> = ({ examId, onBack }) => {
<div style={{ fontSize: '0.75rem', color: 'var(--text-secondary)' }}>{s.studentCode}</div>
</td>
<td style={{ fontSize: '0.85rem' }}>{s.fileName}</td>
<td style={{ fontSize: '0.8rem' }}>
{s.gitPublishUrl ? (
<a href={s.gitPublishUrl} target="_blank" rel="noreferrer">Repo</a>
) : '—'}
</td>
<td style={{ fontSize: '0.8rem', color: 'var(--text-secondary)' }}>{fmtTime(s.createdAt)}</td>
<td style={{ textAlign: 'right' }}>
<button type="button" className="btn btn-secondary btn-sm" onClick={() => downloadSub(s.id, s.fileName)}>Tải</button>