2022-08-09 12:22:18 +00:00
|
|
|
import ReducerRegistry from '../base/redux/ReducerRegistry';
|
|
|
|
import { set } from '../base/redux/functions';
|
2020-05-20 10:57:03 +00:00
|
|
|
|
2019-04-26 18:11:53 +00:00
|
|
|
import {
|
|
|
|
SET_FOLLOW_ME_MODERATOR,
|
|
|
|
SET_FOLLOW_ME_STATE
|
|
|
|
} from './actionTypes';
|
|
|
|
|
2022-08-09 12:22:18 +00:00
|
|
|
export interface IFollowMeState {
|
|
|
|
moderator?: string;
|
|
|
|
state?: {
|
|
|
|
[key: string]: string;
|
2022-09-08 09:52:36 +00:00
|
|
|
};
|
2022-08-09 12:22:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 18:11:53 +00:00
|
|
|
/**
|
|
|
|
* Listen for actions that contain the Follow Me feature active state, so that it can be stored.
|
|
|
|
*/
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<IFollowMeState>(
|
2019-04-26 18:11:53 +00:00
|
|
|
'features/follow-me',
|
2022-09-05 09:05:07 +00:00
|
|
|
(state = {}, action): IFollowMeState => {
|
2019-04-26 18:11:53 +00:00
|
|
|
switch (action.type) {
|
|
|
|
|
|
|
|
case SET_FOLLOW_ME_MODERATOR: {
|
|
|
|
let newState = set(state, 'moderator', action.id);
|
|
|
|
|
|
|
|
if (!action.id) {
|
|
|
|
// clear the state if feature becomes disabled
|
|
|
|
newState = set(newState, 'state', undefined);
|
|
|
|
}
|
|
|
|
|
|
|
|
return newState;
|
|
|
|
}
|
|
|
|
case SET_FOLLOW_ME_STATE: {
|
|
|
|
return set(state, 'state', action.state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|