lbry-desktop/src/renderer/component/recommendedContent/view.jsx

81 lines
1.7 KiB
React
Raw Normal View History

// @flow
import React from 'react';
import FileTile from 'component/fileTile';
import type { Claim } from 'types/claim';
type Props = {
uri: string,
2018-08-03 20:28:11 +02:00
claim: ?Claim,
recommendedContent: Array<string>,
search: string => void,
};
2018-08-03 20:28:11 +02:00
type State = {
didSearch: boolean,
};
export default class RecommendedContent extends React.PureComponent<Props, State> {
constructor() {
super();
this.state = {
didSearch: false,
};
}
componentDidMount() {
2018-08-03 20:28:11 +02:00
this.getRecommendedContent();
}
2018-08-03 20:28:11 +02:00
componentDidUpdate(prevProps: Props) {
const { claim, uri } = this.props;
const { didSearch } = this.state;
2018-08-03 20:28:11 +02:00
if (uri !== prevProps.uri) {
this.setState({ didSearch: false });
}
if (claim && !didSearch) {
this.getRecommendedContent();
}
}
2018-08-03 20:28:11 +02:00
getRecommendedContent() {
const { claim, search } = this.props;
2018-08-03 20:28:11 +02:00
if (claim && claim.value && claim.value.stream && claim.value.stream.metadata) {
const {
value: {
stream: {
metadata: { title },
},
},
} = claim;
// console.log("search", title)
search(title);
this.setState({ didSearch: true });
}
2018-08-03 20:28:11 +02:00
}
render() {
const { recommendedContent } = this.props;
return (
2018-07-25 20:21:41 +02:00
<section className="card__list--recommended">
<span>Related</span>
{recommendedContent &&
2018-08-03 20:28:11 +02:00
recommendedContent.length &&
recommendedContent.map(recommendedUri => (
<FileTile
small
2018-08-03 20:28:11 +02:00
hideNoResult
displayDescription={false}
2018-08-03 20:28:11 +02:00
key={recommendedUri}
uri={recommendedUri}
/>
))}
2018-07-25 20:21:41 +02:00
</section>
);
}
}