2017-12-21 18:32:51 +01:00
|
|
|
import * as ACTIONS from 'constants/action_types';
|
2017-04-23 11:56:50 +02:00
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
const reducers = {};
|
2017-07-25 09:07:54 +02:00
|
|
|
const defaultState = {
|
2017-09-18 04:08:43 +02:00
|
|
|
playingUri: null,
|
2020-04-29 22:50:06 +02:00
|
|
|
floatingUri: null,
|
2017-10-12 15:37:24 +02:00
|
|
|
channelClaimCounts: {},
|
2018-07-31 14:36:20 +02:00
|
|
|
positions: {},
|
2018-07-31 20:07:45 +02:00
|
|
|
history: [],
|
2017-07-25 09:07:54 +02:00
|
|
|
};
|
2017-04-23 11:56:50 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
reducers[ACTIONS.SET_PLAYING_URI] = (state, action) =>
|
2017-12-13 22:36:30 +01:00
|
|
|
Object.assign({}, state, {
|
2017-09-18 04:08:43 +02:00
|
|
|
playingUri: action.data.uri,
|
|
|
|
});
|
|
|
|
|
2020-04-29 22:50:06 +02:00
|
|
|
reducers[ACTIONS.SET_FLOATING_URI] = (state, action) =>
|
|
|
|
Object.assign({}, state, {
|
|
|
|
floatingUri: action.data.uri,
|
|
|
|
});
|
|
|
|
|
2018-07-31 14:36:20 +02:00
|
|
|
reducers[ACTIONS.SET_CONTENT_POSITION] = (state, action) => {
|
|
|
|
const { claimId, outpoint, position } = action.data;
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
positions: {
|
|
|
|
...state.positions,
|
|
|
|
[claimId]: {
|
|
|
|
...state.positions[claimId],
|
|
|
|
[outpoint]: position,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-07-31 20:07:45 +02:00
|
|
|
reducers[ACTIONS.SET_CONTENT_LAST_VIEWED] = (state, action) => {
|
|
|
|
const { uri, lastViewed } = action.data;
|
|
|
|
const { history } = state;
|
|
|
|
const historyObj = { uri, lastViewed };
|
|
|
|
const index = history.findIndex(i => i.uri === uri);
|
|
|
|
const newHistory =
|
|
|
|
index === -1
|
|
|
|
? [historyObj].concat(history)
|
|
|
|
: [historyObj].concat(history.slice(0, index), history.slice(index + 1));
|
|
|
|
return { ...state, history: [...newHistory] };
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[ACTIONS.CLEAR_CONTENT_HISTORY_URI] = (state, action) => {
|
|
|
|
const { uri } = action.data;
|
|
|
|
const { history } = state;
|
|
|
|
const index = history.findIndex(i => i.uri === uri);
|
|
|
|
return index === -1
|
|
|
|
? state
|
|
|
|
: {
|
2019-03-25 07:18:22 +01:00
|
|
|
...state,
|
|
|
|
history: history.slice(0, index).concat(history.slice(index + 1)),
|
|
|
|
};
|
2018-07-31 20:07:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
reducers[ACTIONS.CLEAR_CONTENT_HISTORY_ALL] = state => ({ ...state, history: [] });
|
|
|
|
|
2017-04-23 11:56:50 +02:00
|
|
|
export default function reducer(state = defaultState, action) {
|
|
|
|
const handler = reducers[action.type];
|
|
|
|
if (handler) return handler(state, action);
|
|
|
|
return state;
|
|
|
|
}
|