diff --git a/src/SyncGate.tsx b/src/SyncGate.tsx index 0733209..6ca83a1 100644 --- a/src/SyncGate.tsx +++ b/src/SyncGate.tsx @@ -47,7 +47,13 @@ class SyncGate extends React.Component { componentWillReceiveProps(nextProps: PropsTypeInner) { if (nextProps.journals.value && (this.props.journals.value !== nextProps.journals.value)) { for (const journal of nextProps.journals.value) { - store.dispatch(fetchEntries(this.props.etesync, journal.uid, null)); + let prevUid: string | null = null; + const entries = this.props.entries[journal.uid]; + if (entries && entries.value && (entries.value.length > 0)) { + prevUid = entries.value[entries.value.length - 1].uid; + } + + store.dispatch(fetchEntries(this.props.etesync, journal.uid, prevUid)); } } } diff --git a/src/store.tsx b/src/store.tsx index f33b17e..6740f55 100644 --- a/src/store.tsx +++ b/src/store.tsx @@ -41,7 +41,7 @@ export interface StoreState { }; } -function fetchTypeIdentityReducer(state: FetchType, action: any) { +function fetchTypeIdentityReducer(state: FetchType, action: any, extend: boolean = false) { if (action.error) { return { value: null, @@ -49,9 +49,18 @@ function fetchTypeIdentityReducer(state: FetchType, action: any) { }; } else { const fetching = (action.payload === undefined) ? true : undefined; + const payload = (action.payload === undefined) ? null : action.payload; + let value = state.value; + if (extend && (value !== null)) { + if (payload !== null) { + value = value.concat(payload); + } + } else { + value = payload; + } return { fetching, - value: (action.payload === undefined) ? null : action.payload, + value, }; } } @@ -118,8 +127,10 @@ const credentials = handleActions( const entries = handleAction( fetchEntries, (state: EntriesType, action: any) => { + const prevState = state[action.meta.journal]; + const extend = action.meta.prevUid != null; return { ...state, - [action.meta.journal]: fetchTypeIdentityReducer(state[action.meta.journal], action) + [action.meta.journal]: fetchTypeIdentityReducer(prevState, action, extend) }; }, {}