From a31ea6417a85d7fe1d728d3eba32f21d29f6d16c Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Wed, 16 Mar 2022 19:56:08 +0800 Subject: [PATCH] FYP: "Don't recommend channel" --- static/app-strings.json | 1 + ui/constants/modal_types.js | 1 + ui/modal/modalHideRecommendation/index.js | 9 ++++ ui/modal/modalHideRecommendation/view.jsx | 55 +++++++++++++++++++++++ ui/modal/modalRouter/view.jsx | 1 + ui/redux/actions/search.js | 34 +++++++++----- 6 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 ui/modal/modalHideRecommendation/index.js create mode 100644 ui/modal/modalHideRecommendation/view.jsx diff --git a/static/app-strings.json b/static/app-strings.json index 42de21943..7540721ac 100644 --- a/static/app-strings.json +++ b/static/app-strings.json @@ -1324,6 +1324,7 @@ "I like this": "I like this", "I dislike this": "I dislike this", "Not interested": "Not interested", + "Also, don't recommend channel": "Also, don't recommend channel", "Let %channel% know you enjoyed this!": "Let %channel% know you enjoyed this!", "An account with %domain% allows you to earn rewards and backup your data.": "An account with %domain% allows you to earn rewards and backup your data.", "Sync my YouTube channel": "Sync my YouTube channel", diff --git a/ui/constants/modal_types.js b/ui/constants/modal_types.js index c47777973..4b7b830f5 100644 --- a/ui/constants/modal_types.js +++ b/ui/constants/modal_types.js @@ -48,3 +48,4 @@ export const CONFIRM_REMOVE_CARD = 'CONFIRM_REMOVE_CARD'; export const CONFIRM_REMOVE_COMMENT = 'CONFIRM_REMOVE_COMMENT'; export const CONFIRM_ODYSEE_MEMBERSHIP = 'CONFIRM_ODYSEE_MEMBERSHIP'; export const MEMBERSHIP_SPLASH = 'MEMBERSHIP_SPLASH'; +export const HIDE_RECOMMENDATION = 'HIDE_RECOMMENDATION'; diff --git a/ui/modal/modalHideRecommendation/index.js b/ui/modal/modalHideRecommendation/index.js new file mode 100644 index 000000000..e663db13e --- /dev/null +++ b/ui/modal/modalHideRecommendation/index.js @@ -0,0 +1,9 @@ +import { connect } from 'react-redux'; +import { doHideModal } from 'redux/actions/app'; +import ModalHideRecommendation from './view'; + +const perform = { + doHideModal, +}; + +export default connect(null, perform)(ModalHideRecommendation); diff --git a/ui/modal/modalHideRecommendation/view.jsx b/ui/modal/modalHideRecommendation/view.jsx new file mode 100644 index 000000000..76f25c1b9 --- /dev/null +++ b/ui/modal/modalHideRecommendation/view.jsx @@ -0,0 +1,55 @@ +// @flow +import React from 'react'; +import Button from 'component/button'; +import ClaimPreview from 'component/claimPreview'; +import Card from 'component/common/card'; +import { FormField } from 'component/common/form-components/form-field'; +import { Modal } from 'modal/modal'; + +type Props = { + uri: string, + onConfirm: (hideChannel: boolean) => void, + doHideModal: () => void, +}; + +export default function ModalHideRecommendation(props: Props) { + const { uri, onConfirm, doHideModal } = props; + const [hideChannel, setHideChannel] = React.useState(false); + + function handleOnClick() { + if (onConfirm) { + onConfirm(hideChannel); + } + doHideModal(); + } + + return ( + + + + + } + actions={ + <> +
+ setHideChannel(!hideChannel)} + /> +
+
+
+ + } + /> +
+ ); +} diff --git a/ui/modal/modalRouter/view.jsx b/ui/modal/modalRouter/view.jsx index e561cccbd..43052b3a7 100644 --- a/ui/modal/modalRouter/view.jsx +++ b/ui/modal/modalRouter/view.jsx @@ -28,6 +28,7 @@ const MAP = Object.freeze({ [MODALS.FILE_SELECTION]: lazyImport(() => import('modal/modalFileSelection' /* webpackChunkName: "modalFileSelection" */)), [MODALS.FILE_TIMEOUT]: lazyImport(() => import('modal/modalFileTimeout' /* webpackChunkName: "modalFileTimeout" */)), [MODALS.FIRST_REWARD]: lazyImport(() => import('modal/modalFirstReward' /* webpackChunkName: "modalFirstReward" */)), + [MODALS.HIDE_RECOMMENDATION]: lazyImport(() => import('modal/modalHideRecommendation' /* webpackChunkName: "modalHideRecommendation" */)), [MODALS.IMAGE_UPLOAD]: lazyImport(() => import('modal/modalImageUpload' /* webpackChunkName: "modalImageUpload" */)), [MODALS.LIQUIDATE_SUPPORTS]: lazyImport(() => import('modal/modalSupportsLiquidate' /* webpackChunkName: "modalSupportsLiquidate" */)), [MODALS.MASS_TIP_UNLOCK]: lazyImport(() => import('modal/modalMassTipUnlock' /* webpackChunkName: "modalMassTipUnlock" */)), diff --git a/ui/redux/actions/search.js b/ui/redux/actions/search.js index 545bec2d6..13a16829c 100644 --- a/ui/redux/actions/search.js +++ b/ui/redux/actions/search.js @@ -1,5 +1,7 @@ // @flow import * as ACTIONS from 'constants/action_types'; +import * as MODALS from 'constants/modal_types'; +import { doOpenModal } from 'redux/actions/app'; import { doToast } from 'redux/actions/notifications'; import { selectShowMatureContent } from 'redux/selectors/settings'; import { selectClaimForUri, selectClaimIdForUri, selectClaimIsNsfwForUri } from 'redux/selectors/claims'; @@ -46,8 +48,13 @@ const recsysFyp = { }); }, - ignoreRecommendation: (userId: string, gid: string, claimId: string) => { - return fetch(`${RECSYS_FYP_ENDPOINT}/${userId}/fyp/${gid}/c/${claimId}/ignore`, { + ignoreRecommendation: (userId: string, gid: string, claimId: string, ignoreChannel: boolean) => { + let endpoint = `${RECSYS_FYP_ENDPOINT}/${userId}/fyp/${gid}/c/${claimId}/ignore`; + if (ignoreChannel) { + endpoint += '?entire_channel=1'; + } + + return fetch(endpoint, { method: 'POST', headers: { [X_LBRY_AUTH_TOKEN]: getAuthToken() }, }) @@ -281,15 +288,22 @@ export const doRemovePersonalRecommendation = (uri: string) => (dispatch: Dispat return; } - recsysFyp - .ignoreRecommendation(user.id, personalRecommendations.gid, claimId) - .then((res) => { - dispatch({ type: ACTIONS.FYP_HIDE_URI, data: { uri } }); - dispatch(doToast({ message: __('Recommendation removed. Thanks for the feedback!') })); + dispatch( + doOpenModal(MODALS.HIDE_RECOMMENDATION, { + uri, + onConfirm: (hideChannel) => { + recsysFyp + .ignoreRecommendation(user.id, personalRecommendations.gid, claimId, hideChannel) + .then((res) => { + dispatch({ type: ACTIONS.FYP_HIDE_URI, data: { uri } }); + dispatch(doToast({ message: __('Recommendation removed. Thanks for the feedback!') })); + }) + .catch((err) => { + console.log('doRemovePersonalRecommendation:', err); + }); + }, }) - .catch((err) => { - console.log('doRemovePersonalRecommendation:', err); - }); + ); }; export { lighthouse, recsysFyp };