Store actions fetchAll: cleanup and only fetch if there's new data.

master
Tom Hacohen 5 years ago
parent 0dffd71276
commit c6eafadb8b

@ -170,17 +170,24 @@ export function fetchJournalEntries(etesync: CredentialsData, currentEntries: En
export function fetchAll(etesync: CredentialsData, currentEntries: EntriesType) { export function fetchAll(etesync: CredentialsData, currentEntries: EntriesType) {
return (dispatch: any) => { return (dispatch: any) => {
return dispatch(fetchListJournal(etesync)).then((journalsAction: Action<EteSync.Journal[]>) => { return new Promise<boolean>((resolve, reject) => {
const journals = journalsAction.payload; dispatch(fetchListJournal(etesync)).then((journalsAction: Action<EteSync.Journal[]>) => {
if (!journals || (journals.length === 0)) { const journals = journalsAction.payload;
return false; if (!journals || (journals.length === 0)) {
} resolve(false);
return;
}
journals.forEach((journal) => { Promise.all(journals.map((journal) => {
dispatch(fetchJournalEntries(etesync, currentEntries, journal)); const prevUid = currentEntries.get(journal.uid)?.value?.last(undefined)?.uid ?? null;
});
return true; // FIXME: expose it in a non-hacky way.
if (prevUid === (journal as any)._json.lastUid) {
return true;
}
return dispatch(fetchEntries(etesync, journal.uid, prevUid));
})).then(() => resolve(true)).catch(reject);
}).catch(reject);
}); });
}; };
} }

Loading…
Cancel
Save