Merge branch 'refactor-getOtherAccounts' into 'develop'

Refactor getOtherAccounts selector

See merge request soapbox-pub/soapbox-fe!599
error-boundary-browser-info
Alex Gleason 2021-07-10 10:00:48 +00:00
commit 258889c492
3 zmienionych plików z 16 dodań i 22 usunięć

Wyświetl plik

@ -53,17 +53,13 @@ const makeMapStateToProps = () => {
const me = state.get('me'); const me = state.get('me');
const soapbox = getSoapboxConfig(state); const soapbox = getSoapboxConfig(state);
const accounts = state.get('accounts');
const authUsers = state.getIn(['auth', 'users']);
const otherAccounts = getOtherAccounts(accounts, authUsers, me);
return { return {
account: getAccount(state, me), account: getAccount(state, me),
sidebarOpen: state.get('sidebar').sidebarOpen, sidebarOpen: state.get('sidebar').sidebarOpen,
donateUrl: state.getIn(['patron', 'instance', 'url']), donateUrl: state.getIn(['patron', 'instance', 'url']),
hasCrypto: typeof soapbox.getIn(['cryptoAddresses', 0, 'ticker']) === 'string', hasCrypto: typeof soapbox.getIn(['cryptoAddresses', 0, 'ticker']) === 'string',
isStaff: isStaff(state.getIn(['accounts', me])), isStaff: isStaff(state.getIn(['accounts', me])),
otherAccounts, otherAccounts: getOtherAccounts(state),
}; };
}; };

Wyświetl plik

@ -24,13 +24,9 @@ const makeMapStateToProps = () => {
const mapStateToProps = state => { const mapStateToProps = state => {
const me = state.get('me'); const me = state.get('me');
const accounts = state.get('accounts');
const authUsers = state.getIn(['auth', 'users']);
const otherAccounts = getOtherAccounts(accounts, authUsers, me);
return { return {
account: state.getIn(['accounts', me]), account: state.getIn(['accounts', me]),
otherAccounts, otherAccounts: getOtherAccounts(state),
isStaff: isStaff(state.getIn(['accounts', me])), isStaff: isStaff(state.getIn(['accounts', me])),
}; };
}; };

Wyświetl plik

@ -197,16 +197,18 @@ export const makeGetReport = () => {
}; };
export const makeGetOtherAccounts = () => { export const makeGetOtherAccounts = () => {
return createSelector( return createSelector([
[(accounts, authUsers, me) => { state => state.get('accounts'),
return authUsers state => state.getIn(['auth', 'users']),
.keySeq() state => state.get('me'),
.reduce((list, id) => { ],
if (id === me) return list; (accounts, authUsers, me) => {
const account = accounts.get(id); return authUsers
return account ? list.push(account) : list; .keySeq()
}, ImmutableList()); .reduce((list, id) => {
}], if (id === me) return list;
otherAccounts => otherAccounts, const account = accounts.get(id);
); return account ? list.push(account) : list;
}, ImmutableList());
});
}; };