2022-04-01 16:02:03 +08:00
|
|
|
// @flow
|
2017-12-21 14:32:51 -03:00
|
|
|
import * as ACTIONS from 'constants/action_types';
|
2017-04-23 16:56:50 +07:00
|
|
|
|
2017-06-05 21:21:55 -07:00
|
|
|
const reducers = {};
|
2022-04-01 16:02:03 +08:00
|
|
|
const defaultState: ContentState = {
|
2020-10-20 13:10:02 -04:00
|
|
|
primaryUri: null, // Top level content uri triggered from the file page
|
Playlists v2: Refactors, touch ups + Queue Mode (#1604)
* Playlists v2
* Style pass
* Change playlist items arrange icon
* Playlist card body open by default
* Refactor collectionEdit components
* Paginate & Refactor bid field
* Collection page changes
* Add Thumbnail optional
* Replace extra info for description on collection page
* Playlist card right below video on medium screen
* Allow editing private collections
* Add edit option to menus
* Allow deleting a public playlist but keeping a private version
* Add queue to Save menu, remove edit option from Builtin pages, show queue on playlists page
* Fix scroll to recent persisting on medium screen
* Fix adding to queue from menu
* Fixes for delete
* PublishList: delay mounting Items tab to prevent lock-up (#1783)
For a large list, the playlist publish form is unusable (super-slow typing) due to the entire list being mounted despite the tab is not active.
The full solution is still to paginate it, but for now, don't mount the tab until it is selected. Add a spinner to indicate something is loading. It's not prefect, but it's throwaway code anyway. At least we can fill in the fields properly now.
* Batch-resolve private collections (#1782)
* makeSelectClaimForClaimId --> selectClaimForClaimId
Move away from the problematic `makeSelect*`, especially in large loops.
* Batch-resolve private collections
1758
This alleviates the lock-up that is caused by large number of invidual resolves. There will still be some minor stutter due to the large DOM that React needs to handle -- that is logged in 1758 and will be handled separately.
At least the stutter is short (1-2s) and the app is still usable.
Private list items are being resolve individually, super slow if the list is large (>100). Published lists doesn't have this issue.
doFetchItemsInCollections contains most of the useful logic, but it isn't called for private/built-in lists because it's not an actual claim.
Tweaked doFetchItemsInCollections to handle private (UUID-based) collections.
* Use persisted state for floating player playlist card body
- I find it annoying being open everytime
* Fix removing edits from published playlist
* Fix scroll on mobile
* Allow going editing items from toast
* Fix ClaimShareButton
* Prevent edit/publish of builtin
* Fix async inside forEach
* Fix sync on queue edit
* Fix autoplayCountdown replay
* Fix deleting an item scrolling the playlist
* CreatedAt fixes
* Remove repost for now
* Anon publish fixes
* Fix mature case on floating
Co-authored-by: infinite-persistence <64950861+infinite-persistence@users.noreply.github.com>
2022-07-13 10:59:59 -03:00
|
|
|
playingUri: { uri: undefined, collection: {} },
|
2017-10-12 09:37:24 -04:00
|
|
|
channelClaimCounts: {},
|
2018-07-31 08:36:20 -04:00
|
|
|
positions: {},
|
2018-07-31 14:07:45 -04:00
|
|
|
history: [],
|
2022-04-01 16:02:03 +08:00
|
|
|
recommendationId: {},
|
|
|
|
recommendationParentId: {},
|
|
|
|
recommendationUrls: {},
|
|
|
|
recommendationClicks: {},
|
2022-05-18 17:01:25 +08:00
|
|
|
lastViewedAnnouncement: '',
|
2022-05-24 20:24:04 +08:00
|
|
|
recsysEntries: {},
|
2017-07-25 03:07:54 -04:00
|
|
|
};
|
2017-04-23 16:56:50 +07:00
|
|
|
|
2020-10-20 13:10:02 -04:00
|
|
|
reducers[ACTIONS.SET_PRIMARY_URI] = (state, action) =>
|
2017-12-13 18:36:30 -03:00
|
|
|
Object.assign({}, state, {
|
2020-10-20 13:10:02 -04:00
|
|
|
primaryUri: action.data.uri,
|
2017-09-17 22:08:43 -04:00
|
|
|
});
|
|
|
|
|
2020-10-20 13:10:02 -04:00
|
|
|
reducers[ACTIONS.SET_PLAYING_URI] = (state, action) =>
|
2020-04-29 16:50:06 -04:00
|
|
|
Object.assign({}, state, {
|
2020-10-20 13:10:02 -04:00
|
|
|
playingUri: {
|
|
|
|
uri: action.data.uri,
|
|
|
|
source: action.data.source,
|
|
|
|
pathname: action.data.pathname,
|
|
|
|
commentId: action.data.commentId,
|
Playlists v2: Refactors, touch ups + Queue Mode (#1604)
* Playlists v2
* Style pass
* Change playlist items arrange icon
* Playlist card body open by default
* Refactor collectionEdit components
* Paginate & Refactor bid field
* Collection page changes
* Add Thumbnail optional
* Replace extra info for description on collection page
* Playlist card right below video on medium screen
* Allow editing private collections
* Add edit option to menus
* Allow deleting a public playlist but keeping a private version
* Add queue to Save menu, remove edit option from Builtin pages, show queue on playlists page
* Fix scroll to recent persisting on medium screen
* Fix adding to queue from menu
* Fixes for delete
* PublishList: delay mounting Items tab to prevent lock-up (#1783)
For a large list, the playlist publish form is unusable (super-slow typing) due to the entire list being mounted despite the tab is not active.
The full solution is still to paginate it, but for now, don't mount the tab until it is selected. Add a spinner to indicate something is loading. It's not prefect, but it's throwaway code anyway. At least we can fill in the fields properly now.
* Batch-resolve private collections (#1782)
* makeSelectClaimForClaimId --> selectClaimForClaimId
Move away from the problematic `makeSelect*`, especially in large loops.
* Batch-resolve private collections
1758
This alleviates the lock-up that is caused by large number of invidual resolves. There will still be some minor stutter due to the large DOM that React needs to handle -- that is logged in 1758 and will be handled separately.
At least the stutter is short (1-2s) and the app is still usable.
Private list items are being resolve individually, super slow if the list is large (>100). Published lists doesn't have this issue.
doFetchItemsInCollections contains most of the useful logic, but it isn't called for private/built-in lists because it's not an actual claim.
Tweaked doFetchItemsInCollections to handle private (UUID-based) collections.
* Use persisted state for floating player playlist card body
- I find it annoying being open everytime
* Fix removing edits from published playlist
* Fix scroll on mobile
* Allow going editing items from toast
* Fix ClaimShareButton
* Prevent edit/publish of builtin
* Fix async inside forEach
* Fix sync on queue edit
* Fix autoplayCountdown replay
* Fix deleting an item scrolling the playlist
* CreatedAt fixes
* Remove repost for now
* Anon publish fixes
* Fix mature case on floating
Co-authored-by: infinite-persistence <64950861+infinite-persistence@users.noreply.github.com>
2022-07-13 10:59:59 -03:00
|
|
|
collection: action.data.collection,
|
2020-10-20 13:10:02 -04:00
|
|
|
primaryUri: state.primaryUri,
|
|
|
|
},
|
2020-04-29 16:50:06 -04:00
|
|
|
});
|
|
|
|
|
2018-07-31 08:36:20 -04: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-14 18:18:54 -07: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 14:07:45 -04: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 20:07:49 +08:00
|
|
|
const index = history.findIndex((i) => i.uri === uri);
|
2018-07-31 14:07:45 -04: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 20:07:49 +08:00
|
|
|
const index = history.findIndex((i) => i.uri === uri);
|
2018-07-31 14:07:45 -04:00
|
|
|
return index === -1
|
|
|
|
? state
|
|
|
|
: {
|
2019-03-25 02:18:22 -04:00
|
|
|
...state,
|
|
|
|
history: history.slice(0, index).concat(history.slice(index + 1)),
|
|
|
|
};
|
2018-07-31 14:07:45 -04: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 20:07:49 +08:00
|
|
|
reducers[ACTIONS.CLEAR_CONTENT_HISTORY_ALL] = (state) => ({ ...state, history: [] });
|
|
|
|
|
2022-05-18 17:01:25 +08:00
|
|
|
reducers[ACTIONS.SET_LAST_VIEWED_ANNOUNCEMENT] = (state, action) => ({ ...state, lastViewedAnnouncement: action.data });
|
|
|
|
|
2022-05-24 20:24:04 +08:00
|
|
|
reducers[ACTIONS.SET_RECSYS_ENTRIES] = (state, action) => ({ ...state, recsysEntries: action.data });
|
|
|
|
|
2020-05-21 12:53:21 -04:00
|
|
|
// reducers[LBRY_REDUX_ACTIONS.PURCHASE_URI_FAILED] = (state, action) => {
|
|
|
|
// return {
|
|
|
|
// ...state,
|
|
|
|
// playingUri: null,
|
|
|
|
// };
|
|
|
|
// };
|
2020-05-21 11:38:28 -04:00
|
|
|
|
2022-05-18 17:01:25 +08:00
|
|
|
reducers[ACTIONS.USER_STATE_POPULATE] = (state, action) => {
|
|
|
|
const { lastViewedAnnouncement } = action.data;
|
|
|
|
return { ...state, lastViewedAnnouncement };
|
|
|
|
};
|
|
|
|
|
2022-04-01 16:02:03 +08:00
|
|
|
export default function reducer(state: ContentState = defaultState, action: any) {
|
2017-04-23 16:56:50 +07:00
|
|
|
const handler = reducers[action.type];
|
|
|
|
if (handler) return handler(state, action);
|
|
|
|
return state;
|
|
|
|
}
|