Skip to content

Commit 6ec7dd5

Browse files
pass entry state to the upload panel so we can save an upload without having to check for the entry id everytime
1 parent 353432f commit 6ec7dd5

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

frontend/src/components/MainApp.svelte

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ SPDX-License-Identifier: GPL-3.0-or-later
132132
}
133133
}
134134
135+
// use for Uploads to check the entry Id. Pass it to UploadsPAnel so that we dont need to check and warn
136+
async function ensureEntrySaved(): Promise<number | null> {
137+
if (!currentEntryId) await saveOrUpdateEntry();
138+
return currentEntryId;
139+
}
140+
135141
async function deleteEntry(id: number, title: string): Promise<void> {
136142
alert = null;
137143
const confirmed = window.confirm(`Delete "${title}"? This cannot be undone.`);
@@ -348,6 +354,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
348354
<UploadsPanel
349355
{profileUuid}
350356
entryId={currentEntryId}
357+
{ensureEntrySaved}
351358
onAlert={(nextAlert) => alert = nextAlert}
352359
/>
353360
</form>

frontend/src/components/Uploads/UploadsPanel.svelte

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
type Props = {
1414
profileUuid: string;
1515
entryId: number | null;
16+
ensureEntrySaved: () => Promise<number | null>;
1617
onAlert: (alert: AlertState | null) => void;
1718
};
1819
19-
let {profileUuid, onAlert, entryId}: Props = $props();
20+
let {profileUuid, entryId, ensureEntrySaved, onAlert}: Props = $props();
2021
2122
let uploads = $state<main.StoredUpload[]>([]);
2223
let loading = $state(false);
@@ -38,16 +39,13 @@
3839
}
3940
4041
async function importUpload(): Promise<void> {
41-
// uploads need to be attached to an entry. Before clicking save, the entry doesn't have an id yet.
42-
if (!entryId) {
43-
onAlert({type: 'warning', message: 'Save the entry before adding the first upload.'});
44-
return;
45-
}
42+
const uploadEntryId = await ensureEntrySaved();
43+
if (!uploadEntryId) return;
4644
4745
try {
4846
const path = await SelectFile();
4947
if (!path) return;
50-
const upload = await ImportUpload(profileUuid, entryId, path);
48+
const upload = await ImportUpload(profileUuid, uploadEntryId, path);
5149
onAlert({type: 'success', message: `Imported ${upload.realName} ✔`});
5250
await refreshUploads();
5351
} catch (e: unknown) {

0 commit comments

Comments
 (0)