fix(lists): add items offline via the outbox; recognisable input field
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 1m34s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sandrodachandClaude Opus 5.5 committed 2026-10-31 15:07:19 +01:00
1 parent ab97638361
commit 28ebbe7263
9 files changed
+152 -21

No files matched your search

+34 -4
View File
@@ -52,6 +52,9 @@ import {
clearOfflineData,
enqueue,
flushOutbox,
dropQueued,
updateQueued,
OFFLINE_ITEM_PREFIX,
} from './offline';
const TOKEN_STORAGE_KEY = 'mindsift_jwt_token';
@@ -961,13 +964,32 @@ export const api = {
},
async createListItem(listId: string, content: string, category = '', quantity = ''): Promise<ListItem> {
return request<ListItem>(`/api/v1/lists/${listId}/items`, {
method: 'POST',
body: JSON.stringify({ content, category, quantity }),
});
const path = `/api/v1/lists/${listId}/items`;
try {
return await request<ListItem>(path, { method: 'POST', body: JSON.stringify({ content, category, quantity }) });
} catch (err) {
if (!(err instanceof OfflineError)) throw err;
// Kept in the outbox and sent when the connection is back; until then a stand-in in the list
const entry = enqueue('POST', path, { content, category, quantity });
return {
id: OFFLINE_ITEM_PREFIX + entry.id,
listId,
content,
category,
quantity,
isCompleted: false,
sortOrder: 0,
createdAt: entry.createdAt,
} as ListItem;
}
},
async toggleListItem(listId: string, itemId: string, isCompleted?: boolean): Promise<ListItem> {
// Added offline and checked off before it was sent: nothing left to send
if (itemId.startsWith(OFFLINE_ITEM_PREFIX) && isCompleted) {
dropQueued(itemId.slice(OFFLINE_ITEM_PREFIX.length));
return { id: itemId, listId, isCompleted: true } as ListItem;
}
try {
return await request<ListItem>(`/api/v1/lists/${listId}/items/${itemId}`, {
method: 'PATCH',
@@ -985,6 +1007,10 @@ export const api = {
itemId: string,
payload: { content?: string; category?: string; quantity?: string }
): Promise<ListItem> {
if (itemId.startsWith(OFFLINE_ITEM_PREFIX)) {
updateQueued(itemId.slice(OFFLINE_ITEM_PREFIX.length), payload);
return { id: itemId, listId, ...payload } as ListItem;
}
return request<ListItem>(`/api/v1/lists/${listId}/items/${itemId}`, {
method: 'PUT',
body: JSON.stringify(payload),
@@ -992,6 +1018,10 @@ export const api = {
},
async deleteListItem(listId: string, itemId: string): Promise<void> {
if (itemId.startsWith(OFFLINE_ITEM_PREFIX)) {
dropQueued(itemId.slice(OFFLINE_ITEM_PREFIX.length));
return;
}
await request(`/api/v1/lists/${listId}/items/${itemId}`, { method: 'DELETE' });
},