Make request types generic.

master
Tom Hacohen 7 years ago
parent 37aaebbbd8
commit fb660fc54c

@ -127,7 +127,7 @@ export class EteSyncContextInner extends React.Component {
render() {
if (((this.props.credentials.status === store.FetchStatus.Initial) &&
(this.props.credentials.credentials === null)) ||
(this.props.credentials.value === null)) ||
(this.props.credentials.status === store.FetchStatus.Failure)) {
let advancedSettings = null;
@ -222,7 +222,7 @@ export class EteSyncContextInner extends React.Component {
return (<div>Loading</div>);
}
let context = this.props.credentials.credentials as store.CredentialsData;
let context = this.props.credentials.value as store.CredentialsData;
return (
<div>

@ -19,17 +19,19 @@ export enum FetchStatus {
Success = 'SUCCESS',
}
export interface FetchType<T> {
status: FetchStatus;
value: T | null;
error?: Error;
}
export interface CredentialsData {
serviceApiUrl: string;
credentials: EteSync.Credentials;
encryptionKey: string;
}
export interface CredentialsType {
status: FetchStatus;
credentials: CredentialsData | null;
error?: Error;
}
export type CredentialsType = FetchType<CredentialsData>;
export interface StoreState {
fetchCount: number;
@ -66,7 +68,7 @@ export function logout() {
};
}
function credentials(state: CredentialsType = {status: FetchStatus.Initial, credentials: null},
function credentials(state: CredentialsType = {status: FetchStatus.Initial, value: null},
action: any): CredentialsType {
switch (action.type) {
case Actions.FETCH_CREDENTIALS:
@ -74,18 +76,18 @@ function credentials(state: CredentialsType = {status: FetchStatus.Initial, cred
case FetchStatus.Success:
return {
status: action.status,
credentials: action.credentials,
value: action.credentials,
};
case FetchStatus.Failure:
return {
status: action.status,
credentials: null,
value: null,
error: action.error,
};
default:
return {
status: action.status,
credentials: null,
value: null,
};
}
default:
@ -114,7 +116,7 @@ function fetchCount(state: number = 0, action: any) {
const credentialsPersistConfig = {
key: 'credentials',
storage: session,
whitelist: ['credentials'],
whitelist: ['value'],
};
const reducers = combineReducers({

Loading…
Cancel
Save