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

122 lines
3.7 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import * as MODALS from 'constants/modal_types';
import * as ICONS from 'constants/icons';
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';
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 },
contentType: string,
supportOption: boolean,
2018-03-26 23:32:43 +02:00
};
2020-01-06 19:32:35 +01:00
function FileActions(props: Props) {
const { fileInfo, uri, openModal, claimIsMine, claim, costInfo, contentType, supportOption, prepareEdit } = props;
const webShareable =
costInfo && costInfo.cost === 0 && contentType && ['video', 'image', 'audio'].includes(contentType.split('/')[0]);
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);
}
return (
<div className="media__actions">
<div className="section__actions">
<Button
button="alt"
icon={ICONS.SHARE}
label={__('Share')}
onClick={() => openModal(MODALS.SOCIAL_SHARE, { uri, webShareable })}
/>
2020-02-06 19:49:05 +01:00
<Button
button="alt"
icon={ICONS.REPOST}
label={__('Repost')}
2020-02-13 15:45:41 +01:00
requiresAuth={IS_WEB}
2020-02-06 19:49:05 +01:00
onClick={() => openModal(MODALS.REPOST, { uri })}
/>
2020-01-06 19:32:35 +01:00
{!claimIsMine && (
<Button
button="alt"
icon={ICONS.TIP}
label={__('Tip')}
requiresAuth={IS_WEB}
title={__('Send a tip to this creator')}
onClick={() => openModal(MODALS.SEND_TIP, { uri, claimIsMine, isSupport: false })}
/>
)}
{(claimIsMine || (!claimIsMine && supportOption)) && (
<Button
button="alt"
icon={ICONS.SUPPORT}
label={__('Support')}
requiresAuth={IS_WEB}
title={__('Support this claim')}
onClick={() => openModal(MODALS.SEND_TIP, { uri, claimIsMine, isSupport: true })}
/>
)}
</div>
<div className="section__actions">
<FileDownloadLink uri={uri} />
{claimIsMine && (
<Button
button="alt"
icon={ICONS.EDIT}
label={__('Edit')}
navigate="/$/publish"
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
)}
{!claimIsMine && (
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-01-06 19:32:35 +01:00
</div>
</div>
);
}
2017-06-06 06:21:55 +02:00
export default FileActions;