2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2021-07-23 08:10:41 +02:00
|
|
|
import { URL, SHARE_DOMAIN_URL, SITE_NAME, ENABLE_FILE_REACTIONS } from 'config';
|
2020-06-08 20:42:29 +02:00
|
|
|
import * as PAGES from 'constants/pages';
|
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';
|
2021-06-10 20:23:25 +02:00
|
|
|
import { buildURI, COLLECTIONS_CONSTS } from 'lbry-redux';
|
2020-04-01 20:43:50 +02:00
|
|
|
import * as RENDER_MODES from 'constants/file_render_modes';
|
2020-08-10 22:47:39 +02:00
|
|
|
import { useIsMobile } from 'effects/use-screensize';
|
2020-06-08 20:42:29 +02:00
|
|
|
import ClaimSupportButton from 'component/claimSupportButton';
|
wip
wip
wip - everything but publish, autoplay, and styling
collection publishing
add channel to collection publish
cleanup
wip
bump
clear mass add after success
move collection item management controls
redirect replace to published collection id
bump
playlist selector on create
bump
use new collection add ui element
bump
wip
gitignore
add content json
wip
bump
context add to playlist
basic collections page style pass wip
wip: edits, buttons, styles...
change fileAuthor to claimAuthor
update, pending bugfixes, delete modal progress, collection header, other bugfixes
bump
cleaning
show page bugfix
builtin collection headers
no playlists, no grid title
wip
style tweaks
use normal looking claim previews for collection tiles
add collection changes
style library previews
collection menulist for delete/view on library
delete modal works for unpublished
rearrange collection publish tabs
clean up collection publishing and items
show on odysee
begin collectoin edit header and css renaming
better thumbnails
bump
fix collection publish redirect
view collection in menu does something
copy and thumbs
list previews, pending, context menus, list page
enter to add collection, lists page empty state
playable lists only, delete feature, bump
put fileListDownloaded back
better collection titles
improve collection claim details
fix horiz more icon
fix up channel page
style, copy, bump
refactor preview overlay properties,
fix reposts showing as floppydisk
add watch later toast,
small overlay properties on wunderbar results,
fix collection actions buttons
bump
cleanup
cleaning, refactoring
bump
preview thumb styling, cleanup
support discover page lists search
sync, bump
bump, fix sync more
enforce builtin order for now
new lists page empty state
try to indicate unpublished edits in lists
bump
fix autoplay and linting
consts, fix autoplay
bugs
fixes
cleanup
fix, bump
lists experimental ui, fixes
refactor listIndex out
hack in collection fallback thumb
bump
2021-02-06 08:03:51 +01:00
|
|
|
import ClaimCollectionAddButton from 'component/claimCollectionAddButton';
|
2020-09-17 19:11:19 +02:00
|
|
|
import { useHistory } from 'react-router';
|
2020-10-02 21:18:53 +02:00
|
|
|
import FileReactions from 'component/fileReactions';
|
2021-06-18 15:56:20 +02:00
|
|
|
import { Menu, MenuButton, MenuList, MenuItem } from '@reach/menu-button';
|
|
|
|
import Icon from 'component/common/icon';
|
|
|
|
import { webDownloadClaim } from 'util/downloadClaim';
|
2021-07-23 08:10:41 +02:00
|
|
|
import { generateShareUrl, generateLbryContentUrl } from 'util/url';
|
|
|
|
|
|
|
|
const SHARE_DOMAIN = SHARE_DOMAIN_URL || URL;
|
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,
|
2020-09-17 19:11:19 +02:00
|
|
|
myChannels: ?Array<ChannelClaim>,
|
|
|
|
doToast: ({ message: string }) => void,
|
|
|
|
clearPlayingUri: () => void,
|
2021-07-21 23:09:56 +02:00
|
|
|
hideRepost?: boolean,
|
2021-03-26 22:03:52 +01:00
|
|
|
isLivestreamClaim: boolean,
|
2021-06-03 17:55:16 +02:00
|
|
|
reactionsDisabled: boolean,
|
2021-06-18 15:56:20 +02:00
|
|
|
download: (string) => void,
|
|
|
|
streamingUrl: ?string,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
2020-01-06 19:32:35 +01:00
|
|
|
function FileActions(props: Props) {
|
2020-09-17 19:11:19 +02:00
|
|
|
const {
|
|
|
|
fileInfo,
|
|
|
|
uri,
|
|
|
|
openModal,
|
|
|
|
claimIsMine,
|
|
|
|
claim,
|
|
|
|
costInfo,
|
|
|
|
renderMode,
|
|
|
|
prepareEdit,
|
|
|
|
myChannels,
|
|
|
|
clearPlayingUri,
|
|
|
|
doToast,
|
2021-07-21 23:09:56 +02:00
|
|
|
hideRepost,
|
2021-03-26 22:03:52 +01:00
|
|
|
isLivestreamClaim,
|
2021-06-03 17:55:16 +02:00
|
|
|
reactionsDisabled,
|
2021-06-18 15:56:20 +02:00
|
|
|
download,
|
|
|
|
streamingUrl,
|
2020-09-17 19:11:19 +02:00
|
|
|
} = props;
|
|
|
|
const {
|
|
|
|
push,
|
2021-06-10 20:23:25 +02:00
|
|
|
location: { pathname, search },
|
2020-09-17 19:11:19 +02:00
|
|
|
} = useHistory();
|
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));
|
2020-09-17 19:11:19 +02:00
|
|
|
const hasChannels = myChannels && myChannels.length > 0;
|
2020-01-06 19:32:35 +01:00
|
|
|
const claimId = claim && claim.claim_id;
|
|
|
|
const { signing_channel: signingChannel } = claim;
|
|
|
|
const channelName = signingChannel && signingChannel.name;
|
2021-06-18 15:56:20 +02:00
|
|
|
const fileName = claim && claim.value && claim.value.source && claim.value.source.name;
|
2021-07-23 08:10:41 +02:00
|
|
|
const lbryUrl = generateLbryContentUrl(claim.canonical_url, claim.permanent_url);
|
|
|
|
const shareUrl = generateShareUrl(SHARE_DOMAIN, lbryUrl);
|
2021-06-18 15:56:20 +02:00
|
|
|
|
2020-01-06 19:32:35 +01:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2021-06-10 20:23:25 +02:00
|
|
|
const urlParams = new URLSearchParams(search);
|
|
|
|
const collectionId = urlParams.get(COLLECTIONS_CONSTS.COLLECTION_ID);
|
|
|
|
|
2021-06-18 15:56:20 +02:00
|
|
|
// @if TARGET='web'
|
|
|
|
const [downloadClicked, setDownloadClicked] = React.useState(false);
|
|
|
|
|
|
|
|
function handleWebDownload() {
|
|
|
|
// download() causes 'streamingUrl' to be populated.
|
|
|
|
download(uri);
|
|
|
|
setDownloadClicked(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (downloadClicked && streamingUrl) {
|
|
|
|
webDownloadClaim(streamingUrl, fileName);
|
|
|
|
}
|
|
|
|
}, [downloadClicked, streamingUrl, fileName]);
|
|
|
|
// @endif
|
|
|
|
|
2020-09-17 19:11:19 +02:00
|
|
|
function handleRepostClick() {
|
|
|
|
if (!hasChannels) {
|
|
|
|
clearPlayingUri();
|
|
|
|
push(`/$/${PAGES.CHANNEL_NEW}?redirect=${pathname}`);
|
|
|
|
doToast({ message: __('A channel is required to repost on %SITE_NAME%', { SITE_NAME }) });
|
|
|
|
} else {
|
2021-01-13 17:43:45 +01:00
|
|
|
push(`/$/${PAGES.REPOST_NEW}?from=${encodeURIComponent(uri)}&redirect=${pathname}`);
|
2020-09-17 19:11:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-23 08:10:41 +02:00
|
|
|
function handleOpenInWeb() {
|
|
|
|
window.open(shareUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleOpenInDesktop() {
|
|
|
|
window.open(claim.permanent_url);
|
|
|
|
}
|
|
|
|
|
2020-09-03 03:08:25 +02:00
|
|
|
const lhsSection = (
|
|
|
|
<>
|
2021-07-21 23:09:56 +02:00
|
|
|
{ENABLE_FILE_REACTIONS && !reactionsDisabled && <FileReactions uri={uri} livestream={isLivestreamClaim} />}
|
2020-09-30 22:46:20 +02:00
|
|
|
<ClaimSupportButton uri={uri} fileAction />
|
2021-06-16 00:14:56 +02:00
|
|
|
<ClaimCollectionAddButton uri={uri} fileAction />
|
2021-07-21 23:09:56 +02:00
|
|
|
{!hideRepost && (
|
|
|
|
<Button
|
|
|
|
button="alt"
|
|
|
|
className="button--file-action"
|
|
|
|
icon={ICONS.REPOST}
|
|
|
|
label={
|
|
|
|
claim.meta.reposted > 1 ? __(`%repost_total% Reposts`, { repost_total: claim.meta.reposted }) : __('Repost')
|
|
|
|
}
|
|
|
|
description={__('Repost')}
|
|
|
|
requiresAuth={IS_WEB}
|
|
|
|
onClick={handleRepostClick}
|
|
|
|
/>
|
|
|
|
)}
|
2020-09-30 22:46:20 +02:00
|
|
|
<Button
|
|
|
|
className="button--file-action"
|
2020-09-03 03:08:25 +02:00
|
|
|
icon={ICONS.SHARE}
|
2021-07-21 23:09:56 +02:00
|
|
|
label={isMobile ? undefined : __('Share')}
|
2020-10-02 06:47:54 +02:00
|
|
|
title={__('Share')}
|
2021-06-10 20:23:25 +02:00
|
|
|
onClick={() => openModal(MODALS.SOCIAL_SHARE, { uri, webShareable, collectionId })}
|
2020-09-03 03:08:25 +02:00
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
2020-01-06 19:32:35 +01:00
|
|
|
|
2020-09-03 03:08:25 +02:00
|
|
|
const rhsSection = (
|
|
|
|
<>
|
2021-06-18 15:56:20 +02:00
|
|
|
{/* @if TARGET='app' */}
|
|
|
|
<FileDownloadLink uri={uri} />
|
|
|
|
{/* @endif */}
|
2020-09-03 03:08:25 +02:00
|
|
|
{claimIsMine && (
|
|
|
|
<Button
|
2020-09-30 22:46:20 +02:00
|
|
|
className="button--file-action"
|
2020-09-03 03:08:25 +02:00
|
|
|
icon={ICONS.EDIT}
|
2021-04-14 06:06:11 +02:00
|
|
|
label={isLivestreamClaim ? __('Update') : __('Edit')}
|
|
|
|
navigate={`/$/${PAGES.UPLOAD}`}
|
2021-03-26 22:03:52 +01:00
|
|
|
onClick={() => {
|
|
|
|
prepareEdit(claim, editUri, fileInfo);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
2020-09-03 03:08:25 +02:00
|
|
|
{showDelete && (
|
|
|
|
<Button
|
|
|
|
title={__('Remove from your library')}
|
2020-09-30 22:46:20 +02:00
|
|
|
className="button--file-action"
|
2020-09-03 03:08:25 +02:00
|
|
|
icon={ICONS.DELETE}
|
|
|
|
description={__('Delete')}
|
|
|
|
onClick={() => openModal(MODALS.CONFIRM_FILE_REMOVE, { uri })}
|
|
|
|
/>
|
|
|
|
)}
|
2021-07-18 17:10:34 +02:00
|
|
|
{(!isLivestreamClaim || !claimIsMine) && (
|
|
|
|
<Menu>
|
|
|
|
<MenuButton
|
|
|
|
className="button--file-action"
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Icon size={20} icon={ICONS.MORE} />
|
|
|
|
</MenuButton>
|
|
|
|
<MenuList className="menu__list">
|
|
|
|
{/* @if TARGET='web' */}
|
|
|
|
{!isLivestreamClaim && (
|
|
|
|
<MenuItem className="comment__menu-option" onSelect={handleWebDownload}>
|
|
|
|
<div className="menu__link">
|
|
|
|
<Icon aria-hidden icon={ICONS.DOWNLOAD} />
|
|
|
|
{__('Download')}
|
|
|
|
</div>
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
{/* @endif */}
|
2021-07-23 08:10:41 +02:00
|
|
|
<MenuItem className="comment__menu-option" onSelect={IS_WEB ? handleOpenInDesktop : handleOpenInWeb}>
|
|
|
|
<div className="menu__link">
|
|
|
|
<Icon aria-hidden icon={IS_WEB ? ICONS.DESKTOP : ICONS.WEB} />
|
|
|
|
{IS_WEB ? __('Open in Desktop') : __('Open in Web')}
|
|
|
|
</div>
|
|
|
|
</MenuItem>
|
2021-07-18 17:10:34 +02:00
|
|
|
{!claimIsMine && (
|
|
|
|
<MenuItem
|
|
|
|
className="comment__menu-option"
|
|
|
|
onSelect={() => push(`/$/${PAGES.REPORT_CONTENT}?claimId=${claimId}`)}
|
|
|
|
>
|
|
|
|
<div className="menu__link">
|
|
|
|
<Icon aria-hidden icon={ICONS.REPORT} />
|
|
|
|
{__('Report content')}
|
|
|
|
</div>
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
</MenuList>
|
|
|
|
</Menu>
|
|
|
|
)}
|
2020-09-03 03:08:25 +02:00
|
|
|
</>
|
2020-01-06 19:32:35 +01:00
|
|
|
);
|
2020-09-03 03:08:25 +02:00
|
|
|
|
|
|
|
if (isMobile) {
|
|
|
|
return (
|
|
|
|
<div className="media__actions">
|
|
|
|
{lhsSection}
|
|
|
|
{rhsSection}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<div className="media__actions">
|
2020-10-05 19:38:40 +02:00
|
|
|
<div className="section__actions section__actions--no-margin">
|
|
|
|
{lhsSection}
|
|
|
|
{rhsSection}
|
|
|
|
</div>
|
2020-09-03 03:08:25 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-04-29 19:02:25 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
export default FileActions;
|