lbry-desktop/ui/component/fileActions/view.jsx
Rave | 図書館猫 b20b24bdb6
Publish revamp (Part 2) (#1781)
* Move menu entries & add publish buttons

* Save

* Separate publish forms

* Make new header dynamic for all screen sizes

* Save some livestream creation changes

* Save more livestream changes

* Save

* Change publish folder structure

* Update paths

* Change position of form elements. Again.

* Move, add & delete form fields

* Clean post form

* Clean post form even more

* Clean publish post component

* Save

* Add custom post form state

* Move price to additional options

* Adjust livestream form

* Adjust headers & titles

* Update key section

* Adjust active header icons

* Adjust toggle menu

* Save

* Adjust active button style

* Change active button selector in header

* Fix header menu links

* Move price section in post form

* Adjust instruction text color

* Adjust replay table

* Revert changes & adjust tag section

* Make more form elements dynamic

* Finalize additional options section

* Update post form

* Set mode in upload form

* Update livestream form

* Add clear button

* Make clear button dynamic

* Set upload mode

* Remove new button

* Clean upload form

* Show disabled key on livestream form

* Remove old key section

* Update channel selector for publish forms

* Add updated channel selector to publish forms

* Add mobile links

* Update mobile header

* Adjust channel selector on mobile

* Adjust livestream form on mobile

* Adjust edit links for livestreams

* Adjust edit links for posts

* Adjust more edit links

* Adjust channel selector

* Update disabled in livestream form

* Add missing change

* Fix sign out function

* Save

* Adjust livestream page on mobile

* Adjust tags section on upload page on mobile

* Adjust publish links in left navigation on mobile

* Add images to accepted filetypes on upload page

* Add autofocus to input fields

* Add autofocus to all publish forms

* Save

* Ignore thumbnail api status

* Put active thumbnail upload label in card

* Fix crashes

* Fix flow

* Fix licence fields

* Adjust wallet in header on smaller screens

* Fix channel selector line break on small screens

* Fix border radius for some buttons

* PublishReleaseDate: fix initial value to reflect what's actually in Redux

'undefined' is a valid value that means "use publish time", but the GUI incorrectly starts off by locking to the mounted timestamp.

* Add and hide channel selector on livestream publish page

* Fix channel selector on livestream setup page

* Fix gif aspect ratio in channel selector

* Make layout more dynamic

* Fix some edit redirects

* Save

* Clean publishFile

* Fix build errors

* Fix more build errors in profile menu button

* Remove console logs

* Remove post form reducer

* Limit publish title length to 200 characters

* Remove totalRewardValue from livestreamCreate index

* Remove console log

* Add tooltip to replay refresh button

* Remove scrollToTop function from publish forms

* Adjust emty wallet value trigger and add error to livestream publish page

* Disable some tabs in edit mode in livestream form

* Fix maxLength typo

* Remove 'as' label

* Remove selectPublishFormValues

* Reenable setup tab

* Remove inactive line

* Remove another inactive line

* Remove flow fix

* Update label switch logic in confirmation modal

Adjust gif margin

Adjust gif margin

Remove navigate from edit link

Remove manual updateLabels execution on init

Remove editLabel function

Fix labels in publish modal

Adjust post livestream setup redirect

Remove setOverMaxBitrate from livestream form

Clean livestream publish

More cleanup

Update post livestream creation redirect

Bring back edit tab for livestreams

Update edit tab

Reset form on livestream edit => clear

Update label switch logic

Readjust channel selector position on mobile

* Make some space adjustments for mobile

Update livestream edit page on mobile

Update action label on publish forms in edit mode

* Hide replay options in edit mode in livestream form

* Update label switch logic in confirmation modal

Adjust gif margin

Adjust gif margin

Remove navigate from edit link

Remove manual updateLabels execution on init

Remove editLabel function

Fix labels in publish modal

Adjust post livestream setup redirect

Remove setOverMaxBitrate from livestream form

Clean livestream publish

More cleanup

Update post livestream creation redirect

Bring back edit tab for livestreams

Update edit tab

Reset form on livestream edit => clear

Update label switch logic

Readjust channel selector position on mobile
Make some space adjustments for mobile

Update livestream edit page on mobile

Update action label on publish forms in edit mode
Hide replay options in edit mode in livestream form

* Make form titles dynamic

* Remove spinner on livestream form

* Remove console log

* Fix double history push

* Fix thumbnail status on post form

* Update error message style

* Handle publish error button behavior

* Clean code

* Fix scheduling & date picker

* Fix calendar overlap

* Add replay selector to livestream claim edit form

* Clean code

* Disable autocomplete

* Show replays in edit & replay tab

* Redesign replay picker

* Fix design details

* Save dynamic replay picker

* Fix autoComplete typo

* Change label text

* Add upload to livestream replay form

* Fix scss structure

* Add comunity guideline link to publish forms

* Fix error

* Fix selectThumbnail index

* Reset form values on replay source change

* Add replay redirect to upload page

* Fix publishError state change

* Remove label effect from publish confirmation modal

* Update labels in publish confirmation modal

* Add ? to chaptersButton

* Remove doPrepareEdit({ name })

* Bring upload redirect back

* Adjust redirects

* Save

* Update edit redirects

* Revert scheduling options

* Replace checkboxes for replays with radio

* Update form on source change

* Rearrange entries in mobile navigation

* Change key position on livestream setup page

* Change label for livestream update without replay change

* Adjust margin below label

Co-authored-by: infinite-persistence <inf.persistence@gmail.com>
2022-07-11 16:12:37 +02:00

254 lines
8.2 KiB
JavaScript

// @flow
import { useIsMobile } from 'effects/use-screensize';
import { SITE_NAME, ENABLE_FILE_REACTIONS } from 'config';
import * as PAGES from 'constants/pages';
import * as MODALS from 'constants/modal_types';
import * as ICONS from 'constants/icons';
import React from 'react';
import Button from 'component/button';
import { buildURI } from 'util/lbryURI';
import * as COLLECTIONS_CONSTS from 'constants/collections';
import * as RENDER_MODES from 'constants/file_render_modes';
import ClaimSupportButton from 'component/claimSupportButton';
import ClaimCollectionAddButton from 'component/claimCollectionAddButton';
import { useHistory } from 'react-router';
import FileReactions from 'component/fileReactions';
import { Menu, MenuButton, MenuList, MenuItem } from '@reach/menu-button';
import Icon from 'component/common/icon';
import { webDownloadClaim } from 'util/downloadClaim';
import Tooltip from 'component/common/tooltip';
type Props = {
uri: string,
hideRepost?: boolean,
// redux
claim: StreamClaim,
claimIsMine: boolean,
renderMode: string,
costInfo: ?{ cost: number },
hasChannels: boolean,
isLivestreamClaim: boolean,
isPostClaim?: boolean,
streamingUrl: ?string,
disableDownloadButton: boolean,
doOpenModal: (id: string, { uri: string, claimIsMine?: boolean, isSupport?: boolean }) => void,
doPrepareEdit: (claim: Claim, uri: string, claimType: string) => void,
doToast: (data: { message: string }) => void,
doDownloadUri: (uri: string) => void,
isMature: boolean,
isAPreorder: boolean,
};
export default function FileActions(props: Props) {
const {
uri,
claimIsMine,
claim,
costInfo,
renderMode,
hasChannels,
hideRepost,
isLivestreamClaim,
isPostClaim,
streamingUrl,
disableDownloadButton,
doOpenModal,
doPrepareEdit,
doToast,
doDownloadUri,
isMature,
isAPreorder,
} = props;
const {
push,
location: { search },
} = useHistory();
const isMobile = useIsMobile();
const [downloadClicked, setDownloadClicked] = React.useState(false);
const { claim_id: claimId, signing_channel: signingChannel, value, meta: claimMeta } = claim;
const channelName = signingChannel && signingChannel.name;
const fileName = value && value.source && value.source.name;
const claimType = isLivestreamClaim ? 'livestream' : isPostClaim ? 'post' : 'upload';
const webShareable = costInfo && costInfo.cost === 0 && RENDER_MODES.WEB_SHAREABLE_MODES.includes(renderMode);
const urlParams = new URLSearchParams(search);
const collectionId = urlParams.get(COLLECTIONS_CONSTS.COLLECTION_ID);
// 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: LbryUrlObj = {
streamName: claim.name,
streamClaimId: claim.claim_id,
};
if (channelName) {
uriObject.channelName = channelName;
}
editUri = buildURI(uriObject);
}
function handleWebDownload() {
// doDownloadUri() causes 'streamingUrl' to be populated.
doDownloadUri(uri);
setDownloadClicked(true);
}
React.useEffect(() => {
if (downloadClicked && streamingUrl) {
webDownloadClaim(streamingUrl, fileName);
setDownloadClicked(false);
}
}, [downloadClicked, streamingUrl, fileName]);
function handleRepostClick() {
if (!hasChannels) {
doToast({ message: __('A channel is required to repost on %SITE_NAME%', { SITE_NAME }) });
return;
}
doOpenModal(MODALS.REPOST, { uri });
}
return (
<div className="media__actions">
{ENABLE_FILE_REACTIONS && <FileReactions uri={uri} />}
{!isAPreorder && <ClaimSupportButton uri={uri} fileAction />}
<ClaimCollectionAddButton uri={uri} fileAction />
{!hideRepost && !isMobile && !isLivestreamClaim && (
<Tooltip title={__('Repost')} arrow={false}>
<Button
button="alt"
className="button--file-action"
icon={ICONS.REPOST}
label={
claimMeta.reposted > 1 ? __(`%repost_total% Reposts`, { repost_total: claimMeta.reposted }) : __('Repost')
}
requiresAuth
onClick={handleRepostClick}
/>
</Tooltip>
)}
<Tooltip title={__('Share')} arrow={false}>
<Button
className="button--file-action"
icon={ICONS.SHARE}
label={__('Share')}
onClick={() => doOpenModal(MODALS.SOCIAL_SHARE, { uri, webShareable, collectionId })}
/>
</Tooltip>
{claimIsMine && !isMobile && (
<>
<Tooltip title={isLivestreamClaim ? __('Update or Publish Replay') : __('Edit')} arrow={false}>
<div style={{ margin: '0px' }}>
<Button
className="button--file-action"
icon={ICONS.EDIT}
label={isLivestreamClaim ? __('Update or Publish Replay') : __('Edit')}
onClick={() => doPrepareEdit(claim, editUri, claimType)}
/>
</div>
</Tooltip>
<Tooltip title={__('Remove from your library')} arrow={false}>
<Button
className="button--file-action"
icon={ICONS.DELETE}
description={__('Delete')}
onClick={() => doOpenModal(MODALS.CONFIRM_FILE_REMOVE, { uri })}
/>
</Tooltip>
</>
)}
{(!isLivestreamClaim || !claimIsMine || isMobile) && (
<Menu>
<MenuButton
className="button--file-action--menu"
onClick={(e) => {
e.stopPropagation();
e.preventDefault();
}}
>
<Icon size={20} icon={ICONS.MORE} />
</MenuButton>
<MenuList className="menu__list">
{isMobile && (
<>
{!hideRepost && !isLivestreamClaim && (
<MenuItem className="comment__menu-option" onSelect={handleRepostClick}>
<div className="menu__link">
<Icon aria-hidden icon={ICONS.REPOST} />
{claimMeta.reposted > 1
? __(`%repost_total% Reposts`, { repost_total: claimMeta.reposted })
: __('Repost')}
</div>
</MenuItem>
)}
{claimIsMine && (
<>
<MenuItem
className="comment__menu-option"
onSelect={() => {
doPrepareEdit(claim, editUri, claimType);
push(`/$/${PAGES.UPLOAD}`);
}}
>
<div className="menu__link">
<Icon aria-hidden icon={ICONS.EDIT} />
{isLivestreamClaim ? __('Update or Publish Replay') : __('Edit')}
</div>
</MenuItem>
<MenuItem
className="comment__menu-option"
onSelect={() => doOpenModal(MODALS.CONFIRM_FILE_REMOVE, { uri })}
>
<div className="menu__link">
<Icon aria-hidden icon={ICONS.DELETE} />
{__('Delete')}
</div>
</MenuItem>
</>
)}
</>
)}
{!isLivestreamClaim && !disableDownloadButton && !isMature && (
<MenuItem className="comment__menu-option" onSelect={handleWebDownload}>
<div className="menu__link">
<Icon aria-hidden icon={ICONS.DOWNLOAD} />
{__('Download')}
</div>
</MenuItem>
)}
{!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>
)}
</div>
);
}