Add create modal for words and pictures tables

- + Button in TableView for tables with a create form (words, pictures)
- Words: form with titel_de/en/sv + difficulty_level → POST /words
- Pictures: design field + image uploader → POST /pictures then POST /pictures/:id/upload
- Image drag-drop area with preview before upload, sends multipart to Hetzner via API
- New record prepended to table on success
- apiPost + apiUpload helpers added to api.js

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-21 22:17:55 +02:00
parent e6c86a97fc
commit a8ff541117
3 changed files with 249 additions and 0 deletions

View File

@@ -62,6 +62,29 @@ export async function apiPatch(endpoint, id, body) {
});
}
export async function apiPost(endpoint, body) {
return apiFetch(endpoint, {
method: 'POST',
body: JSON.stringify(body),
});
}
export async function apiFetchOne(path) {
return apiFetch(path);
}
// Multipart upload — does NOT set Content-Type (browser sets boundary automatically)
export async function apiUpload(path, formData) {
const token = getToken();
const res = await fetch(`${API_URL}${path}`, {
method: 'POST',
headers: token ? { Authorization: `Bearer ${token}` } : {},
body: formData,
});
if (res.status === 401) { logout(); window.location.href = '/login'; return; }
if (!res.ok) {
const err = await res.json().catch(() => ({}));
throw new Error(err.error || `HTTP ${res.status}`);
}
return res.json();
}