2022-06-04 00:22:36 -07:00
|
|
|
import { List as ImmutableList, Record as ImmutableRecord } from 'immutable';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2021-08-05 06:31:29 -07:00
|
|
|
import {
|
|
|
|
ALIASES_SUGGESTIONS_READY,
|
|
|
|
ALIASES_SUGGESTIONS_CLEAR,
|
|
|
|
ALIASES_SUGGESTIONS_CHANGE,
|
2022-02-14 12:00:41 -08:00
|
|
|
ALIASES_FETCH_SUCCESS,
|
2021-08-05 06:31:29 -07:00
|
|
|
} from '../actions/aliases';
|
|
|
|
|
2022-06-04 00:22:36 -07:00
|
|
|
import type { AnyAction } from 'redux';
|
|
|
|
import type { APIEntity } from 'soapbox/types/entities';
|
|
|
|
|
|
|
|
|
|
|
|
const ReducerRecord = ImmutableRecord({
|
|
|
|
aliases: ImmutableRecord({
|
|
|
|
items: ImmutableList<string>(),
|
2022-02-14 12:00:41 -08:00
|
|
|
loaded: false,
|
2022-06-04 00:22:36 -07:00
|
|
|
})(),
|
|
|
|
suggestions: ImmutableRecord({
|
|
|
|
items: ImmutableList<string>(),
|
2021-08-05 06:31:29 -07:00
|
|
|
value: '',
|
2021-08-08 07:17:29 -07:00
|
|
|
loaded: false,
|
2022-06-04 00:22:36 -07:00
|
|
|
})(),
|
2021-08-05 06:31:29 -07:00
|
|
|
});
|
|
|
|
|
2022-06-04 00:22:36 -07:00
|
|
|
export default function aliasesReducer(state = ReducerRecord(), action: AnyAction) {
|
2022-05-11 10:40:34 -07:00
|
|
|
switch (action.type) {
|
2022-05-11 14:06:35 -07:00
|
|
|
case ALIASES_FETCH_SUCCESS:
|
|
|
|
return state
|
|
|
|
.setIn(['aliases', 'items'], action.value);
|
|
|
|
case ALIASES_SUGGESTIONS_CHANGE:
|
|
|
|
return state
|
|
|
|
.setIn(['suggestions', 'value'], action.value)
|
|
|
|
.setIn(['suggestions', 'loaded'], false);
|
|
|
|
case ALIASES_SUGGESTIONS_READY:
|
|
|
|
return state
|
2022-06-04 00:22:36 -07:00
|
|
|
.setIn(['suggestions', 'items'], ImmutableList(action.accounts.map((item: APIEntity) => item.id)))
|
2022-05-11 14:06:35 -07:00
|
|
|
.setIn(['suggestions', 'loaded'], true);
|
|
|
|
case ALIASES_SUGGESTIONS_CLEAR:
|
|
|
|
return state.update('suggestions', suggestions => suggestions.withMutations(map => {
|
|
|
|
map.set('items', ImmutableList());
|
|
|
|
map.set('value', '');
|
|
|
|
map.set('loaded', false);
|
|
|
|
}));
|
|
|
|
default:
|
|
|
|
return state;
|
2021-08-05 06:31:29 -07:00
|
|
|
}
|
2021-08-11 10:22:06 -07:00
|
|
|
}
|