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 = {
|
2020-10-20 19:10:02 +02:00
|
|
|
primaryUri: null, // Top level content uri triggered from the file page
|
2017-09-18 04:08:43 +02:00
|
|
|
playingUri: 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: [],
|
Fill in remaining Recsys fields
## Issue
6366 Recsys Evaluation Telemetry
The recommended list from lighthouse is obtained from `makeSelectRecommendedContentForUri`. This list is further tweaked by the GUI (e.g. move autoplay next item to top, remove blocked content, etc.). Recsys wants the final recommendation list and the clicked index (in exact order), so we need pass these info to the videojs recsys plugin somehow. Also, Recsys wants a recommendation list ID as well as the parent (referrer) ID, we so need to track the clicks and navigation.
## General Approach
- It seems easiest to just spew back the final (displayed) list and all the required info to Redux, and the recsys plugin (or anyone else in the future) can grab it.
- Try to touch few files as possible. The dirty work should all reside in `<RecommendedContent>` only.
## Changes
- `ClaimPreview`: add optional parameters to store an ID of the container that it is in (for this case, it is `ClaimList`) as well as the index within the container.
- When clicked, we store the container ID in the navigation history `state` object.
- For general cases, anyone can check this state from `history.location.state` to know which container referred/navigated to the current page. For the recsys use case, we can use this as the `parentUUID`.
- `ClaimList`: just relay `onClick` and set IDs.
- `RecommendedContent`: now handles the uuid generation (for both parent and child) and stores the data in Redux.
2021-07-28 14:07:49 +02:00
|
|
|
recommendationId: {}, // { "claimId": "recommendationId" }
|
|
|
|
recommendationParentId: {}, // { "claimId": "referrerId" }
|
|
|
|
recommendationUrls: {}, // { "claimId": [lbryUrls...] }
|
|
|
|
recommendationClicks: {}, // { "claimId": [clicked indices...] }
|
2017-07-25 09:07:54 +02:00
|
|
|
};
|
2017-04-23 11:56:50 +02:00
|
|
|
|
2020-10-20 19:10:02 +02:00
|
|
|
reducers[ACTIONS.SET_PRIMARY_URI] = (state, action) =>
|
2017-12-13 22:36:30 +01:00
|
|
|
Object.assign({}, state, {
|
2020-10-20 19:10:02 +02:00
|
|
|
primaryUri: action.data.uri,
|
2017-09-18 04:08:43 +02:00
|
|
|
});
|
|
|
|
|
2020-10-20 19:10:02 +02:00
|
|
|
reducers[ACTIONS.SET_PLAYING_URI] = (state, action) =>
|
2020-04-29 22:50:06 +02:00
|
|
|
Object.assign({}, state, {
|
2020-10-20 19:10:02 +02:00
|
|
|
playingUri: {
|
|
|
|
uri: action.data.uri,
|
|
|
|
source: action.data.source,
|
|
|
|
pathname: action.data.pathname,
|
|
|
|
commentId: action.data.commentId,
|
2021-08-24 13:50:37 +02:00
|
|
|
collectionId: action.data.collectionId,
|
2020-10-20 19:10:02 +02:00
|
|
|
primaryUri: state.primaryUri,
|
|
|
|
},
|
2020-04-29 22:50:06 +02:00
|
|
|
});
|
|
|
|
|
2021-08-24 13:48:43 +02:00
|
|
|
reducers[ACTIONS.TOGGLE_LOOP_LIST] = (state, action) =>
|
|
|
|
Object.assign({}, state, {
|
|
|
|
loopList: {
|
|
|
|
collectionId: action.data.collectionId,
|
|
|
|
loop: action.data.loop,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-08-25 14:06:16 +02:00
|
|
|
reducers[ACTIONS.TOGGLE_SHUFFLE_LIST] = (state, action) =>
|
|
|
|
Object.assign({}, state, {
|
|
|
|
shuffleList: {
|
|
|
|
collectionId: action.data.collectionId,
|
|
|
|
newUrls: action.data.newUrls,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-05-15 03:18:54 +02:00
|
|
|
reducers[ACTIONS.CLEAR_CONTENT_POSITION] = (state, action) => {
|
|
|
|
const { claimId, outpoint } = action.data;
|
|
|
|
|
|
|
|
if (state.positions[claimId]) {
|
|
|
|
const numOutpoints = Object.keys(state.positions[claimId]).length;
|
|
|
|
if (numOutpoints <= 1) {
|
|
|
|
let positions = { ...state.positions };
|
|
|
|
delete positions[claimId];
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
positions: positions,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
let outpoints = { ...state.positions[claimId] };
|
|
|
|
delete outpoints[outpoint];
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
positions: {
|
|
|
|
...state.positions,
|
|
|
|
[claimId]: outpoints,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 };
|
Fill in remaining Recsys fields
## Issue
6366 Recsys Evaluation Telemetry
The recommended list from lighthouse is obtained from `makeSelectRecommendedContentForUri`. This list is further tweaked by the GUI (e.g. move autoplay next item to top, remove blocked content, etc.). Recsys wants the final recommendation list and the clicked index (in exact order), so we need pass these info to the videojs recsys plugin somehow. Also, Recsys wants a recommendation list ID as well as the parent (referrer) ID, we so need to track the clicks and navigation.
## General Approach
- It seems easiest to just spew back the final (displayed) list and all the required info to Redux, and the recsys plugin (or anyone else in the future) can grab it.
- Try to touch few files as possible. The dirty work should all reside in `<RecommendedContent>` only.
## Changes
- `ClaimPreview`: add optional parameters to store an ID of the container that it is in (for this case, it is `ClaimList`) as well as the index within the container.
- When clicked, we store the container ID in the navigation history `state` object.
- For general cases, anyone can check this state from `history.location.state` to know which container referred/navigated to the current page. For the recsys use case, we can use this as the `parentUUID`.
- `ClaimList`: just relay `onClick` and set IDs.
- `RecommendedContent`: now handles the uuid generation (for both parent and child) and stores the data in Redux.
2021-07-28 14:07:49 +02:00
|
|
|
const index = history.findIndex((i) => i.uri === uri);
|
2018-07-31 20:07:45 +02:00
|
|
|
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;
|
Fill in remaining Recsys fields
## Issue
6366 Recsys Evaluation Telemetry
The recommended list from lighthouse is obtained from `makeSelectRecommendedContentForUri`. This list is further tweaked by the GUI (e.g. move autoplay next item to top, remove blocked content, etc.). Recsys wants the final recommendation list and the clicked index (in exact order), so we need pass these info to the videojs recsys plugin somehow. Also, Recsys wants a recommendation list ID as well as the parent (referrer) ID, we so need to track the clicks and navigation.
## General Approach
- It seems easiest to just spew back the final (displayed) list and all the required info to Redux, and the recsys plugin (or anyone else in the future) can grab it.
- Try to touch few files as possible. The dirty work should all reside in `<RecommendedContent>` only.
## Changes
- `ClaimPreview`: add optional parameters to store an ID of the container that it is in (for this case, it is `ClaimList`) as well as the index within the container.
- When clicked, we store the container ID in the navigation history `state` object.
- For general cases, anyone can check this state from `history.location.state` to know which container referred/navigated to the current page. For the recsys use case, we can use this as the `parentUUID`.
- `ClaimList`: just relay `onClick` and set IDs.
- `RecommendedContent`: now handles the uuid generation (for both parent and child) and stores the data in Redux.
2021-07-28 14:07:49 +02:00
|
|
|
const index = history.findIndex((i) => i.uri === uri);
|
2018-07-31 20:07:45 +02:00
|
|
|
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
|
|
|
};
|
|
|
|
|
Fill in remaining Recsys fields
## Issue
6366 Recsys Evaluation Telemetry
The recommended list from lighthouse is obtained from `makeSelectRecommendedContentForUri`. This list is further tweaked by the GUI (e.g. move autoplay next item to top, remove blocked content, etc.). Recsys wants the final recommendation list and the clicked index (in exact order), so we need pass these info to the videojs recsys plugin somehow. Also, Recsys wants a recommendation list ID as well as the parent (referrer) ID, we so need to track the clicks and navigation.
## General Approach
- It seems easiest to just spew back the final (displayed) list and all the required info to Redux, and the recsys plugin (or anyone else in the future) can grab it.
- Try to touch few files as possible. The dirty work should all reside in `<RecommendedContent>` only.
## Changes
- `ClaimPreview`: add optional parameters to store an ID of the container that it is in (for this case, it is `ClaimList`) as well as the index within the container.
- When clicked, we store the container ID in the navigation history `state` object.
- For general cases, anyone can check this state from `history.location.state` to know which container referred/navigated to the current page. For the recsys use case, we can use this as the `parentUUID`.
- `ClaimList`: just relay `onClick` and set IDs.
- `RecommendedContent`: now handles the uuid generation (for both parent and child) and stores the data in Redux.
2021-07-28 14:07:49 +02:00
|
|
|
reducers[ACTIONS.CLEAR_CONTENT_HISTORY_ALL] = (state) => ({ ...state, history: [] });
|
|
|
|
|
|
|
|
reducers[ACTIONS.RECOMMENDATION_UPDATED] = (state, action) => {
|
|
|
|
const { claimId, urls, id, parentId } = action.data;
|
|
|
|
const recommendationId = Object.assign({}, state.recommendationId);
|
|
|
|
const recommendationParentId = Object.assign({}, state.recommendationParentId);
|
|
|
|
const recommendationUrls = Object.assign({}, state.recommendationUrls);
|
|
|
|
const recommendationClicks = Object.assign({}, state.recommendationClicks);
|
|
|
|
|
|
|
|
if (urls && urls.length > 0) {
|
|
|
|
recommendationId[claimId] = id;
|
|
|
|
recommendationParentId[claimId] = parentId;
|
|
|
|
recommendationUrls[claimId] = urls;
|
|
|
|
recommendationClicks[claimId] = [];
|
|
|
|
} else {
|
|
|
|
delete recommendationId[claimId];
|
|
|
|
delete recommendationParentId[claimId];
|
|
|
|
delete recommendationUrls[claimId];
|
|
|
|
delete recommendationClicks[claimId];
|
|
|
|
}
|
|
|
|
|
|
|
|
return { ...state, recommendationId, recommendationParentId, recommendationUrls, recommendationClicks };
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[ACTIONS.RECOMMENDATION_CLICKED] = (state, action) => {
|
|
|
|
const { claimId, index } = action.data;
|
|
|
|
const recommendationClicks = Object.assign({}, state.recommendationClicks);
|
|
|
|
|
|
|
|
if (state.recommendationUrls[claimId] && index >= 0 && index < state.recommendationUrls[claimId].length) {
|
|
|
|
if (recommendationClicks[claimId]) {
|
|
|
|
recommendationClicks[claimId].push(index);
|
|
|
|
} else {
|
|
|
|
recommendationClicks[claimId] = [index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { ...state, recommendationClicks };
|
|
|
|
};
|
2018-07-31 20:07:45 +02:00
|
|
|
|
2020-05-21 18:53:21 +02:00
|
|
|
// reducers[LBRY_REDUX_ACTIONS.PURCHASE_URI_FAILED] = (state, action) => {
|
|
|
|
// return {
|
|
|
|
// ...state,
|
|
|
|
// playingUri: null,
|
|
|
|
// };
|
|
|
|
// };
|
2020-05-21 17:38:28 +02:00
|
|
|
|
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;
|
|
|
|
}
|