|
|
@ -22,7 +22,7 @@ import Pim from './Pim';
|
|
|
|
import * as EteSync from 'etesync';
|
|
|
|
import * as EteSync from 'etesync';
|
|
|
|
import { CURRENT_VERSION } from 'etesync';
|
|
|
|
import { CURRENT_VERSION } from 'etesync';
|
|
|
|
|
|
|
|
|
|
|
|
import { store, SettingsType, JournalsType, EntriesType, StoreState, CredentialsData, UserInfoType } from './store';
|
|
|
|
import { store, SettingsType, JournalsType, EntriesType, StoreState, CredentialsData, UserInfoData } from './store';
|
|
|
|
import { addJournal, fetchAll, fetchEntries, fetchUserInfo, createUserInfo } from './store/actions';
|
|
|
|
import { addJournal, fetchAll, fetchEntries, fetchUserInfo, createUserInfo } from './store/actions';
|
|
|
|
|
|
|
|
|
|
|
|
export interface SyncInfoJournal {
|
|
|
|
export interface SyncInfoJournal {
|
|
|
@ -42,7 +42,7 @@ type PropsTypeInner = RouteComponentProps<{}> & PropsType & {
|
|
|
|
settings: SettingsType;
|
|
|
|
settings: SettingsType;
|
|
|
|
journals: JournalsType;
|
|
|
|
journals: JournalsType;
|
|
|
|
entries: EntriesType;
|
|
|
|
entries: EntriesType;
|
|
|
|
userInfo: UserInfoType;
|
|
|
|
userInfo: UserInfoData;
|
|
|
|
fetchCount: number;
|
|
|
|
fetchCount: number;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -50,7 +50,7 @@ const syncInfoSelector = createSelector(
|
|
|
|
(props: PropsTypeInner) => props.etesync,
|
|
|
|
(props: PropsTypeInner) => props.etesync,
|
|
|
|
(props: PropsTypeInner) => props.journals.value!,
|
|
|
|
(props: PropsTypeInner) => props.journals.value!,
|
|
|
|
(props: PropsTypeInner) => props.entries,
|
|
|
|
(props: PropsTypeInner) => props.entries,
|
|
|
|
(props: PropsTypeInner) => props.userInfo.value!,
|
|
|
|
(props: PropsTypeInner) => props.userInfo,
|
|
|
|
(etesync, journals, entries, userInfo) => {
|
|
|
|
(etesync, journals, entries, userInfo) => {
|
|
|
|
const derived = etesync.encryptionKey;
|
|
|
|
const derived = etesync.encryptionKey;
|
|
|
|
const userInfoCryptoManager = userInfo.getCryptoManager(etesync.encryptionKey);
|
|
|
|
const userInfoCryptoManager = userInfo.getCryptoManager(etesync.encryptionKey);
|
|
|
@ -132,10 +132,14 @@ class SyncGate extends React.PureComponent<PropsTypeInner> {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const sync = () => {
|
|
|
|
if (this.props.userInfo) {
|
|
|
|
if (this.props.userInfo.value) {
|
|
|
|
syncAll();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const fetching = fetchUserInfo(this.props.etesync, me);
|
|
|
|
|
|
|
|
fetching.payload?.then(() => {
|
|
|
|
|
|
|
|
store.dispatch(fetching);
|
|
|
|
syncAll();
|
|
|
|
syncAll();
|
|
|
|
} else {
|
|
|
|
}).catch(() => {
|
|
|
|
const userInfo = new EteSync.UserInfo(me, CURRENT_VERSION);
|
|
|
|
const userInfo = new EteSync.UserInfo(me, CURRENT_VERSION);
|
|
|
|
const keyPair = EteSync.AsymmetricCryptoManager.generateKeyPair();
|
|
|
|
const keyPair = EteSync.AsymmetricCryptoManager.generateKeyPair();
|
|
|
|
const cryptoManager = userInfo.getCryptoManager(this.props.etesync.encryptionKey);
|
|
|
|
const cryptoManager = userInfo.getCryptoManager(this.props.etesync.encryptionKey);
|
|
|
@ -143,14 +147,7 @@ class SyncGate extends React.PureComponent<PropsTypeInner> {
|
|
|
|
userInfo.setKeyPair(cryptoManager, keyPair);
|
|
|
|
userInfo.setKeyPair(cryptoManager, keyPair);
|
|
|
|
|
|
|
|
|
|
|
|
store.dispatch<any>(createUserInfo(this.props.etesync, userInfo)).then(syncAll);
|
|
|
|
store.dispatch<any>(createUserInfo(this.props.etesync, userInfo)).then(syncAll);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.props.userInfo.value) {
|
|
|
|
|
|
|
|
syncAll();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const fetching = store.dispatch(fetchUserInfo(this.props.etesync, me)) as any;
|
|
|
|
|
|
|
|
fetching.then(sync).catch(() => sync());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -158,9 +155,7 @@ class SyncGate extends React.PureComponent<PropsTypeInner> {
|
|
|
|
const entryArrays = this.props.entries;
|
|
|
|
const entryArrays = this.props.entries;
|
|
|
|
const journals = this.props.journals.value;
|
|
|
|
const journals = this.props.journals.value;
|
|
|
|
|
|
|
|
|
|
|
|
if (this.props.userInfo.error) {
|
|
|
|
if (this.props.journals.error) {
|
|
|
|
return <PrettyError error={this.props.userInfo.error} />;
|
|
|
|
|
|
|
|
} else if (this.props.journals.error) {
|
|
|
|
|
|
|
|
return <PrettyError error={this.props.journals.error} />;
|
|
|
|
return <PrettyError error={this.props.journals.error} />;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
const errors: Array<{journal: string, error: Error}> = [];
|
|
|
|
const errors: Array<{journal: string, error: Error}> = [];
|
|
|
@ -179,7 +174,7 @@ class SyncGate extends React.PureComponent<PropsTypeInner> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((this.props.userInfo.value === null) || (journals === null) ||
|
|
|
|
if ((this.props.userInfo === null) || (journals === null) ||
|
|
|
|
((this.props.fetchCount > 0) &&
|
|
|
|
((this.props.fetchCount > 0) &&
|
|
|
|
((entryArrays.size === 0) || !entryArrays.every((x: any) => (x.value !== null))))
|
|
|
|
((entryArrays.size === 0) || !entryArrays.every((x: any) => (x.value !== null))))
|
|
|
|
) {
|
|
|
|
) {
|
|
|
@ -208,7 +203,7 @@ class SyncGate extends React.PureComponent<PropsTypeInner> {
|
|
|
|
<AppBarOverride title="EteSync" />
|
|
|
|
<AppBarOverride title="EteSync" />
|
|
|
|
<PimRouter
|
|
|
|
<PimRouter
|
|
|
|
etesync={this.props.etesync}
|
|
|
|
etesync={this.props.etesync}
|
|
|
|
userInfo={this.props.userInfo.value!}
|
|
|
|
userInfo={this.props.userInfo}
|
|
|
|
syncInfo={journalMap}
|
|
|
|
syncInfo={journalMap}
|
|
|
|
history={history}
|
|
|
|
history={history}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
@ -220,7 +215,7 @@ class SyncGate extends React.PureComponent<PropsTypeInner> {
|
|
|
|
render={({ location, history }) => (
|
|
|
|
render={({ location, history }) => (
|
|
|
|
<Journals
|
|
|
|
<Journals
|
|
|
|
etesync={this.props.etesync}
|
|
|
|
etesync={this.props.etesync}
|
|
|
|
userInfo={this.props.userInfo.value!}
|
|
|
|
userInfo={this.props.userInfo}
|
|
|
|
syncInfo={journalMap}
|
|
|
|
syncInfo={journalMap}
|
|
|
|
journals={journals}
|
|
|
|
journals={journals}
|
|
|
|
location={location}
|
|
|
|
location={location}
|
|
|
@ -243,7 +238,7 @@ class SyncGate extends React.PureComponent<PropsTypeInner> {
|
|
|
|
render={() => (
|
|
|
|
render={() => (
|
|
|
|
<Debug
|
|
|
|
<Debug
|
|
|
|
etesync={this.props.etesync}
|
|
|
|
etesync={this.props.etesync}
|
|
|
|
userInfo={this.props.userInfo.value!}
|
|
|
|
userInfo={this.props.userInfo}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|