From f26af1e1ace66fabc1719e27242af534e795699e Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 25 Feb 2019 23:05:04 +0000 Subject: [PATCH] Journal actions: split fetchAll and fetching journal entries. --- src/store/actions.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/store/actions.ts b/src/store/actions.ts index 5965a13..6dedefa 100644 --- a/src/store/actions.ts +++ b/src/store/actions.ts @@ -147,6 +147,20 @@ export const createUserInfo = createAction( } ); +export function fetchJournalEntries(etesync: CredentialsData, currentEntries: EntriesType, journal: EteSync.Journal) { + return (dispatch: any) => { + let prevUid: string | null = null; + const entries = currentEntries.get(journal.uid); + if (entries && entries.value) { + const last = entries.value.last() as EteSync.Entry; + prevUid = (last) ? last.uid : null; + } + + return dispatch(fetchEntries(etesync, journal.uid, prevUid)); + }; +} + + export function fetchAll(etesync: CredentialsData, currentEntries: EntriesType) { return (dispatch: any) => { return dispatch(fetchListJournal(etesync)).then((journalsAction: any) => { @@ -156,14 +170,7 @@ export function fetchAll(etesync: CredentialsData, currentEntries: EntriesType) } journals.forEach((journal, uid) => { - let prevUid: string | null = null; - const entries = currentEntries.get(journal.uid); - if (entries && entries.value) { - const last = entries.value.last() as EteSync.Entry; - prevUid = (last) ? last.uid : null; - } - - dispatch(fetchEntries(etesync, journal.uid, prevUid)); + dispatch(fetchJournalEntries(etesync, currentEntries, journal)); }); return true;