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,
|
isLoading: false,
|
||||||
async hydrate() {
|
async hydrate() {
|
||||||
set({ isLoading: true });
|
set({ isLoading: true });
|
||||||
const [approvals, activity] = await Promise.all([listApprovalQueue(), listActivityFeed()]);
|
try {
|
||||||
set({
|
const [approvals, activity] = await Promise.all([listApprovalQueue(), listActivityFeed()]);
|
||||||
approvals: approvals.map(toApprovalItem),
|
set({
|
||||||
activity: activity.map(toActivityItem),
|
approvals: approvals.map(toApprovalItem),
|
||||||
isLoading: false,
|
activity: activity.map(toActivityItem),
|
||||||
});
|
isLoading: false,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
set({ isLoading: false });
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async approve(id: string, reviewNote?: string) {
|
async approve(id: string, reviewNote?: string) {
|
||||||
const current = get().approvals.find((item) => item.id === id);
|
const current = get().approvals.find((item) => item.id === id);
|
||||||
|
|||||||
@ -30,8 +30,12 @@ export const useNotesStore = create<NotesState>((set, get) => ({
|
|||||||
isLoading: false,
|
isLoading: false,
|
||||||
async hydrate() {
|
async hydrate() {
|
||||||
set({ isLoading: true });
|
set({ isLoading: true });
|
||||||
const notes = await listNotes();
|
try {
|
||||||
set({ notes, isLoading: false });
|
const notes = await listNotes();
|
||||||
|
set({ notes, isLoading: false });
|
||||||
|
} catch {
|
||||||
|
set({ isLoading: false });
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async openNote(id: string) {
|
async openNote(id: string) {
|
||||||
set({ isLoading: true });
|
set({ isLoading: true });
|
||||||
@ -41,8 +45,12 @@ export const useNotesStore = create<NotesState>((set, get) => ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const note = await getNote(id, current.workspaceId);
|
try {
|
||||||
set({ selectedNote: note, isLoading: false });
|
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) {
|
async saveDraft(workspaceId: string | null, title: string, body: string) {
|
||||||
if (!workspaceId) {
|
if (!workspaceId) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user