lbry-desktop/ui/component/recommendedContent/view.jsx

66 lines
1.3 KiB
React
Raw Normal View History

// @flow
import React from 'react';
2019-06-19 01:05:43 -04:00
import ClaimList from 'component/claimList';
type Props = {
uri: string,
2019-04-24 10:02:08 -04:00
claim: ?StreamClaim,
2018-08-03 14:28:11 -04:00
recommendedContent: Array<string>,
isSearching: boolean,
2018-08-03 14:28:11 -04:00
search: string => void,
};
2018-08-13 23:52:09 -04:00
export default class RecommendedContent extends React.PureComponent<Props> {
2018-08-03 14:28:11 -04:00
constructor() {
super();
2018-08-09 12:41:14 -04:00
this.didSearch = undefined;
2018-08-03 14:28:11 -04:00
}
componentDidMount() {
2018-08-03 14:28:11 -04:00
this.getRecommendedContent();
}
2018-08-03 14:28:11 -04:00
componentDidUpdate(prevProps: Props) {
const { claim, uri } = this.props;
2018-08-03 14:28:11 -04:00
if (uri !== prevProps.uri) {
2018-08-09 12:41:14 -04:00
this.didSearch = false;
2018-08-03 14:28:11 -04:00
}
2018-08-09 12:41:14 -04:00
if (claim && !this.didSearch) {
2018-08-03 14:28:11 -04:00
this.getRecommendedContent();
}
}
2018-08-03 14:28:11 -04:00
getRecommendedContent() {
const { claim, search } = this.props;
2019-04-24 10:02:08 -04:00
if (claim && claim.value && claim.value) {
const { title } = claim.value;
if (title) {
search(title);
this.didSearch = true;
}
}
2018-08-03 14:28:11 -04:00
}
2018-08-09 12:41:14 -04:00
didSearch: ?boolean;
2018-08-03 14:28:11 -04:00
render() {
const { recommendedContent, isSearching } = this.props;
return (
2019-06-11 14:10:58 -04:00
<section className="card">
2019-06-19 01:05:43 -04:00
<ClaimList
type="small"
2019-06-11 14:10:58 -04:00
loading={isSearching}
uris={recommendedContent}
2019-07-21 17:31:22 -04:00
header={__('Related')}
2019-07-21 22:05:37 -04:00
empty={__('No related content found')}
2019-06-11 14:10:58 -04:00
/>
2018-07-25 14:21:41 -04:00
</section>
);
}
}