2021-09-25 23:46:13 -04:00
|
|
|
import { Map as ImmutableMap } from 'immutable';
|
|
|
|
|
2023-05-23 11:15:17 -04:00
|
|
|
import { ACCOUNT_LOOKUP_FAIL } from '../actions/accounts';
|
|
|
|
import { ACCOUNT_IMPORT, ACCOUNTS_IMPORT } from '../actions/importer';
|
|
|
|
|
2022-10-21 04:06:03 -04:00
|
|
|
export const normalizeForLookup = str => str.toLowerCase();
|
|
|
|
|
2021-09-25 23:46:13 -04:00
|
|
|
const initialState = ImmutableMap();
|
|
|
|
|
|
|
|
export default function accountsMap(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
2022-11-27 14:48:12 -05:00
|
|
|
case ACCOUNT_LOOKUP_FAIL:
|
|
|
|
return action.error?.response?.status === 404 ? state.set(normalizeForLookup(action.acct), null) : state;
|
2021-09-25 23:46:13 -04:00
|
|
|
case ACCOUNT_IMPORT:
|
2022-10-21 04:06:03 -04:00
|
|
|
return state.set(normalizeForLookup(action.account.acct), action.account.id);
|
2021-09-25 23:46:13 -04:00
|
|
|
case ACCOUNTS_IMPORT:
|
2022-10-21 04:06:03 -04:00
|
|
|
return state.withMutations(map => action.accounts.forEach(account => map.set(normalizeForLookup(account.acct), account.id)));
|
2021-09-25 23:46:13 -04:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2022-12-18 10:51:37 -05:00
|
|
|
}
|