Update index.html
1 file changed+15−1
index.html+15−1View file
| @@ -1389,10 +1389,24 @@ | ||
| async function syncPostKallax(endpoint, data) { | ||
| try { | ||
| - await apiFetch(`/api/${endpoint}`, { | ||
| + if (data._id && !data._id.startsWith('draft_')) { | ||
| + const updateRes = await apiFetch(`/api/${endpoint}/${data._id}`, { | ||
| + method: 'PUT', | ||
| + body: JSON.stringify(data) | ||
| + }); | ||
| + if (updateRes.ok) return await updateRes.json(); | ||
| + } | ||
| + const createRes = await apiFetch(`/api/${endpoint}`, { | ||
| method: 'POST', | ||
| body: JSON.stringify(data) | ||
| }); | ||
| + if (createRes.ok) { | ||
| + const resData = await createRes.json(); | ||
| + if (resData._id && data._id && data._id.startsWith('draft_')) { | ||
| + data._id = resData._id; | ||
| + } | ||
| + return resData; | ||
| + } | ||
| } catch (err) { | ||
| // Non-blocking fallback | ||
| } | ||