mirror of
https://github.com/velocitatem/cvfs.git
synced 2026-05-31 16:53:38 +00:00
feat: allow updating existing CV branches
This commit is contained in:
@@ -5,6 +5,7 @@ import CVTree from '@/components/cv/CVTree';
|
||||
import DiffViewer from '@/components/cv/DiffViewer';
|
||||
import Link from 'next/link';
|
||||
import {
|
||||
appendPatches,
|
||||
createBranch, createSubmission, deleteDocument, deleteVersion,
|
||||
Document, downloadVersionUrl,
|
||||
fetchDocuments, fetchSubmissions, fetchPublicAssetAnalytics, getPublicPdfUrl,
|
||||
@@ -488,6 +489,8 @@ export default function Dashboard() {
|
||||
const [pendingEdits, setPendingEdits] = useState<Map<string, { old_value: string; new_value: string }>>(new Map());
|
||||
const [sidebarOpen, setSidebarOpen] = useState(false);
|
||||
const [docHovered, setDocHovered] = useState<string | null>(null);
|
||||
const [applyLoading, setApplyLoading] = useState(false);
|
||||
const [applyError, setApplyError] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
fetchDocuments()
|
||||
@@ -501,6 +504,8 @@ export default function Dashboard() {
|
||||
|
||||
useEffect(() => {
|
||||
setPendingEdits(new Map());
|
||||
setApplyError('');
|
||||
setApplyLoading(false);
|
||||
}, [selectedVersionId]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -554,6 +559,21 @@ export default function Dashboard() {
|
||||
|
||||
const discardEdits = () => setPendingEdits(new Map());
|
||||
|
||||
const applyStagedEdits = async () => {
|
||||
if (!selectedVersionId || !stagedPatches.length) return;
|
||||
setApplyLoading(true);
|
||||
setApplyError('');
|
||||
try {
|
||||
await appendPatches(selectedVersionId, stagedPatches as Record<string, unknown>[]);
|
||||
await refreshDocs();
|
||||
setPendingEdits(new Map());
|
||||
} catch (e: unknown) {
|
||||
setApplyError(e instanceof Error ? e.message : 'Failed to apply edits');
|
||||
} finally {
|
||||
setApplyLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteDoc = async (docId: string) => {
|
||||
if (!confirm('Delete this CV and all its branches? This cannot be undone.')) return;
|
||||
try {
|
||||
@@ -809,13 +829,22 @@ export default function Dashboard() {
|
||||
<button
|
||||
className="btn btn-primary"
|
||||
style={{ fontSize: 12, padding: '3px 10px', background: '#92400e', borderColor: '#92400e' }}
|
||||
onClick={() => setModal('branch')}
|
||||
onClick={applyStagedEdits}
|
||||
disabled={applyLoading}
|
||||
>
|
||||
Save as branch
|
||||
{applyLoading ? 'Applying…' : 'Apply to branch'}
|
||||
</button>
|
||||
<button className="btn btn-ghost" style={{ fontSize: 12, padding: '3px 8px' }} onClick={() => setModal('branch')}>
|
||||
Save as new branch
|
||||
</button>
|
||||
<button className="btn btn-ghost" style={{ fontSize: 12, padding: '3px 8px' }} onClick={discardEdits}>
|
||||
Discard
|
||||
</button>
|
||||
{applyError && (
|
||||
<span style={{ color: '#b91c1c', fontSize: 12, flexBasis: '100%' }}>
|
||||
{applyError}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -133,6 +133,17 @@ export async function createBranch(
|
||||
});
|
||||
}
|
||||
|
||||
export async function appendPatches(
|
||||
versionId: string,
|
||||
patches: Record<string, unknown>[],
|
||||
): Promise<Version> {
|
||||
return req<Version>(`/api/v1/versions/${versionId}/patches`, {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ patches }),
|
||||
});
|
||||
}
|
||||
|
||||
export async function createSubmission(
|
||||
versionId: string,
|
||||
companyName: string,
|
||||
|
||||
Reference in New Issue
Block a user