diff --git a/src/EteSyncContext.tsx b/src/EteSyncContext.tsx index f152cc1..a0ed1eb 100644 --- a/src/EteSyncContext.tsx +++ b/src/EteSyncContext.tsx @@ -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 (
Loading
); } - let context = this.props.credentials.credentials as store.CredentialsData; + let context = this.props.credentials.value as store.CredentialsData; return (
diff --git a/src/store.tsx b/src/store.tsx index 5f5f9ea..011dbc0 100644 --- a/src/store.tsx +++ b/src/store.tsx @@ -19,17 +19,19 @@ export enum FetchStatus { Success = 'SUCCESS', } +export interface FetchType { + 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; 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({