fix(mobile): add error handling to store hydrate methods
- notes-store: wrap hydrate() and openNote() in try/catch to prevent isLoading stuck true - inbox-store: wrap hydrate() in try/catch to prevent isLoading stuck true on API failure - openNote falls back to cached list note when detail fetch fails
This commit is contained in:
parent
9d3ac06234
commit
c96c7855c6
@ -46,12 +46,16 @@ export const useInboxStore = create<InboxState>((set, get) => ({
|
||||
isLoading: false,
|
||||
async hydrate() {
|
||||
set({ isLoading: true });
|
||||
const [approvals, activity] = await Promise.all([listApprovalQueue(), listActivityFeed()]);
|
||||
set({
|
||||
approvals: approvals.map(toApprovalItem),
|
||||
activity: activity.map(toActivityItem),
|
||||
isLoading: false,
|
||||
});
|
||||
try {
|
||||
const [approvals, activity] = await Promise.all([listApprovalQueue(), listActivityFeed()]);
|
||||
set({
|
||||
approvals: approvals.map(toApprovalItem),
|
||||
activity: activity.map(toActivityItem),
|
||||
isLoading: false,
|
||||
});
|
||||
} catch {
|
||||
set({ isLoading: false });
|
||||
}
|
||||
},
|
||||
async approve(id: string, reviewNote?: string) {
|
||||
const current = get().approvals.find((item) => item.id === id);
|
||||
|
||||
@ -30,8 +30,12 @@ export const useNotesStore = create<NotesState>((set, get) => ({
|
||||
isLoading: false,
|
||||
async hydrate() {
|
||||
set({ isLoading: true });
|
||||
const notes = await listNotes();
|
||||
set({ notes, isLoading: false });
|
||||
try {
|
||||
const notes = await listNotes();
|
||||
set({ notes, isLoading: false });
|
||||
} catch {
|
||||
set({ isLoading: false });
|
||||
}
|
||||
},
|
||||
async openNote(id: string) {
|
||||
set({ isLoading: true });
|
||||
@ -41,8 +45,12 @@ export const useNotesStore = create<NotesState>((set, get) => ({
|
||||
return;
|
||||
}
|
||||
|
||||
const note = await getNote(id, current.workspaceId);
|
||||
set({ selectedNote: note, isLoading: false });
|
||||
try {
|
||||
const note = await getNote(id, current.workspaceId);
|
||||
set({ selectedNote: note, isLoading: false });
|
||||
} catch {
|
||||
set({ selectedNote: current, isLoading: false });
|
||||
}
|
||||
},
|
||||
async saveDraft(workspaceId: string | null, title: string, body: string) {
|
||||
if (!workspaceId) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user