feat(backlog): save only the changed fields

This commit is contained in:
lobo committed 2026-09-30 07:57:52 +02:00
1 parent 9ddc50f819
commit 628920a006
6 files changed
+133 -83

No files matched your search

+15 -6
View File
@@ -14,15 +14,24 @@ export const toBacklogRequest = ({status, rating, notes, priority}) => ({
});
/**
* PUT /api/library/games/{appid}/backlog. The caller handles the response status.
*
* @param entry a backlog entry in request form, see toBacklogRequest
* The fields of `form` that differ from `saved`, in request form: what saveBacklogEntry sends.
*/
export const saveBacklogEntry = (appid, entry) =>
export const changedFields = (saved, form) => {
const before = toBacklogRequest(saved);
return Object.fromEntries(Object.entries(toBacklogRequest(form)).filter(([field, value]) => value !== before[field]));
};
/**
* PATCH /api/library/games/{appid}/backlog with only the changed fields, so an older tab keeps the newer ones; null
* clears a field. Answers the whole entry. The caller handles the response status.
*
* @param changes see changedFields
*/
export const saveBacklogEntry = (appid, changes) =>
apiFetch(`${import.meta.env.VITE_CORE_API_URL}/api/library/games/${appid}/backlog`, {
method: 'PUT',
method: 'PATCH',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(entry),
body: JSON.stringify(changes),
});
/**