2022-08-09 12:22:18 +00:00
|
|
|
import ReducerRegistry from '../base/redux/ReducerRegistry';
|
2022-03-11 13:00:49 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
ADD_GIF_FOR_PARTICIPANT,
|
|
|
|
HIDE_GIF_FOR_PARTICIPANT,
|
|
|
|
REMOVE_GIF_FOR_PARTICIPANT,
|
|
|
|
SET_GIF_DRAWER_VISIBILITY,
|
|
|
|
SET_GIF_MENU_VISIBILITY
|
|
|
|
} from './actionTypes';
|
|
|
|
|
|
|
|
const initialState = {
|
|
|
|
drawerVisible: false,
|
|
|
|
gifList: new Map(),
|
|
|
|
menuOpen: false
|
|
|
|
};
|
|
|
|
|
2022-09-29 11:45:34 +00:00
|
|
|
export interface IGif {
|
|
|
|
gifUrl?: string;
|
|
|
|
timeoutID?: number;
|
|
|
|
}
|
|
|
|
|
2022-08-09 12:22:18 +00:00
|
|
|
export interface IGifsState {
|
|
|
|
drawerVisible: boolean;
|
2022-09-29 11:45:34 +00:00
|
|
|
gifList: Map<string, IGif>;
|
2022-08-09 12:22:18 +00:00
|
|
|
menuOpen: boolean;
|
|
|
|
}
|
|
|
|
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<IGifsState>(
|
2022-03-11 13:00:49 +00:00
|
|
|
'features/gifs',
|
2022-09-05 09:05:07 +00:00
|
|
|
(state = initialState, action): IGifsState => {
|
2022-03-11 13:00:49 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case ADD_GIF_FOR_PARTICIPANT: {
|
|
|
|
const newList = state.gifList;
|
|
|
|
|
|
|
|
newList.set(action.participantId, {
|
|
|
|
gifUrl: action.gifUrl,
|
|
|
|
timeoutID: action.timeoutID
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
gifList: newList
|
|
|
|
};
|
|
|
|
}
|
|
|
|
case REMOVE_GIF_FOR_PARTICIPANT: {
|
|
|
|
const newList = state.gifList;
|
|
|
|
|
|
|
|
newList.delete(action.participantId);
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
gifList: newList
|
|
|
|
};
|
|
|
|
}
|
|
|
|
case HIDE_GIF_FOR_PARTICIPANT: {
|
|
|
|
const newList = state.gifList;
|
|
|
|
const gif = state.gifList.get(action.participantId);
|
|
|
|
|
|
|
|
newList.set(action.participantId, {
|
2022-09-05 09:05:07 +00:00
|
|
|
gifUrl: gif?.gifUrl ?? '',
|
2022-03-11 13:00:49 +00:00
|
|
|
timeoutID: action.timeoutID
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
gifList: newList
|
|
|
|
};
|
|
|
|
}
|
|
|
|
case SET_GIF_DRAWER_VISIBILITY:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
drawerVisible: action.visible
|
|
|
|
};
|
|
|
|
case SET_GIF_MENU_VISIBILITY:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
menuOpen: action.visible
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|
|
|
|
|