Simplify the fetch credentials structure to not use the fetch record.
It was thrashing the redux store. We made the same change for the ios app.master
parent
5301b546df
commit
118d26ce83
@ -0,0 +1,44 @@
|
|||||||
|
import { shallowEqual, useSelector } from 'react-redux';
|
||||||
|
import { createSelector } from 'reselect';
|
||||||
|
|
||||||
|
import * as store from '../store';
|
||||||
|
|
||||||
|
export const remoteCredentialsSelector = createSelector(
|
||||||
|
(state: store.StoreState) => state.credentials.credentials,
|
||||||
|
(state: store.StoreState) => state.credentials.serviceApiUrl,
|
||||||
|
(credentials, serviceApiUrl) => {
|
||||||
|
if (!credentials) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ret: store.CredentialsDataRemote = {
|
||||||
|
credentials,
|
||||||
|
serviceApiUrl,
|
||||||
|
};
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export function useRemoteCredentials() {
|
||||||
|
return useSelector(remoteCredentialsSelector, shallowEqual);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const credentialsSelector = createSelector(
|
||||||
|
(state: store.StoreState) => remoteCredentialsSelector(state),
|
||||||
|
(state: store.StoreState) => state.encryptionKey.key,
|
||||||
|
(remoteCredentials, encryptionKey) => {
|
||||||
|
if (!remoteCredentials || !encryptionKey) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ret: store.CredentialsData = {
|
||||||
|
...remoteCredentials,
|
||||||
|
encryptionKey,
|
||||||
|
};
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export function useCredentials() {
|
||||||
|
return useSelector(credentialsSelector, shallowEqual);
|
||||||
|
}
|
Loading…
Reference in New Issue