Fix entries fetching by creating a fetchAll action.

master
Tom Hacohen 7 years ago
parent e38409203c
commit e48ebc5137

@ -15,7 +15,7 @@ import Pim from './Pim';
import * as EteSync from './api/EteSync';
import { store, JournalsType, EntriesType, StoreState, CredentialsData } from './store';
import { fetchJournals, fetchEntries } from './store/actions';
import { fetchAll } from './store/actions';
export interface SyncInfoJournal {
journal: EteSync.Journal;
@ -89,22 +89,7 @@ class SyncGate extends React.PureComponent {
}
componentDidMount() {
store.dispatch(fetchJournals(this.props.etesync));
}
componentWillReceiveProps(nextProps: PropsTypeInner) {
if (nextProps.journals.value && (this.props.journals.value !== nextProps.journals.value)) {
nextProps.journals.value.forEach((journal) => {
let prevUid: string | null = null;
const entries = this.props.entries.get(journal.uid);
if (entries && entries.value) {
const last = entries.value.last();
prevUid = (last) ? last.uid : null;
}
store.dispatch(fetchEntries(this.props.etesync, journal.uid, prevUid));
});
}
store.dispatch(fetchAll(this.props.etesync, this.props.entries));
}
render() {

@ -2,7 +2,7 @@ import { createActions } from 'redux-actions';
import * as EteSync from '../api/EteSync';
import { CredentialsData } from './';
import { CredentialsData, EntriesType } from './';
export const { fetchCredentials, logout } = createActions({
FETCH_CREDENTIALS: (username: string, password: string, encryptionPassword: string, server: string) => {
@ -67,3 +67,25 @@ export const { fetchEntries, createEntries } = createActions({
}
]
});
export function fetchAll(etesync: CredentialsData, currentEntries: EntriesType) {
return (dispatch: any) => {
dispatch(fetchJournals(etesync)).then((journalsAction: any) => {
const journals: Array<EteSync.Journal> = journalsAction.payload;
if (!journals) {
return;
}
journals.forEach((journal) => {
let prevUid: string | null = null;
const entries = currentEntries.get(journal.uid);
if (entries && entries.value) {
const last = entries.value.last();
prevUid = (last) ? last.uid : null;
}
dispatch(fetchEntries(etesync, journal.uid, prevUid));
});
});
};
}

Loading…
Cancel
Save