2018-03-26 14:32:43 -07:00
|
|
|
// @flow
|
|
|
|
import * as React from 'react';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import Page from 'component/page';
|
2019-11-14 15:31:38 -05:00
|
|
|
import I18nMessage from 'component/i18nMessage/view';
|
2020-01-06 13:32:35 -05:00
|
|
|
import LayoutWrapperFile from 'component/layoutWrapperFile';
|
|
|
|
import LayoutWrapperText from 'component/layoutWrapperText';
|
2019-08-13 01:35:13 -04:00
|
|
|
|
2018-03-26 14:32:43 -07:00
|
|
|
type Props = {
|
2019-04-24 10:02:08 -04:00
|
|
|
claim: StreamClaim,
|
|
|
|
fileInfo: FileListItem,
|
2018-03-26 14:32:43 -07:00
|
|
|
uri: string,
|
|
|
|
claimIsMine: boolean,
|
2019-05-02 14:29:45 -04:00
|
|
|
costInfo: ?{ cost: number },
|
2018-03-26 14:32:43 -07:00
|
|
|
fetchFileInfo: string => void,
|
|
|
|
fetchCostInfo: string => void,
|
2018-10-10 01:22:06 -04:00
|
|
|
setViewed: string => void,
|
2018-10-19 16:38:07 -04:00
|
|
|
isSubscribed: ?string,
|
|
|
|
isSubscribed: boolean,
|
|
|
|
channelUri: string,
|
2019-03-14 14:40:26 -04:00
|
|
|
viewCount: number,
|
2018-10-19 16:38:07 -04:00
|
|
|
markSubscriptionRead: (string, string) => void,
|
2019-03-14 14:40:26 -04:00
|
|
|
fetchViewCount: string => void,
|
2019-04-03 00:17:00 -04:00
|
|
|
balance: number,
|
2020-01-06 15:57:49 -05:00
|
|
|
isText: boolean,
|
2018-03-26 14:32:43 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class FilePage extends React.Component<Props> {
|
2017-05-12 18:50:51 -04:00
|
|
|
componentDidMount() {
|
2019-09-26 23:52:04 -04:00
|
|
|
const { uri, claim, fetchFileInfo, fetchCostInfo, setViewed, isSubscribed, fetchViewCount } = this.props;
|
2018-10-19 16:38:07 -04:00
|
|
|
|
2019-05-02 14:29:45 -04:00
|
|
|
if (isSubscribed) {
|
2018-10-19 16:38:07 -04:00
|
|
|
this.removeFromSubscriptionNotifications();
|
|
|
|
}
|
2019-03-14 14:40:26 -04:00
|
|
|
|
2019-09-26 23:52:04 -04:00
|
|
|
fetchViewCount(claim.claim_id);
|
2019-03-14 14:40:26 -04:00
|
|
|
|
2019-03-15 12:15:31 -04:00
|
|
|
// always refresh file info when entering file page to see if we have the file
|
|
|
|
// @if TARGET='app'
|
2019-02-12 12:26:50 -05:00
|
|
|
fetchFileInfo(uri);
|
2019-03-15 12:15:31 -04:00
|
|
|
// @endif
|
2017-05-12 13:14:06 -04:00
|
|
|
|
2018-07-12 14:39:12 -04:00
|
|
|
// See https://github.com/lbryio/lbry-desktop/pull/1563 for discussion
|
2018-06-07 13:47:09 -04:00
|
|
|
fetchCostInfo(uri);
|
2018-07-31 14:07:45 -04:00
|
|
|
setViewed(uri);
|
2017-05-12 13:14:06 -04:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:38:07 -04:00
|
|
|
componentDidUpdate(prevProps: Props) {
|
2019-09-26 23:52:04 -04:00
|
|
|
const { isSubscribed, claim, uri, fileInfo, setViewed, fetchViewCount, fetchFileInfo } = this.props;
|
2019-03-14 14:40:26 -04:00
|
|
|
|
2019-05-02 14:29:45 -04:00
|
|
|
if (!prevProps.isSubscribed && isSubscribed) {
|
2018-10-19 16:38:07 -04:00
|
|
|
this.removeFromSubscriptionNotifications();
|
|
|
|
}
|
2019-03-14 14:40:26 -04:00
|
|
|
|
2019-09-26 23:52:04 -04:00
|
|
|
if (prevProps.uri !== uri) {
|
2019-03-14 14:40:26 -04:00
|
|
|
fetchViewCount(claim.claim_id);
|
|
|
|
}
|
2019-05-29 13:35:46 -06:00
|
|
|
|
2019-06-11 14:10:58 -04:00
|
|
|
if (prevProps.uri !== uri) {
|
|
|
|
setViewed(uri);
|
|
|
|
}
|
|
|
|
|
2019-05-29 13:35:46 -06:00
|
|
|
// @if TARGET='app'
|
|
|
|
if (fileInfo === undefined) {
|
|
|
|
fetchFileInfo(uri);
|
|
|
|
}
|
|
|
|
// @endif
|
2018-10-19 16:38:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
removeFromSubscriptionNotifications() {
|
|
|
|
// Always try to remove
|
|
|
|
// If it doesn't exist, nothing will happen
|
2019-05-02 14:29:45 -04:00
|
|
|
const { markSubscriptionRead, uri, channelUri } = this.props;
|
2018-10-19 16:38:07 -04:00
|
|
|
markSubscriptionRead(channelUri, uri);
|
|
|
|
}
|
2018-03-06 00:32:58 -08:00
|
|
|
|
2017-05-12 13:14:06 -04:00
|
|
|
render() {
|
2020-01-06 15:57:49 -05:00
|
|
|
const { uri, claimIsMine, costInfo, fileInfo, balance, isText } = this.props;
|
2019-04-19 13:56:58 -04:00
|
|
|
const insufficientCredits = !claimIsMine && costInfo && costInfo.cost > balance;
|
2017-05-12 13:14:06 -04:00
|
|
|
return (
|
2019-06-11 14:10:58 -04:00
|
|
|
<Page className="main--file-page">
|
2020-01-06 13:32:35 -05:00
|
|
|
{!fileInfo && insufficientCredits && (
|
|
|
|
<div className="media__insufficient-credits help--warning">
|
|
|
|
<I18nMessage
|
|
|
|
tokens={{
|
|
|
|
reward_link: <Button button="link" navigate="/$/rewards" label={__('Rewards')} />,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
The publisher has chosen to charge LBC to view this content. Your balance is currently too low to view it.
|
|
|
|
Check out %reward_link% for free LBC or send more LBC to your wallet.
|
|
|
|
</I18nMessage>
|
2019-06-17 16:32:38 -04:00
|
|
|
</div>
|
2020-01-06 13:32:35 -05:00
|
|
|
)}
|
|
|
|
|
2020-01-06 15:57:49 -05:00
|
|
|
{isText ? <LayoutWrapperText uri={uri} /> : <LayoutWrapperFile uri={uri} />}
|
2018-03-26 14:32:43 -07:00
|
|
|
</Page>
|
2017-06-06 17:19:12 -04:00
|
|
|
);
|
2017-05-12 13:14:06 -04:00
|
|
|
}
|
2017-05-05 12:10:37 +07:00
|
|
|
}
|
2017-05-01 15:59:40 -04:00
|
|
|
|
2017-05-26 02:16:25 +02:00
|
|
|
export default FilePage;
|