2018-07-25 02:50:04 +02:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
import FileTile from 'component/fileTile';
|
|
|
|
import { FormRow, FormField } from 'component/common/form';
|
|
|
|
import ToolTip from 'component/common/tooltip';
|
|
|
|
import type { Claim } from 'types/claim';
|
2018-07-25 06:45:24 +02:00
|
|
|
import { buildURI, parseURI } from 'lbry-redux';
|
2018-07-25 02:50:04 +02:00
|
|
|
|
|
|
|
type Props = {
|
2018-07-25 06:45:24 +02:00
|
|
|
uri: string,
|
2018-07-25 02:50:04 +02:00
|
|
|
channelUri: ?string,
|
|
|
|
claimsInChannel: ?Array<Claim>,
|
2018-07-25 06:23:58 +02:00
|
|
|
autoplay: boolean,
|
|
|
|
setAutoplay: boolean => void,
|
2018-07-25 02:50:04 +02:00
|
|
|
fetchClaims: (string, number) => void,
|
|
|
|
};
|
|
|
|
|
2018-07-25 06:45:24 +02:00
|
|
|
export default class RecommendedContent extends React.PureComponent<Props> {
|
2018-07-25 02:50:04 +02:00
|
|
|
componentDidMount() {
|
|
|
|
const { channelUri, fetchClaims, claimsInChannel } = this.props;
|
2018-07-25 03:10:33 +02:00
|
|
|
if (channelUri && !claimsInChannel) {
|
2018-07-25 02:50:04 +02:00
|
|
|
fetchClaims(channelUri, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-07-25 06:45:24 +02:00
|
|
|
const { claimsInChannel, autoplay, uri, setAutoplay } = this.props;
|
|
|
|
|
|
|
|
let recommendedContent;
|
|
|
|
if (claimsInChannel) {
|
|
|
|
recommendedContent = claimsInChannel.filter(claim => {
|
|
|
|
const { name, claim_id: claimId, channel_name: channelName, value } = claim;
|
|
|
|
const { isChannel } = parseURI(uri);
|
|
|
|
|
|
|
|
// The uri may include the channel name
|
|
|
|
const recommendedUri =
|
|
|
|
isChannel && value && value.publisherSignature
|
|
|
|
? buildURI({
|
|
|
|
contentName: name,
|
|
|
|
claimName: channelName,
|
|
|
|
claimId: value.publisherSignature.certificateId,
|
|
|
|
})
|
|
|
|
: buildURI({ claimName: name, claimId });
|
|
|
|
|
|
|
|
return recommendedUri !== uri;
|
|
|
|
});
|
|
|
|
}
|
2018-07-25 02:50:04 +02:00
|
|
|
|
|
|
|
return (
|
2018-07-25 20:21:41 +02:00
|
|
|
<section className="card__list--recommended">
|
2018-07-25 03:10:33 +02:00
|
|
|
<FormRow>
|
2018-07-25 02:50:04 +02:00
|
|
|
<ToolTip onComponent body={__('Automatically download and play free content.')}>
|
|
|
|
<FormField
|
|
|
|
useToggle
|
2018-07-25 20:21:41 +02:00
|
|
|
firstInList
|
2018-07-25 02:50:04 +02:00
|
|
|
name="autoplay"
|
|
|
|
type="checkbox"
|
|
|
|
prefix={__('Autoplay')}
|
2018-07-25 06:23:58 +02:00
|
|
|
checked={autoplay}
|
|
|
|
onChange={e => setAutoplay(e.target.checked)}
|
2018-07-25 02:50:04 +02:00
|
|
|
/>
|
|
|
|
</ToolTip>
|
|
|
|
</FormRow>
|
2018-07-25 06:45:24 +02:00
|
|
|
{recommendedContent &&
|
|
|
|
recommendedContent.map(({ permanent_url: permanentUrl }) => (
|
2018-07-25 02:50:04 +02:00
|
|
|
<FileTile
|
|
|
|
small
|
|
|
|
displayDescription={false}
|
|
|
|
key={permanentUrl}
|
|
|
|
uri={`lbry://${permanentUrl}`}
|
|
|
|
/>
|
|
|
|
))}
|
2018-07-25 20:21:41 +02:00
|
|
|
</section>
|
2018-07-25 02:50:04 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|