2021-04-23 05:04:11 +02:00
|
|
|
// @flow
|
|
|
|
import * as ACTIONS from 'constants/action_types';
|
|
|
|
import { handleActions } from 'util/redux-utils';
|
|
|
|
|
|
|
|
const defaultState: LivestreamState = {
|
2021-04-23 19:11:53 +02:00
|
|
|
fetchingById: {},
|
2021-06-17 20:55:23 +02:00
|
|
|
viewersById: {},
|
2021-09-16 10:02:41 +02:00
|
|
|
fetchingActiveLivestreams: false,
|
|
|
|
activeLivestreams: null,
|
2021-09-23 10:33:19 +02:00
|
|
|
activeLivestreamsLastFetchedDate: 0,
|
|
|
|
activeLivestreamsLastFetchedOptions: {},
|
2021-04-23 05:04:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default handleActions(
|
|
|
|
{
|
|
|
|
[ACTIONS.FETCH_NO_SOURCE_CLAIMS_STARTED]: (state: LivestreamState, action: any): LivestreamState => {
|
|
|
|
const claimId = action.data;
|
2021-04-23 19:11:53 +02:00
|
|
|
const newIdsFetching = Object.assign({}, state.fetchingById);
|
2021-04-23 05:04:11 +02:00
|
|
|
newIdsFetching[claimId] = true;
|
|
|
|
|
2021-04-23 19:11:53 +02:00
|
|
|
return { ...state, fetchingById: newIdsFetching };
|
2021-04-23 05:04:11 +02:00
|
|
|
},
|
|
|
|
[ACTIONS.FETCH_NO_SOURCE_CLAIMS_COMPLETED]: (state: LivestreamState, action: any): LivestreamState => {
|
|
|
|
const claimId = action.data;
|
2021-04-23 19:11:53 +02:00
|
|
|
const newIdsFetching = Object.assign({}, state.fetchingById);
|
2021-04-23 05:04:11 +02:00
|
|
|
newIdsFetching[claimId] = false;
|
|
|
|
|
2021-04-23 19:11:53 +02:00
|
|
|
return { ...state, fetchingById: newIdsFetching };
|
2021-04-23 05:04:11 +02:00
|
|
|
},
|
|
|
|
[ACTIONS.FETCH_NO_SOURCE_CLAIMS_FAILED]: (state: LivestreamState, action: any) => {
|
|
|
|
const claimId = action.data;
|
2021-04-23 19:11:53 +02:00
|
|
|
const newIdsFetching = Object.assign({}, state.fetchingById);
|
2021-04-23 05:04:11 +02:00
|
|
|
newIdsFetching[claimId] = false;
|
|
|
|
|
2021-04-23 19:11:53 +02:00
|
|
|
return { ...state, fetchingById: newIdsFetching };
|
2021-04-23 05:04:11 +02:00
|
|
|
},
|
2021-06-17 20:55:23 +02:00
|
|
|
[ACTIONS.VIEWERS_RECEIVED]: (state: LivestreamState, action: any) => {
|
|
|
|
const { connected, claimId } = action.data;
|
|
|
|
const newViewersById = Object.assign({}, state.viewersById);
|
|
|
|
newViewersById[claimId] = connected;
|
|
|
|
return { ...state, viewersById: newViewersById };
|
|
|
|
},
|
2021-09-16 10:02:41 +02:00
|
|
|
[ACTIONS.FETCH_ACTIVE_LIVESTREAMS_STARTED]: (state: LivestreamState) => {
|
|
|
|
return { ...state, fetchingActiveLivestreams: true };
|
|
|
|
},
|
|
|
|
[ACTIONS.FETCH_ACTIVE_LIVESTREAMS_FAILED]: (state: LivestreamState) => {
|
|
|
|
return { ...state, fetchingActiveLivestreams: false };
|
|
|
|
},
|
|
|
|
[ACTIONS.FETCH_ACTIVE_LIVESTREAMS_COMPLETED]: (state: LivestreamState, action: any) => {
|
2021-09-23 10:33:19 +02:00
|
|
|
const { activeLivestreams, activeLivestreamsLastFetchedDate, activeLivestreamsLastFetchedOptions } = action.data;
|
2021-09-20 04:30:23 +02:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
fetchingActiveLivestreams: false,
|
|
|
|
activeLivestreams,
|
2021-09-23 10:33:19 +02:00
|
|
|
activeLivestreamsLastFetchedDate,
|
|
|
|
activeLivestreamsLastFetchedOptions,
|
2021-09-20 04:30:23 +02:00
|
|
|
};
|
2021-09-16 10:02:41 +02:00
|
|
|
},
|
2021-04-23 05:04:11 +02:00
|
|
|
},
|
|
|
|
defaultState
|
|
|
|
);
|