2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2020-04-01 20:43:50 +02:00
|
|
|
import type { Node } from 'react';
|
2020-07-24 20:00:17 +02:00
|
|
|
import { SIMPLE_SITE } from 'config';
|
2020-06-08 20:42:29 +02:00
|
|
|
import * as PAGES from 'constants/pages';
|
|
|
|
import * as CS from 'constants/claim_search';
|
2018-10-29 18:23:53 +01:00
|
|
|
import * as MODALS from 'constants/modal_types';
|
|
|
|
import * as ICONS from 'constants/icons';
|
2020-04-01 20:43:50 +02:00
|
|
|
import React from 'react';
|
2018-03-26 23:32:43 +02:00
|
|
|
import Button from 'component/button';
|
2020-01-06 19:32:35 +01:00
|
|
|
import FileDownloadLink from 'component/fileDownloadLink';
|
|
|
|
import { buildURI } from 'lbry-redux';
|
2020-04-01 20:43:50 +02:00
|
|
|
import * as RENDER_MODES from 'constants/file_render_modes';
|
|
|
|
import useIsMobile from 'effects/use-is-mobile';
|
2020-06-08 20:42:29 +02:00
|
|
|
import ClaimSupportButton from 'component/claimSupportButton';
|
2017-01-13 03:03:34 +01:00
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
type Props = {
|
|
|
|
uri: string,
|
2020-01-06 19:32:35 +01:00
|
|
|
claim: StreamClaim,
|
|
|
|
openModal: (id: string, { uri: string, claimIsMine?: boolean, isSupport?: boolean }) => void,
|
|
|
|
prepareEdit: ({}, string, {}) => void,
|
2018-03-26 23:32:43 +02:00
|
|
|
claimIsMine: boolean,
|
2019-08-06 05:25:33 +02:00
|
|
|
fileInfo: FileListItem,
|
2020-01-06 19:32:35 +01:00
|
|
|
costInfo: ?{ cost: number },
|
2020-04-01 20:43:50 +02:00
|
|
|
renderMode: string,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
2020-01-06 19:32:35 +01:00
|
|
|
function FileActions(props: Props) {
|
2020-06-08 20:42:29 +02:00
|
|
|
const { fileInfo, uri, openModal, claimIsMine, claim, costInfo, renderMode, prepareEdit } = props;
|
2020-04-01 20:43:50 +02:00
|
|
|
const isMobile = useIsMobile();
|
|
|
|
const webShareable = costInfo && costInfo.cost === 0 && RENDER_MODES.WEB_SHAREABLE_MODES.includes(renderMode);
|
2020-01-06 19:32:35 +01:00
|
|
|
const showDelete = claimIsMine || (fileInfo && (fileInfo.written_bytes > 0 || fileInfo.blobs_completed > 0));
|
|
|
|
const claimId = claim && claim.claim_id;
|
|
|
|
const { signing_channel: signingChannel } = claim;
|
|
|
|
const channelName = signingChannel && signingChannel.name;
|
|
|
|
// We want to use the short form uri for editing
|
|
|
|
// This is what the user is used to seeing, they don't care about the claim id
|
|
|
|
// We will select the claim id before they publish
|
|
|
|
let editUri;
|
|
|
|
if (claimIsMine) {
|
|
|
|
const uriObject: { streamName: string, streamClaimId: string, channelName?: string } = {
|
|
|
|
streamName: claim.name,
|
|
|
|
streamClaimId: claim.claim_id,
|
|
|
|
};
|
|
|
|
if (channelName) {
|
|
|
|
uriObject.channelName = channelName;
|
|
|
|
}
|
|
|
|
|
|
|
|
editUri = buildURI(uriObject);
|
|
|
|
}
|
|
|
|
|
2020-04-01 20:43:50 +02:00
|
|
|
const ActionWrapper = (props: { children: Node }) =>
|
|
|
|
isMobile ? (
|
|
|
|
<React.Fragment>{props.children}</React.Fragment>
|
|
|
|
) : (
|
|
|
|
<div className="section__actions section__actions--no-margin">{props.children}</div>
|
2020-03-19 17:54:37 +01:00
|
|
|
);
|
|
|
|
|
2020-01-06 19:32:35 +01:00
|
|
|
return (
|
|
|
|
<div className="media__actions">
|
2020-04-01 20:43:50 +02:00
|
|
|
<ActionWrapper>
|
2020-01-06 19:32:35 +01:00
|
|
|
<Button
|
|
|
|
button="alt"
|
|
|
|
icon={ICONS.SHARE}
|
|
|
|
label={__('Share')}
|
|
|
|
onClick={() => openModal(MODALS.SOCIAL_SHARE, { uri, webShareable })}
|
|
|
|
/>
|
|
|
|
|
2020-07-24 20:00:17 +02:00
|
|
|
{!SIMPLE_SITE && (
|
|
|
|
<div className="button-group">
|
2020-06-08 20:42:29 +02:00
|
|
|
<Button
|
|
|
|
button="alt"
|
2020-07-24 20:00:17 +02:00
|
|
|
icon={ICONS.REPOST}
|
|
|
|
label={__('Repost')}
|
2020-06-08 20:42:29 +02:00
|
|
|
requiresAuth={IS_WEB}
|
2020-07-24 20:00:17 +02:00
|
|
|
onClick={() => openModal(MODALS.REPOST, { uri })}
|
2020-06-08 20:42:29 +02:00
|
|
|
/>
|
2020-07-24 20:00:17 +02:00
|
|
|
{claim.meta.reposted > 0 && (
|
|
|
|
<Button
|
|
|
|
button="alt"
|
|
|
|
label={claim.meta.reposted}
|
|
|
|
requiresAuth={IS_WEB}
|
|
|
|
navigate={`/$/${PAGES.DISCOVER}?${CS.REPOSTED_URI_KEY}=${encodeURIComponent(uri)}`}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
2020-06-08 20:42:29 +02:00
|
|
|
<ClaimSupportButton uri={uri} />
|
2020-04-01 20:43:50 +02:00
|
|
|
</ActionWrapper>
|
2020-01-06 19:32:35 +01:00
|
|
|
|
2020-04-01 20:43:50 +02:00
|
|
|
<ActionWrapper>
|
2020-07-24 20:00:17 +02:00
|
|
|
{!SIMPLE_SITE && <FileDownloadLink uri={uri} />}
|
2020-01-06 19:32:35 +01:00
|
|
|
|
|
|
|
{claimIsMine && (
|
|
|
|
<Button
|
|
|
|
button="alt"
|
|
|
|
icon={ICONS.EDIT}
|
|
|
|
label={__('Edit')}
|
2020-07-23 19:02:07 +02:00
|
|
|
navigate="/$/upload"
|
2020-01-06 19:32:35 +01:00
|
|
|
onClick={() => {
|
|
|
|
prepareEdit(claim, editUri, fileInfo);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
2017-11-24 15:31:05 +01:00
|
|
|
{showDelete && (
|
2020-01-06 19:32:35 +01:00
|
|
|
<Button
|
|
|
|
title={__('Remove from your library')}
|
|
|
|
button="alt"
|
|
|
|
icon={ICONS.DELETE}
|
|
|
|
description={__('Delete')}
|
|
|
|
onClick={() => openModal(MODALS.CONFIRM_FILE_REMOVE, { uri })}
|
|
|
|
/>
|
2017-11-24 15:31:05 +01:00
|
|
|
)}
|
2020-07-24 20:00:17 +02:00
|
|
|
{!claimIsMine && !SIMPLE_SITE && (
|
2020-01-06 19:32:35 +01:00
|
|
|
<Button
|
|
|
|
title={__('Report content')}
|
|
|
|
button="alt"
|
|
|
|
icon={ICONS.REPORT}
|
|
|
|
href={`https://lbry.com/dmca/${claimId}`}
|
|
|
|
/>
|
2017-11-24 15:31:05 +01:00
|
|
|
)}
|
2020-04-01 20:43:50 +02:00
|
|
|
</ActionWrapper>
|
2020-01-06 19:32:35 +01:00
|
|
|
</div>
|
|
|
|
);
|
2017-04-29 19:02:25 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
export default FileActions;
|