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) {
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));
}
}
}

@ -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) {
return {
value: null,
@ -49,9 +49,18 @@ function fetchTypeIdentityReducer(state: FetchType<any>, 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)
};
},
{}

Loading…
Cancel
Save