|
|
@ -4,6 +4,8 @@ import session from 'redux-persist/lib/storage/session';
|
|
|
|
import thunkMiddleware from 'redux-thunk';
|
|
|
|
import thunkMiddleware from 'redux-thunk';
|
|
|
|
import { createLogger } from 'redux-logger';
|
|
|
|
import { createLogger } from 'redux-logger';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import promiseMiddleware from './promise-middleware';
|
|
|
|
|
|
|
|
|
|
|
|
import * as EteSync from './api/EteSync';
|
|
|
|
import * as EteSync from './api/EteSync';
|
|
|
|
|
|
|
|
|
|
|
|
const loggerMiddleware = createLogger();
|
|
|
|
const loggerMiddleware = createLogger();
|
|
|
@ -101,91 +103,26 @@ export function fetchCredentials(username: string, password: string, encryptionP
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function journalsSuccess(value: JournalsData) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
type: Actions.FETCH_JOURNALS,
|
|
|
|
|
|
|
|
status: FetchStatus.Success,
|
|
|
|
|
|
|
|
journals: value,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function journalsRequest() {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
type: Actions.FETCH_JOURNALS,
|
|
|
|
|
|
|
|
status: FetchStatus.Request,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function journalsFailure(error: Error) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
type: Actions.FETCH_JOURNALS,
|
|
|
|
|
|
|
|
status: FetchStatus.Failure,
|
|
|
|
|
|
|
|
error,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function fetchJournals(etesync: CredentialsData) {
|
|
|
|
export function fetchJournals(etesync: CredentialsData) {
|
|
|
|
const creds = etesync.credentials;
|
|
|
|
const creds = etesync.credentials;
|
|
|
|
const apiBase = etesync.serviceApiUrl;
|
|
|
|
const apiBase = etesync.serviceApiUrl;
|
|
|
|
|
|
|
|
let journalManager = new EteSync.JournalManager(creds, apiBase);
|
|
|
|
|
|
|
|
|
|
|
|
return (dispatch: any) => {
|
|
|
|
|
|
|
|
dispatch(journalsRequest());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let journalManager = new EteSync.JournalManager(creds, apiBase);
|
|
|
|
|
|
|
|
journalManager.list().then(
|
|
|
|
|
|
|
|
(vals) => {
|
|
|
|
|
|
|
|
dispatch(journalsSuccess(vals));
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
(error) => {
|
|
|
|
|
|
|
|
dispatch(journalsFailure(error));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function entriesSuccess(journal: string, value: EntriesData) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
type: Actions.FETCH_ENTRIES,
|
|
|
|
|
|
|
|
status: FetchStatus.Success,
|
|
|
|
|
|
|
|
entries: value,
|
|
|
|
|
|
|
|
journal,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function entriesRequest(journal: string) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
type: Actions.FETCH_ENTRIES,
|
|
|
|
type: Actions.FETCH_JOURNALS,
|
|
|
|
status: FetchStatus.Request,
|
|
|
|
payload: journalManager.list(),
|
|
|
|
journal,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function entriesFailure(journal: string, error: Error) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
type: Actions.FETCH_ENTRIES,
|
|
|
|
|
|
|
|
status: FetchStatus.Failure,
|
|
|
|
|
|
|
|
journal,
|
|
|
|
|
|
|
|
error,
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function fetchEntries(etesync: CredentialsData, journalUid: string) {
|
|
|
|
export function fetchEntries(etesync: CredentialsData, journalUid: string, prevUid: string | null) {
|
|
|
|
const creds = etesync.credentials;
|
|
|
|
const creds = etesync.credentials;
|
|
|
|
const apiBase = etesync.serviceApiUrl;
|
|
|
|
const apiBase = etesync.serviceApiUrl;
|
|
|
|
|
|
|
|
let entryManager = new EteSync.EntryManager(creds, apiBase, journalUid);
|
|
|
|
|
|
|
|
|
|
|
|
return (dispatch: any) => {
|
|
|
|
return {
|
|
|
|
const prevUid = null;
|
|
|
|
type: Actions.FETCH_ENTRIES,
|
|
|
|
dispatch(entriesRequest(journalUid));
|
|
|
|
payload: entryManager.list(prevUid),
|
|
|
|
|
|
|
|
meta: { journal: journalUid, prevUid },
|
|
|
|
let entryManager = new EteSync.EntryManager(creds, apiBase, journalUid);
|
|
|
|
|
|
|
|
entryManager.list(prevUid).then(
|
|
|
|
|
|
|
|
(vals) => {
|
|
|
|
|
|
|
|
dispatch(entriesSuccess(journalUid, vals));
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
(error) => {
|
|
|
|
|
|
|
|
dispatch(entriesFailure(journalUid, error));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -226,23 +163,15 @@ function credentials(state: CredentialsType = {status: FetchStatus.Initial, valu
|
|
|
|
function journals(state: JournalsType = {status: FetchStatus.Initial, value: null}, action: any) {
|
|
|
|
function journals(state: JournalsType = {status: FetchStatus.Initial, value: null}, action: any) {
|
|
|
|
switch (action.type) {
|
|
|
|
switch (action.type) {
|
|
|
|
case Actions.FETCH_JOURNALS:
|
|
|
|
case Actions.FETCH_JOURNALS:
|
|
|
|
switch (action.status) {
|
|
|
|
if (action.error) {
|
|
|
|
case FetchStatus.Success:
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
value: null,
|
|
|
|
status: action.status,
|
|
|
|
error: action.payload,
|
|
|
|
value: action.journals,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
case FetchStatus.Failure:
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
value: (action.payload === undefined) ? null : action.payload,
|
|
|
|
status: action.status,
|
|
|
|
};
|
|
|
|
value: null,
|
|
|
|
|
|
|
|
error: action.error,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
status: action.status,
|
|
|
|
|
|
|
|
value: null,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
return state;
|
|
|
@ -252,29 +181,19 @@ function journals(state: JournalsType = {status: FetchStatus.Initial, value: nul
|
|
|
|
function entries(state: EntriesType = {}, action: any) {
|
|
|
|
function entries(state: EntriesType = {}, action: any) {
|
|
|
|
switch (action.type) {
|
|
|
|
switch (action.type) {
|
|
|
|
case Actions.FETCH_ENTRIES:
|
|
|
|
case Actions.FETCH_ENTRIES:
|
|
|
|
switch (action.status) {
|
|
|
|
if (action.error) {
|
|
|
|
case FetchStatus.Success:
|
|
|
|
return { ...state,
|
|
|
|
return { ...state,
|
|
|
|
[action.meta.journal]: {
|
|
|
|
[action.journal]: {
|
|
|
|
|
|
|
|
status: action.status,
|
|
|
|
|
|
|
|
value: action.entries,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
case FetchStatus.Failure:
|
|
|
|
|
|
|
|
return { ...state,
|
|
|
|
|
|
|
|
[action.journal]: {
|
|
|
|
|
|
|
|
status: action.status,
|
|
|
|
|
|
|
|
value: null,
|
|
|
|
value: null,
|
|
|
|
error: action.error,
|
|
|
|
error: action.payload,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
default:
|
|
|
|
} else {
|
|
|
|
return { ...state,
|
|
|
|
return { ...state,
|
|
|
|
[action.journal]: {
|
|
|
|
[action.meta.journal]: {
|
|
|
|
status: action.status,
|
|
|
|
value: (action.payload === undefined) ? null : action.payload,
|
|
|
|
value: null,
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
return state;
|
|
|
@ -282,18 +201,14 @@ function entries(state: EntriesType = {}, action: any) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function fetchCount(state: number = 0, action: any) {
|
|
|
|
function fetchCount(state: number = 0, action: any) {
|
|
|
|
if ('status' in action) {
|
|
|
|
switch (action.type) {
|
|
|
|
switch (action.status) {
|
|
|
|
case Actions.FETCH_JOURNALS:
|
|
|
|
case FetchStatus.Request:
|
|
|
|
case Actions.FETCH_ENTRIES:
|
|
|
|
|
|
|
|
if (action.payload === undefined) {
|
|
|
|
return state + 1;
|
|
|
|
return state + 1;
|
|
|
|
case FetchStatus.Success:
|
|
|
|
} else {
|
|
|
|
case FetchStatus.Failure:
|
|
|
|
|
|
|
|
return state - 1;
|
|
|
|
return state - 1;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (action.type) {
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -318,6 +233,7 @@ export const store = createStore(
|
|
|
|
reducers,
|
|
|
|
reducers,
|
|
|
|
applyMiddleware(
|
|
|
|
applyMiddleware(
|
|
|
|
thunkMiddleware,
|
|
|
|
thunkMiddleware,
|
|
|
|
|
|
|
|
promiseMiddleware,
|
|
|
|
loggerMiddleware
|
|
|
|
loggerMiddleware
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
);
|
|
|
|