2018-07-25 02:50:04 +02:00
|
|
|
// @flow
|
2021-01-22 00:57:29 +01:00
|
|
|
import { SHOW_ADS, SIMPLE_SITE } from 'config';
|
2018-07-25 02:50:04 +02:00
|
|
|
import React from 'react';
|
2019-06-19 07:05:43 +02:00
|
|
|
import ClaimList from 'component/claimList';
|
2020-05-07 20:44:11 +02:00
|
|
|
import Ads from 'web/component/ads';
|
2020-04-29 21:31:11 +02:00
|
|
|
import Card from 'component/common/card';
|
2020-08-25 15:49:19 +02:00
|
|
|
import { useIsMobile, useIsMediumScreen } from 'effects/use-screensize';
|
2018-07-25 02:50:04 +02:00
|
|
|
|
2020-01-28 23:05:44 +01:00
|
|
|
type Options = {
|
|
|
|
related_to: string,
|
|
|
|
nsfw?: boolean,
|
|
|
|
};
|
|
|
|
|
2018-07-25 02:50:04 +02:00
|
|
|
type Props = {
|
2018-07-25 06:45:24 +02:00
|
|
|
uri: string,
|
2019-04-24 16:02:08 +02:00
|
|
|
claim: ?StreamClaim,
|
2018-08-03 20:28:11 +02:00
|
|
|
recommendedContent: Array<string>,
|
2018-08-27 05:18:57 +02:00
|
|
|
isSearching: boolean,
|
2020-01-28 23:05:44 +01:00
|
|
|
search: (string, Options) => void,
|
|
|
|
mature: boolean,
|
2020-03-26 22:47:07 +01:00
|
|
|
isAuthenticated: boolean,
|
2018-07-25 02:50:04 +02:00
|
|
|
};
|
|
|
|
|
2020-08-25 15:49:19 +02:00
|
|
|
export default function RecommendedContent(props: Props) {
|
2021-01-27 00:45:34 +01:00
|
|
|
const { uri, claim, search, mature, recommendedContent, isSearching, isAuthenticated } = props;
|
2020-08-25 15:49:19 +02:00
|
|
|
const isMobile = useIsMobile();
|
|
|
|
const isMedium = useIsMediumScreen();
|
2018-07-25 06:45:24 +02:00
|
|
|
|
2020-12-01 18:56:59 +01:00
|
|
|
const stringifiedClaim = JSON.stringify(claim);
|
|
|
|
const getRecommendedContent = React.useCallback(() => {
|
|
|
|
if (stringifiedClaim) {
|
|
|
|
const jsonClaim = JSON.parse(stringifiedClaim);
|
|
|
|
if (jsonClaim && jsonClaim.value && jsonClaim.claim_id) {
|
|
|
|
const options: Options = { size: 20, related_to: jsonClaim.claim_id, isBackgroundSearch: true };
|
|
|
|
if (jsonClaim && !mature) {
|
|
|
|
options['nsfw'] = false;
|
|
|
|
}
|
|
|
|
const { title } = jsonClaim.value;
|
|
|
|
if (title && options) {
|
|
|
|
search(title, options);
|
|
|
|
}
|
2019-04-24 16:02:08 +02:00
|
|
|
}
|
2018-07-25 06:45:24 +02:00
|
|
|
}
|
2020-12-01 18:56:59 +01:00
|
|
|
}, [stringifiedClaim, mature]);
|
2018-08-03 20:28:11 +02:00
|
|
|
|
2020-08-25 15:49:19 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
getRecommendedContent();
|
|
|
|
}, [uri]);
|
2018-08-09 18:41:14 +02:00
|
|
|
|
2020-08-25 15:49:19 +02:00
|
|
|
return (
|
|
|
|
<Card
|
|
|
|
isBodyList
|
|
|
|
smallTitle={!isMobile && !isMedium}
|
|
|
|
className="file-page__recommended"
|
|
|
|
title={__('Related')}
|
|
|
|
body={
|
|
|
|
<ClaimList
|
|
|
|
type="small"
|
|
|
|
loading={isSearching}
|
|
|
|
uris={recommendedContent}
|
2021-03-04 07:03:58 +01:00
|
|
|
hideMenu={isMobile}
|
2021-01-23 22:21:25 +01:00
|
|
|
injectedItem={
|
|
|
|
SHOW_ADS && IS_WEB ? (
|
|
|
|
SIMPLE_SITE ? (
|
2021-01-31 04:47:06 +01:00
|
|
|
<Ads small type={'google'} uri={uri} />
|
2021-01-23 22:21:25 +01:00
|
|
|
) : (
|
2021-01-27 00:45:34 +01:00
|
|
|
!isAuthenticated && <Ads small type={'video'} />
|
2021-01-23 22:21:25 +01:00
|
|
|
)
|
|
|
|
) : (
|
|
|
|
false
|
|
|
|
)
|
|
|
|
}
|
2020-08-25 15:49:19 +02:00
|
|
|
empty={__('No related content found')}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
2018-07-25 02:50:04 +02:00
|
|
|
}
|