Use the last entry id when fetching entries from server.

master
Tom Hacohen 7 years ago
parent 4e9317a1ae
commit 5dacc4c013

@ -47,7 +47,13 @@ class SyncGate extends React.Component {
componentWillReceiveProps(nextProps: PropsTypeInner) { componentWillReceiveProps(nextProps: PropsTypeInner) {
if (nextProps.journals.value && (this.props.journals.value !== nextProps.journals.value)) { if (nextProps.journals.value && (this.props.journals.value !== nextProps.journals.value)) {
for (const journal of 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));
} }
} }
} }

@ -41,7 +41,7 @@ export interface StoreState {
}; };
} }
function fetchTypeIdentityReducer(state: FetchType<any>, action: any) { function fetchTypeIdentityReducer(state: FetchType<any>, action: any, extend: boolean = false) {
if (action.error) { if (action.error) {
return { return {
value: null, value: null,
@ -49,9 +49,18 @@ function fetchTypeIdentityReducer(state: FetchType<any>, action: any) {
}; };
} else { } else {
const fetching = (action.payload === undefined) ? true : undefined; 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 { return {
fetching, fetching,
value: (action.payload === undefined) ? null : action.payload, value,
}; };
} }
} }
@ -118,8 +127,10 @@ const credentials = handleActions(
const entries = handleAction( const entries = handleAction(
fetchEntries, fetchEntries,
(state: EntriesType, action: any) => { (state: EntriesType, action: any) => {
const prevState = state[action.meta.journal];
const extend = action.meta.prevUid != null;
return { ...state, return { ...state,
[action.meta.journal]: fetchTypeIdentityReducer(state[action.meta.journal], action) [action.meta.journal]: fetchTypeIdentityReducer(prevState, action, extend)
}; };
}, },
{} {}

Loading…
Cancel
Save