2022-12-11 12:37:00 -08:00
|
|
|
import { Record as ImmutableRecord } from 'immutable';
|
|
|
|
|
|
|
|
import {
|
|
|
|
GROUP_EDITOR_RESET,
|
|
|
|
GROUP_EDITOR_TITLE_CHANGE,
|
2022-12-14 08:41:16 -08:00
|
|
|
GROUP_EDITOR_DESCRIPTION_CHANGE,
|
2022-12-15 14:51:30 -08:00
|
|
|
GROUP_EDITOR_PRIVACY_CHANGE,
|
|
|
|
GROUP_EDITOR_MEDIA_CHANGE,
|
2022-12-11 12:37:00 -08:00
|
|
|
GROUP_CREATE_REQUEST,
|
|
|
|
GROUP_CREATE_FAIL,
|
|
|
|
GROUP_CREATE_SUCCESS,
|
2022-12-15 14:51:30 -08:00
|
|
|
GROUP_UPDATE_REQUEST,
|
|
|
|
GROUP_UPDATE_FAIL,
|
|
|
|
GROUP_UPDATE_SUCCESS,
|
2022-12-16 12:33:17 -08:00
|
|
|
GROUP_EDITOR_SET,
|
2022-12-11 12:37:00 -08:00
|
|
|
} from 'soapbox/actions/groups';
|
|
|
|
|
|
|
|
import type { AnyAction } from 'redux';
|
|
|
|
|
|
|
|
const ReducerRecord = ImmutableRecord({
|
|
|
|
groupId: null as string | null,
|
2022-12-15 14:51:30 -08:00
|
|
|
progress: 0,
|
2022-12-14 08:41:16 -08:00
|
|
|
isUploading: false,
|
2022-12-11 12:37:00 -08:00
|
|
|
isSubmitting: false,
|
|
|
|
isChanged: false,
|
|
|
|
displayName: '',
|
|
|
|
note: '',
|
2022-12-15 14:51:30 -08:00
|
|
|
avatar: null as File | null,
|
|
|
|
header: null as File | null,
|
2022-12-14 08:41:16 -08:00
|
|
|
locked: false,
|
2022-12-11 12:37:00 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
type State = ReturnType<typeof ReducerRecord>;
|
|
|
|
|
|
|
|
export default function groupEditor(state: State = ReducerRecord(), action: AnyAction) {
|
|
|
|
switch (action.type) {
|
|
|
|
case GROUP_EDITOR_RESET:
|
|
|
|
return ReducerRecord();
|
2022-12-16 12:33:17 -08:00
|
|
|
case GROUP_EDITOR_SET:
|
|
|
|
return state.withMutations(map => {
|
|
|
|
map.set('groupId', action.group.id);
|
|
|
|
map.set('displayName', action.group.display_name);
|
|
|
|
map.set('note', action.group.note);
|
|
|
|
});
|
2022-12-11 12:37:00 -08:00
|
|
|
case GROUP_EDITOR_TITLE_CHANGE:
|
|
|
|
return state.withMutations(map => {
|
|
|
|
map.set('displayName', action.value);
|
|
|
|
map.set('isChanged', true);
|
|
|
|
});
|
2022-12-14 08:41:16 -08:00
|
|
|
case GROUP_EDITOR_DESCRIPTION_CHANGE:
|
|
|
|
return state.withMutations(map => {
|
|
|
|
map.set('note', action.value);
|
|
|
|
map.set('isChanged', true);
|
|
|
|
});
|
2022-12-15 14:51:30 -08:00
|
|
|
case GROUP_EDITOR_PRIVACY_CHANGE:
|
|
|
|
return state.withMutations(map => {
|
|
|
|
map.set('locked', action.value);
|
|
|
|
map.set('isChanged', true);
|
|
|
|
});
|
|
|
|
case GROUP_EDITOR_MEDIA_CHANGE:
|
|
|
|
return state.set(action.mediaType, action.value);
|
2022-12-11 12:37:00 -08:00
|
|
|
case GROUP_CREATE_REQUEST:
|
2022-12-15 14:51:30 -08:00
|
|
|
case GROUP_UPDATE_REQUEST:
|
2022-12-11 12:37:00 -08:00
|
|
|
return state.withMutations(map => {
|
|
|
|
map.set('isSubmitting', true);
|
|
|
|
map.set('isChanged', false);
|
|
|
|
});
|
|
|
|
case GROUP_CREATE_FAIL:
|
2022-12-15 14:51:30 -08:00
|
|
|
case GROUP_UPDATE_FAIL:
|
2022-12-11 12:37:00 -08:00
|
|
|
return state.set('isSubmitting', false);
|
|
|
|
case GROUP_CREATE_SUCCESS:
|
2022-12-15 14:51:30 -08:00
|
|
|
case GROUP_UPDATE_SUCCESS:
|
2022-12-11 12:37:00 -08:00
|
|
|
return state.withMutations(map => {
|
|
|
|
map.set('isSubmitting', false);
|
|
|
|
map.set('groupId', action.group.id);
|
|
|
|
});
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|