Recsys: determine the clicked index based on raw results instead of rendered order

## Ticket
1606

## Issue
The displayed order of the recs are often re-adjusted -- viewed content are pushed to the bottom to avoid auto-play-next from picking it up again. This was causing recsys to be confused, because the click order does not correspond the results.

## Change
Refactored the selector we can grab the raw results and use that as the index reference.
This commit is contained in:
infinite-persistence 2022-06-01 20:19:50 +08:00 committed by Thomas Zarebczan
parent 2edf1ca564
commit e4214b1c1b
3 changed files with 10 additions and 6 deletions

View file

@ -1,7 +1,7 @@
// @flow
import { RECSYS_ENDPOINT } from 'config';
import { selectUser } from 'redux/selectors/user';
import { makeSelectRecommendedRecsysIdForClaimId } from 'redux/selectors/search';
import { makeSelectRecommendedRecsysIdForClaimId, selectRecommendedContentRawForUri } from 'redux/selectors/search';
import { v4 as Uuidv4 } from 'uuid';
import { parseURI } from 'util/lbryURI';
import { getAuthToken } from 'util/saved-passwords';
@ -82,13 +82,17 @@ const recsys: Recsys = {
* plus recommended content, recsysId, etc.
* Called from recommendedContent component
*/
onRecsLoaded: function (claimId, uris, uuid = '') {
onRecsLoaded: function (uri, claimId, uuid = '') {
if (window && window.store) {
const state = window.store.getState();
const rawRecommendations = selectRecommendedContentRawForUri(state, uri);
const rawUris = rawRecommendations ? rawRecommendations.uris : null;
if (!recsys.entries[claimId]) {
recsys.createRecsysEntry(claimId, null, uuid);
}
const claimIds = getClaimIdsFromUris(uris);
const claimIds = getClaimIdsFromUris(rawUris);
recsys.entries[claimId]['recsysId'] = makeSelectRecommendedRecsysIdForClaimId(claimId)(state) || recsysId;
recsys.entries[claimId]['pageLoadedAt'] = Date.now();

View file

@ -4,7 +4,7 @@ declare type Recsys = {
saveEntries: () => void,
onClickedRecommended: (parentClaimId: ClaimId, newClaimId: ClaimId) => void,
onRecsLoaded: (claimId: ClaimId, uris: Array<string>, uuid: string) => void,
onRecsLoaded: (uri: ?string, claimId: ClaimId, uuid: string) => void,
createRecsysEntry: (claimId: ClaimId, parentUuid?: ?string, uuid?: string) => void,
sendRecsysEntry: (claimId: ClaimId, isTentative?: boolean) => ?Promise<?Response>,
sendEntries: (entries: ?{ [ClaimId]: RecsysEntry }, isResumedSend: boolean) => void,

View file

@ -107,9 +107,9 @@ export default React.memo<Props>(function RecommendedContent(props: Props) {
nextRecommendedUri &&
viewMode === VIEW_ALL_RELATED
) {
onRecommendationsLoaded(claimId, recommendedContentUris, uuid);
onRecommendationsLoaded(uri, claimId, uuid);
}
}, [recommendedContentUris, onRecommendationsLoaded, claimId, nextRecommendedUri, viewMode, uuid]);
}, [uri, recommendedContentUris, onRecommendationsLoaded, claimId, nextRecommendedUri, viewMode, uuid]);
function handleRecommendationClicked(e, clickedClaim) {
if (claim) {