fix(lists): add items offline via the outbox; recognisable input field
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 1m34s
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:
1 parent
ab97638361
commit
28ebbe7263
9 files changed
+152
-21
No files matched your search
@@ -154,6 +154,43 @@ export function enqueue(method: OutboxEntry['method'], path: string, body: Recor
|
||||
|
||||
export const outboxCount = () => getOutbox().length;
|
||||
|
||||
/** Changes the body of a queued entry (e.g. the quantity of a list item added offline). */
|
||||
export function updateQueued(entryId: string, body: Record<string, unknown>): boolean {
|
||||
const entries = getOutbox();
|
||||
const entry = entries.find((e) => e.id === entryId);
|
||||
if (!entry) return false;
|
||||
entry.body = { ...entry.body, ...body };
|
||||
saveOutbox(entries);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Removes a queued entry that is no longer wanted (e.g. a list item added and deleted while offline). */
|
||||
export function dropQueued(entryId: string): boolean {
|
||||
const entries = getOutbox();
|
||||
const rest = entries.filter((e) => e.id !== entryId);
|
||||
if (rest.length === entries.length) return false;
|
||||
saveOutbox(rest);
|
||||
return true;
|
||||
}
|
||||
|
||||
// List items added offline: a stand-in id until the server knows them, derived from the outbox entry
|
||||
export const OFFLINE_ITEM_PREFIX = 'itm_offline_';
|
||||
const LIST_ITEMS_PATH = /^\/api\/v1\/lists\/([^/]+)\/items$/;
|
||||
|
||||
/** List items still waiting in the outbox, as stand-ins for the list view (also after a reload). */
|
||||
export function pendingListItems(): { listId: string; id: string; content: string; category: string; quantity: string; createdAt: string }[] {
|
||||
return getOutbox()
|
||||
.filter((e) => e.method === 'POST' && LIST_ITEMS_PATH.test(e.path))
|
||||
.map((e) => ({
|
||||
listId: (e.path.match(LIST_ITEMS_PATH) as RegExpMatchArray)[1],
|
||||
id: OFFLINE_ITEM_PREFIX + e.id,
|
||||
content: String(e.body.content || ''),
|
||||
category: String(e.body.category || ''),
|
||||
quantity: String(e.body.quantity || ''),
|
||||
createdAt: e.createdAt,
|
||||
}));
|
||||
}
|
||||
|
||||
let flushing: Promise<number> | null = null;
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user