2018-07-24 20:50:04 -04:00
|
|
|
// @flow
|
2021-01-21 18:57:29 -05:00
|
|
|
import { SHOW_ADS, SIMPLE_SITE } from 'config';
|
2018-07-24 20:50:04 -04:00
|
|
|
import React from 'react';
|
2019-06-19 01:05:43 -04:00
|
|
|
import ClaimList from 'component/claimList';
|
2020-05-07 14:44:11 -04:00
|
|
|
import Ads from 'web/component/ads';
|
2020-04-29 15:31:11 -04:00
|
|
|
import Card from 'component/common/card';
|
2020-08-25 09:49:19 -04:00
|
|
|
import { useIsMobile, useIsMediumScreen } from 'effects/use-screensize';
|
2018-07-24 20:50:04 -04:00
|
|
|
|
|
|
|
type Props = {
|
2018-07-25 00:45:24 -04:00
|
|
|
uri: string,
|
2018-08-03 14:28:11 -04:00
|
|
|
recommendedContent: Array<string>,
|
2021-03-19 11:16:05 +08:00
|
|
|
nextRecommendedUri: string,
|
2018-08-26 23:18:57 -04:00
|
|
|
isSearching: boolean,
|
2021-03-19 23:04:12 +08:00
|
|
|
doFetchRecommendedContent: (string, boolean) => void,
|
2020-01-28 17:05:44 -05:00
|
|
|
mature: boolean,
|
2020-03-26 17:47:07 -04:00
|
|
|
isAuthenticated: boolean,
|
2018-07-24 20:50:04 -04:00
|
|
|
};
|
|
|
|
|
2020-08-25 09:49:19 -04:00
|
|
|
export default function RecommendedContent(props: Props) {
|
2021-03-19 23:04:12 +08:00
|
|
|
const {
|
|
|
|
uri,
|
|
|
|
doFetchRecommendedContent,
|
|
|
|
mature,
|
|
|
|
recommendedContent,
|
|
|
|
nextRecommendedUri,
|
|
|
|
isSearching,
|
|
|
|
isAuthenticated,
|
|
|
|
} = props;
|
2020-08-25 09:49:19 -04:00
|
|
|
const isMobile = useIsMobile();
|
|
|
|
const isMedium = useIsMediumScreen();
|
2018-07-25 00:45:24 -04:00
|
|
|
|
2021-03-19 11:16:05 +08:00
|
|
|
function reorderList(recommendedContent) {
|
|
|
|
let newList = recommendedContent;
|
|
|
|
if (newList) {
|
|
|
|
const index = newList.indexOf(nextRecommendedUri);
|
|
|
|
if (index === -1) {
|
|
|
|
// This would be weird. Shouldn't happen since it is derived from the same list.
|
|
|
|
} else if (index !== 0) {
|
|
|
|
// Swap the "next" item to the top of the list
|
|
|
|
const a = newList[0];
|
|
|
|
newList[0] = nextRecommendedUri;
|
|
|
|
newList[index] = a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newList;
|
|
|
|
}
|
|
|
|
|
2020-08-25 09:49:19 -04:00
|
|
|
React.useEffect(() => {
|
2021-03-19 23:04:12 +08:00
|
|
|
doFetchRecommendedContent(uri, mature);
|
|
|
|
}, [uri, mature, doFetchRecommendedContent]);
|
2018-08-09 12:41:14 -04:00
|
|
|
|
2020-08-25 09:49:19 -04:00
|
|
|
return (
|
|
|
|
<Card
|
|
|
|
isBodyList
|
|
|
|
smallTitle={!isMobile && !isMedium}
|
|
|
|
className="file-page__recommended"
|
|
|
|
title={__('Related')}
|
|
|
|
body={
|
|
|
|
<ClaimList
|
|
|
|
type="small"
|
|
|
|
loading={isSearching}
|
2021-03-19 11:16:05 +08:00
|
|
|
uris={reorderList(recommendedContent)}
|
2021-03-04 01:03:58 -05:00
|
|
|
hideMenu={isMobile}
|
2021-01-23 16:21:25 -05:00
|
|
|
injectedItem={
|
|
|
|
SHOW_ADS && IS_WEB ? (
|
|
|
|
SIMPLE_SITE ? (
|
2021-01-30 22:47:06 -05:00
|
|
|
<Ads small type={'google'} uri={uri} />
|
2021-01-23 16:21:25 -05:00
|
|
|
) : (
|
2021-01-26 18:45:34 -05:00
|
|
|
!isAuthenticated && <Ads small type={'video'} />
|
2021-01-23 16:21:25 -05:00
|
|
|
)
|
|
|
|
) : (
|
|
|
|
false
|
|
|
|
)
|
|
|
|
}
|
2020-08-25 09:49:19 -04:00
|
|
|
empty={__('No related content found')}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
2018-07-24 20:50:04 -04:00
|
|
|
}
|