// @flow import React from 'react'; import moment from 'moment'; import Button from 'component/button'; import { Form, FormField } from 'component/common/form'; import { Modal } from 'modal/modal'; import Card from 'component/common/card'; import Tag from 'component/tag'; import MarkdownPreview from 'component/common/markdown-preview'; import { getLanguageName } from 'constants/languages'; import { COPYRIGHT, OTHER } from 'constants/licenses'; import LbcSymbol from 'component/common/lbc-symbol'; import ChannelThumbnail from 'component/channelThumbnail'; import * as ICONS from 'constants/icons'; import Icon from 'component/common/icon'; import { NO_FILE } from 'redux/actions/publish'; import { INTERNAL_TAGS } from 'constants/tags'; type Props = { filePath: string | WebFile, isMarkdownPost: boolean, optimize: boolean, title: ?string, description: ?string, channel: ?string, bid: ?number, uri: ?string, contentIsFree: boolean, fee: { amount: string, currency: string, }, language: string, releaseTimeEdited: ?number, licenseType: string, otherLicenseDescription: ?string, licenseUrl: ?string, tags: Array, isVid: boolean, ffmpegStatus: any, previewResponse: PublishResponse, publish: (?string, ?boolean) => void, closeModal: () => void, enablePublishPreview: boolean, setEnablePublishPreview: (boolean) => void, isStillEditing: boolean, myChannels: ?Array, publishSuccess: boolean, publishing: boolean, isLivestreamClaim: boolean, remoteFile: string, appLanguage: string, // isLivestreamPublish?: boolean, }; // class ModalPublishPreview extends React.PureComponent { const ModalPublishPreview = (props: Props) => { const { filePath, isMarkdownPost, optimize, title, description, channel, bid, uri, contentIsFree, fee, language, releaseTimeEdited, licenseType, otherLicenseDescription, licenseUrl, tags, isVid, ffmpegStatus = {}, previewResponse, enablePublishPreview, setEnablePublishPreview, isStillEditing, myChannels, publishSuccess, publishing, publish, closeModal, isLivestreamClaim, remoteFile, appLanguage, // isLivestreamPublish, } = props; const maxCharsBeforeOverflow = 128; const formattedTitle = React.useMemo(() => { if (title && title.length > maxCharsBeforeOverflow) { return title.slice(0, maxCharsBeforeOverflow).trim() + '...'; } return title; }, [title]); const formattedUri = React.useMemo(() => { if (uri && uri.length > maxCharsBeforeOverflow) { return uri.slice(0, maxCharsBeforeOverflow).trim() + '...'; } return uri; }, [uri]); const livestream = (uri && isLivestreamClaim) || // $FlowFixMe (previewResponse.outputs[0] && previewResponse.outputs[0].value && !previewResponse.outputs[0].value.source); // leave the confirm modal up if we're not going straight to upload/reflecting // @if TARGET='web' React.useEffect(() => { if (publishing && !livestream) { closeModal(); } else if (publishSuccess) { closeModal(); } }, [publishSuccess, publishing, livestream]); // @endif function onConfirmed() { // Publish for real: publish(getFilePathName(filePath), false); // @if TARGET='app' closeModal(); // @endif } function getFilePathName(filePath: string | WebFile) { if (!filePath) { return NO_FILE; } if (typeof filePath === 'string') { return filePath; } else { return filePath.name; } } function createRow(label: string, value: any) { return ( {label} {value} ); } const releasesInFuture = releaseTimeEdited && moment(releaseTimeEdited * 1000).isAfter(); const txFee = previewResponse ? previewResponse['total_fee'] : null; // $FlowFixMe add outputs[0] etc to PublishResponse type const isOptimizeAvail = filePath && filePath !== '' && isVid && ffmpegStatus.available; var modalTitle = 'Upload'; var confirmBtnText = 'Save'; if (isStillEditing) { if (livestream || isLivestreamClaim) { modalTitle = __('Confirm Update'); } else { modalTitle = __('Confirm Edit'); } } else if (livestream || isLivestreamClaim || remoteFile) { modalTitle = releasesInFuture ? __('Schedule Livestream') : (!livestream || !isLivestreamClaim) && remoteFile ? __('Publish Replay') : __('Create Livestream'); } else if (isMarkdownPost) { modalTitle = __('Confirm Post'); } else { modalTitle = __('Confirm Upload'); } if (!publishing) { if (isMarkdownPost) { confirmBtnText = __('Post'); } else if (livestream || isLivestreamClaim) { confirmBtnText = __('Create'); } else { confirmBtnText = __('Upload'); } } else { if (isMarkdownPost) { confirmBtnText = __('Saving'); } else if (livestream || isLivestreamClaim) { confirmBtnText = __('Creating'); } else { confirmBtnText = __('Uploading'); } } const releaseDateText = releasesInFuture ? __('Scheduled for') : __('Release date'); const descriptionValue = description ? (
) : null; const licenseValue = licenseType === COPYRIGHT ? (

© {otherLicenseDescription}

) : licenseType === OTHER ? (

{otherLicenseDescription}
{licenseUrl}

) : (

{__(licenseType)}

); const visibleTags = tags.filter((tag) => !INTERNAL_TAGS.includes(tag.name)); const tagsValue = // Do nothing for onClick(). Setting to 'null' results in "View Tag" action -- we don't want to leave the modal. visibleTags.map((tag) => {}} />); const depositValue = bid ? :

---

; let priceValue = __('Free'); if (!contentIsFree) { if (fee.currency === 'LBC') { priceValue = ; } else { priceValue = `${fee.amount} ${fee.currency}`; } } const channelValue = (channel) => { const channelClaim = myChannels && myChannels.find((x) => x.name === channel); return channel ? (
{channelClaim && } {channel}
) : (
{__('Anonymous')}
); }; const releaseTimeStr = (time) => { if (time) { try { return new Date(time * 1000).toLocaleString(appLanguage); } catch { return moment(new Date(time * 1000)).format('MMMM Do, YYYY - h:mm a'); } } else { return ''; } }; return (
{!livestream && !isMarkdownPost && createRow(__('File'), getFilePathName(filePath))} {livestream && remoteFile && createRow(__('Replay'), __('Remote File Selected'))} {livestream && filePath && createRow(__('Replay'), __('Manual Upload'))} {isOptimizeAvail && createRow(__('Transcode'), optimize ? __('Yes') : __('No'))} {createRow(__('Title'), formattedTitle)} {createRow(__('Description'), descriptionValue)} {createRow(__('Channel'), channelValue(channel))} {createRow(__('URL'), formattedUri)} {createRow(__('Deposit'), depositValue)} {createRow(__('Price'), priceValue)} {createRow(__('Language'), language ? getLanguageName(language) : '')} {releaseTimeEdited && createRow(releaseDateText, releaseTimeStr(releaseTimeEdited))} {createRow(__('License'), licenseValue)} {createRow(__('Tags'), tagsValue)}
{txFee && (
{__('Est. transaction fee:')}  
)} } actions={ <>

{__('Once the transaction is sent, it cannot be reversed.')}

setEnablePublishPreview(!enablePublishPreview)} /> } />
); }; export default ModalPublishPreview;