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

660 lines
21 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
/*
On submit, this component calls publish, which dispatches doPublishDesktop.
doPublishDesktop calls lbry-redux Lbry publish method using lbry-redux publish state as params.
Publish simply instructs the SDK to find the file path on disk and publish it with the provided metadata.
On web, the Lbry publish method call is overridden in platform/web/api-setup, using a function in platform/web/publish.
File upload is carried out in the background by that function.
*/
2020-07-28 21:10:07 +02:00
import { SITE_NAME, ENABLE_NO_SOURCE_CLAIMS, SIMPLE_SITE, CHANNEL_STAKED_LEVEL_LIVESTREAM } from 'config';
import React, { useEffect, useState } from 'react';
import { buildURI, isURIValid, isNameValid, THUMBNAIL_STATUSES, Lbry } from 'lbry-redux';
2018-03-26 23:32:43 +02:00
import Button from 'component/button';
import ChannelSelect from 'component/channelSelector';
2018-03-26 23:32:43 +02:00
import classnames from 'classnames';
import TagsSelect from 'component/tagsSelect';
import PublishDescription from 'component/publishDescription';
import PublishPrice from 'component/publishPrice';
import PublishFile from 'component/publishFile';
import PublishBid from 'component/publishBid';
import PublishAdditionalOptions from 'component/publishAdditionalOptions';
import PublishFormErrors from 'component/publishFormErrors';
import SelectThumbnail from 'component/selectThumbnail';
2019-09-27 20:56:15 +02:00
import Card from 'component/common/card';
import I18nMessage from 'component/i18nMessage';
import * as PUBLISH_MODES from 'constants/publish_types';
import { useHistory } from 'react-router';
2021-03-30 04:04:14 +02:00
import Spinner from 'component/spinner';
import { toHex } from 'util/hex';
import { BITWAVE_REPLAY_API } from 'constants/livestream';
2020-07-28 21:10:07 +02:00
// @if TARGET='app'
import fs from 'fs';
import tempy from 'tempy';
2020-07-28 21:10:07 +02:00
// @endif
2018-03-26 23:32:43 +02:00
type Props = {
2019-10-28 19:53:59 +01:00
disabled: boolean,
tags: Array<Tag>,
publish: (source?: string | File, ?boolean) => void,
2020-08-11 03:26:44 +02:00
filePath: string | File,
fileText: string,
2018-03-26 23:32:43 +02:00
bid: ?number,
bidError: ?string,
2018-03-26 23:32:43 +02:00
editingURI: ?string,
title: ?string,
thumbnail: ?string,
thumbnailError: ?boolean,
uploadThumbnailStatus: ?string,
2018-06-08 06:05:45 +02:00
thumbnailPath: ?string,
2018-03-26 23:32:43 +02:00
description: ?string,
language: string,
nsfw: boolean,
contentIsFree: boolean,
fee: {
amount: string,
2018-03-26 23:32:43 +02:00
currency: string,
},
name: ?string,
nameError: ?string,
isResolvingUri: boolean,
winningBidForClaimUri: number,
2019-04-24 16:02:08 +02:00
myClaimForUri: ?StreamClaim,
2018-03-26 23:32:43 +02:00
licenseType: string,
otherLicenseDescription: ?string,
licenseUrl: ?string,
useLBRYUploader: ?boolean,
2018-03-26 23:32:43 +02:00
publishing: boolean,
2021-04-23 18:57:51 +02:00
publishSuccess: boolean,
2018-03-26 23:32:43 +02:00
balance: number,
2018-06-12 07:11:17 +02:00
isStillEditing: boolean,
2018-03-26 23:32:43 +02:00
clearPublish: () => void,
2021-03-11 17:26:11 +01:00
resolveUri: (string) => void,
2018-03-26 23:32:43 +02:00
scrollToTop: () => void,
2018-10-13 17:49:47 +02:00
prepareEdit: (claim: any, uri: string) => void,
resetThumbnailStatus: () => void,
2018-09-25 02:17:08 +02:00
amountNeededForTakeover: ?number,
// Add back type
2021-03-11 17:26:11 +01:00
updatePublishForm: (any) => void,
checkAvailability: (string) => void,
ytSignupPending: boolean,
modal: { id: string, modalProps: {} },
enablePublishPreview: boolean,
activeChannelClaim: ?ChannelClaim,
incognito: boolean,
user: ?User,
activeChannelStakedLevel: number,
isLivestreamClaim: boolean,
isPostClaim: boolean,
permanentUrl: ?string,
remoteUrl: ?string,
2018-03-26 23:32:43 +02:00
};
function PublishForm(props: Props) {
// Detect upload type from query in URL
const {
thumbnail,
thumbnailError,
name,
editingURI,
myClaimForUri,
resolveUri,
title,
bid,
bidError,
uploadThumbnailStatus,
resetThumbnailStatus,
updatePublishForm,
filePath,
fileText,
publishing,
2021-04-23 18:57:51 +02:00
publishSuccess,
clearPublish,
isStillEditing,
tags,
publish,
2019-10-28 19:53:59 +01:00
disabled = false,
checkAvailability,
ytSignupPending,
modal,
enablePublishPreview,
activeChannelClaim,
incognito,
user,
activeChannelStakedLevel,
isLivestreamClaim,
isPostClaim,
permanentUrl,
remoteUrl,
} = props;
2021-03-26 22:11:22 +01:00
const { replace, location } = useHistory();
const urlParams = new URLSearchParams(location.search);
const TYPE_PARAM = 'type';
const uploadType = urlParams.get(TYPE_PARAM);
2021-04-14 17:56:45 +02:00
const _uploadType = uploadType && uploadType.toLowerCase();
const enableLivestream =
ENABLE_NO_SOURCE_CLAIMS &&
user &&
!user.odysee_live_disabled &&
(activeChannelStakedLevel >= CHANNEL_STAKED_LEVEL_LIVESTREAM || user.odysee_live_enabled);
// $FlowFixMe
const AVAILABLE_MODES = Object.values(PUBLISH_MODES).filter((mode) => {
2021-04-14 17:56:45 +02:00
// $FlowFixMe
if (editingURI) {
if (isPostClaim) {
return mode === PUBLISH_MODES.POST;
} else if (isLivestreamClaim) {
return mode === PUBLISH_MODES.LIVESTREAM && enableLivestream;
} else {
return mode === PUBLISH_MODES.FILE;
}
2021-04-14 17:56:45 +02:00
} else if (_uploadType) {
return mode === _uploadType && (mode !== PUBLISH_MODES.LIVESTREAM || enableLivestream);
} else {
2021-04-14 17:56:45 +02:00
return mode !== PUBLISH_MODES.LIVESTREAM || enableLivestream;
}
});
const MODE_TO_I18N_STR = {
2021-04-19 18:45:01 +02:00
[PUBLISH_MODES.FILE]: SIMPLE_SITE ? 'Video/Audio' : 'File',
[PUBLISH_MODES.POST]: 'Post --[noun, markdown post tab button]--',
[PUBLISH_MODES.LIVESTREAM]: 'Livestream --[noun, livestream tab button]--',
};
2021-04-14 17:56:45 +02:00
const [mode, setMode] = React.useState(_uploadType || PUBLISH_MODES.FILE);
const [isCheckingLivestreams, setCheckingLivestreams] = React.useState(false);
let customSubtitle;
if (mode === PUBLISH_MODES.LIVESTREAM || isLivestreamClaim) {
if (isLivestreamClaim) {
customSubtitle = __('Update your livestream');
} else {
customSubtitle = __('Prepare an upcoming livestream');
}
} else if (mode === PUBLISH_MODES.POST || isPostClaim) {
if (isPostClaim) {
customSubtitle = __('Edit your post');
} else {
customSubtitle = __('Craft an epic post clearly explaining... whatever.');
}
} else {
if (editingURI) {
odysee fix replay select styling make meme a link Fix audio references get newest livestream claim in livestreamLink pin crackermilk fix livestream banner placement fix live page fix rebase fix rebase fix error nag fix darkmode blockquote style break word on livestream comment text fix dark mode snack fix live badge fix lint small fixes - word wrap, live badge wip Fix invisible snack in Odysee Light Theme Revert "wip" This reverts commit d17e477fe0e6633709ea30bdc403448825db4c71. Revert "small fixes - word wrap, live badge" This reverts commit 0e431d4038d774079c78f0de32238aac7260e4ca. fix blank pinned destiny fix badges and homepage again only get livestreams live for less than a day pinned hammy and olivia multi pin pin destiny updated pinned videos update tagline Update view.jsx pins updated destiny's video updated pinned videos removed destiny, added lie likes music pinned destiny and mason's woodshop removed hammy and olivia unpinned mason's woodshop removed pins added hammy and olivia pinned sam seder unpinned destiny and hammy and olivia Fix merge on ChannelThumbnails - sam seder, + hammy & olivia and passion for food update tagline (#6086) removed everyone, added kona and suba Theme color fixes (odysee) (#6089) * Cherry-pick master's 'base-theme.scss' * Non-functional cleanup (remove dups, re-order, etc.) * Dark: update positive Toast to --color-primary as well. This follows the intention of the refactoring, which I guess was (1) reduce the number of color names (2) reduce the number of customizations needed. The only issue I have with this is that the current Odysee primary color is pink, which can be intepreted as an error. The original (pre-refactoring color was green). For now, I follow the refactoring path. We can tweak this later. * Fix text color inside '--color-card-background-highlighted' Light: use base-theme (it was the same value anyway). Dark: use bright text. * Dark: add some contrast between the components The color for the background, header, card, placeholder, etc. is almost identical -- it looks like there are all in the same component. The almost-invisible border doesn't help. One would have to crank up the monitor's contrast setting to see separation of components. Brighten up the components a bit, somewhat following the same scale as lbry.tv's dark theme. Overall, I still think it's too dark. The Card's background color can still be brightened up further for better contrast, but I try not to make too drastic of a change for now. The original lbry.tv's gray theme is the most pleasant theme I've seen so far, but this is all subjective. changed pins removed kona and suba added destiny changed pins removed destiny pinned sgtducky changed pins removed sgtducky added hammy and olivia added chrissie mayr added the bite shot changed pins removed the bite shot added heads of tech changed pins removed hammy and olivia removed chrissie mayr changed pins removed heads of tech added crackermilk changed pins removed crackermilk added some ordinary gamer added passion for food changed pins removed some ordinary gamers removed passion for food added emmy hucker changed pins added game knights Update view.jsx Force rebuild changed pins removed emmy hucker changed pins removed game knights added crackermilk changed pins removed crackermilk added some ordinary gamer changed pins removed some ordinary gamers added passion for food added green renaissance changed pins removed passion for food removed green renaissance added expand love changed pins removed expand love added dr nora change tagline (#6122) there's so much room for activities comment out music changed pins removed dr nora added kona and suba changed pins removed kona and suba added destiny changed pins removed destiny added crackermilk changed pins removed crackermilk added someordinarygamers change tagline Drake, where's the door hole? changed pins unpinned someordinarygamers pinned kona and suba Add message for mature content changed pin changed pins removed creative model changed pins added bcpov added krish mohan added cigarvixen changed pins removed krish mohan added adrian logan bump fix footer change tagline just like the simulations changed pins removed: bcpov cigarvixen adrian logan added: someordinarygamers quick fix for reposts oops fix channel tabs changed pin removed someordinarygamers added kona and suba changed pins removed kona and suba added dirtyworkz added crackermilk
2021-06-11 19:47:56 +02:00
customSubtitle = __('Update your video/audio');
} else {
odysee fix replay select styling make meme a link Fix audio references get newest livestream claim in livestreamLink pin crackermilk fix livestream banner placement fix live page fix rebase fix rebase fix error nag fix darkmode blockquote style break word on livestream comment text fix dark mode snack fix live badge fix lint small fixes - word wrap, live badge wip Fix invisible snack in Odysee Light Theme Revert "wip" This reverts commit d17e477fe0e6633709ea30bdc403448825db4c71. Revert "small fixes - word wrap, live badge" This reverts commit 0e431d4038d774079c78f0de32238aac7260e4ca. fix blank pinned destiny fix badges and homepage again only get livestreams live for less than a day pinned hammy and olivia multi pin pin destiny updated pinned videos update tagline Update view.jsx pins updated destiny's video updated pinned videos removed destiny, added lie likes music pinned destiny and mason's woodshop removed hammy and olivia unpinned mason's woodshop removed pins added hammy and olivia pinned sam seder unpinned destiny and hammy and olivia Fix merge on ChannelThumbnails - sam seder, + hammy & olivia and passion for food update tagline (#6086) removed everyone, added kona and suba Theme color fixes (odysee) (#6089) * Cherry-pick master's 'base-theme.scss' * Non-functional cleanup (remove dups, re-order, etc.) * Dark: update positive Toast to --color-primary as well. This follows the intention of the refactoring, which I guess was (1) reduce the number of color names (2) reduce the number of customizations needed. The only issue I have with this is that the current Odysee primary color is pink, which can be intepreted as an error. The original (pre-refactoring color was green). For now, I follow the refactoring path. We can tweak this later. * Fix text color inside '--color-card-background-highlighted' Light: use base-theme (it was the same value anyway). Dark: use bright text. * Dark: add some contrast between the components The color for the background, header, card, placeholder, etc. is almost identical -- it looks like there are all in the same component. The almost-invisible border doesn't help. One would have to crank up the monitor's contrast setting to see separation of components. Brighten up the components a bit, somewhat following the same scale as lbry.tv's dark theme. Overall, I still think it's too dark. The Card's background color can still be brightened up further for better contrast, but I try not to make too drastic of a change for now. The original lbry.tv's gray theme is the most pleasant theme I've seen so far, but this is all subjective. changed pins removed kona and suba added destiny changed pins removed destiny pinned sgtducky changed pins removed sgtducky added hammy and olivia added chrissie mayr added the bite shot changed pins removed the bite shot added heads of tech changed pins removed hammy and olivia removed chrissie mayr changed pins removed heads of tech added crackermilk changed pins removed crackermilk added some ordinary gamer added passion for food changed pins removed some ordinary gamers removed passion for food added emmy hucker changed pins added game knights Update view.jsx Force rebuild changed pins removed emmy hucker changed pins removed game knights added crackermilk changed pins removed crackermilk added some ordinary gamer changed pins removed some ordinary gamers added passion for food added green renaissance changed pins removed passion for food removed green renaissance added expand love changed pins removed expand love added dr nora change tagline (#6122) there's so much room for activities comment out music changed pins removed dr nora added kona and suba changed pins removed kona and suba added destiny changed pins removed destiny added crackermilk changed pins removed crackermilk added someordinarygamers change tagline Drake, where's the door hole? changed pins unpinned someordinarygamers pinned kona and suba Add message for mature content changed pin changed pins removed creative model changed pins added bcpov added krish mohan added cigarvixen changed pins removed krish mohan added adrian logan bump fix footer change tagline just like the simulations changed pins removed: bcpov cigarvixen adrian logan added: someordinarygamers quick fix for reposts oops fix channel tabs changed pin removed someordinarygamers added kona and suba changed pins removed kona and suba added dirtyworkz added crackermilk
2021-06-11 19:47:56 +02:00
customSubtitle = __('Upload that unlabeled video or cassette you found behind the TV in 1991');
}
}
const [autoSwitchMode, setAutoSwitchMode] = React.useState(true);
// Used to check if the url name has changed:
// A new file needs to be provided
const [prevName, setPrevName] = React.useState(false);
// Used to check if the file has been modified by user
const [fileEdited, setFileEdited] = React.useState(false);
const [prevFileText, setPrevFileText] = React.useState('');
const [waitForFile, setWaitForFile] = useState(false);
const [livestreamData, setLivestreamData] = React.useState([]);
const [signedMessage, setSignedMessage] = React.useState({ signature: undefined, signing_ts: undefined });
const signedMessageStr = JSON.stringify(signedMessage);
2020-03-05 22:35:01 +01:00
const TAGS_LIMIT = 5;
2021-04-26 19:45:36 +02:00
const fileFormDisabled = mode === PUBLISH_MODES.FILE && !filePath && !remoteUrl;
2020-07-29 22:30:26 +02:00
const emptyPostError = mode === PUBLISH_MODES.POST && (!fileText || fileText.trim() === '');
const formDisabled = (fileFormDisabled && !editingURI) || emptyPostError || publishing;
const isInProgress = filePath || editingURI || name || title;
const activeChannelName = activeChannelClaim && activeChannelClaim.name;
const activeChannelClaimStr = JSON.stringify(activeChannelClaim);
// Editing content info
2020-10-26 19:56:38 +01:00
const fileMimeType =
myClaimForUri && myClaimForUri.value && myClaimForUri.value.source
? myClaimForUri.value.source.media_type
: undefined;
2021-04-14 17:56:45 +02:00
const claimChannelId =
(myClaimForUri && myClaimForUri.signing_channel && myClaimForUri.signing_channel.claim_id) ||
(activeChannelClaim && activeChannelClaim.claim_id);
2020-07-30 06:03:56 +02:00
const nameEdited = isStillEditing && name !== prevName;
const waitingForFile = waitForFile && !remoteUrl && !filePath;
// If they are editing, they don't need a new file chosen
2019-07-24 20:21:34 +02:00
const formValidLessFile =
name &&
isNameValid(name, false) &&
title &&
bid &&
2021-04-19 18:45:01 +02:00
thumbnail &&
!bidError &&
2020-07-29 22:30:26 +02:00
!emptyPostError &&
!thumbnailError &&
!(uploadThumbnailStatus === THUMBNAIL_STATUSES.IN_PROGRESS);
const isOverwritingExistingClaim = !editingURI && myClaimForUri;
const formValid = isOverwritingExistingClaim
? false
: editingURI && !filePath // if we're editing we don't need a file
? isStillEditing && formValidLessFile && !waitingForFile
: formValidLessFile;
const [previewing, setPreviewing] = React.useState(false);
React.useEffect(() => {
if (activeChannelClaimStr) {
const channelClaim = JSON.parse(activeChannelClaimStr);
const message = 'get-claim-id-replays';
setSignedMessage({ signature: null, signing_ts: null });
// ensure we have a channel
if (channelClaim.claim_id) {
Lbry.channel_sign({
channel_id: channelClaim.claim_id,
hexdata: toHex(message),
})
.then((data) => {
setSignedMessage(data);
})
.catch((error) => {
setSignedMessage({ signature: null, signing_ts: null });
});
}
}
}, [activeChannelClaimStr, setSignedMessage]);
useEffect(() => {
if (!modal) {
setTimeout(() => {
setPreviewing(false);
}, 250);
}
}, [modal]);
// move this to lbryinc OR to a file under ui, and/or provide a standardized livestreaming config.
function fetchLivestreams(channelId, signature, timestamp) {
setCheckingLivestreams(true);
fetch(`${BITWAVE_REPLAY_API}/${channelId}?signature=${signature || ''}&signing_ts=${timestamp || ''}`) // claimChannelId
.then((res) => res.json())
.then((res) => {
if (!res || !res.data) {
setLivestreamData([]);
}
setLivestreamData(res.data);
setCheckingLivestreams(false);
})
.catch((e) => {
setLivestreamData([]);
setCheckingLivestreams(false);
});
}
useEffect(() => {
const signedMessage = JSON.parse(signedMessageStr);
2021-04-14 17:56:45 +02:00
if (claimChannelId && signedMessage.signature) {
fetchLivestreams(claimChannelId, signedMessage.signature, signedMessage.signing_ts);
}
2021-04-14 17:56:45 +02:00
}, [claimChannelId, signedMessageStr]);
const isLivestreamMode = mode === PUBLISH_MODES.LIVESTREAM;
let submitLabel;
if (publishing) {
if (isStillEditing) {
submitLabel = __('Saving...');
} else if (isLivestreamMode) {
submitLabel = __('Creating...');
} else {
submitLabel = __('Uploading...');
}
} else if (previewing) {
submitLabel = __('Preparing...');
} else {
if (isStillEditing) {
submitLabel = __('Save');
} else if (isLivestreamMode) {
submitLabel = __('Create');
} else {
submitLabel = __('Upload');
}
2018-03-26 23:32:43 +02:00
}
// if you enter the page and it is stuck in publishing, "stop it."
useEffect(() => {
2021-04-23 18:57:51 +02:00
if (publishing || publishSuccess) {
clearPublish();
}
2021-04-23 18:57:51 +02:00
}, [clearPublish]);
useEffect(() => {
2018-07-17 19:43:43 +02:00
if (!thumbnail) {
resetThumbnailStatus();
2018-06-13 06:19:39 +02:00
}
}, [thumbnail, resetThumbnailStatus]);
// Save previous name of the editing claim
2020-07-30 06:03:56 +02:00
useEffect(() => {
if (isStillEditing && (!prevName || !prevName.trim() === '')) {
if (name !== prevName) {
setPrevName(name);
}
}
}, [name, prevName, setPrevName, isStillEditing]);
// Check for content changes on the text editor
useEffect(() => {
if (!fileEdited && fileText !== prevFileText && fileText !== '') {
setFileEdited(true);
} else if (fileEdited && fileText === prevFileText) {
setFileEdited(false);
}
}, [fileText, prevFileText, fileEdited]);
// Every time the channel or name changes, resolve the uris to find winning bid amounts
useEffect(() => {
2018-09-25 02:17:08 +02:00
// We are only going to store the full uri, but we need to resolve the uri with and without the channel name
let uri;
try {
uri = name && buildURI({ streamName: name, activeChannelName });
} catch (e) {}
if (activeChannelName && name) {
// resolve without the channel name so we know the winning bid for it
2019-07-02 06:49:21 +02:00
try {
const uriLessChannel = buildURI({ streamName: name });
2019-07-02 06:49:21 +02:00
resolveUri(uriLessChannel);
} catch (e) {}
}
2019-07-03 16:49:28 +02:00
const isValid = isURIValid(uri);
if (uri && isValid && checkAvailability && name) {
resolveUri(uri);
checkAvailability(name);
updatePublishForm({ uri });
}
}, [name, activeChannelName, resolveUri, updatePublishForm, checkAvailability]);
// because publish editingUri is channel_short/claim_long and we don't have that, resolve it.
2021-03-30 01:05:18 +02:00
useEffect(() => {
if (editingURI) {
resolveUri(editingURI);
}
}, [editingURI, resolveUri]);
// set isMarkdownPost in publish form if so, also update isLivestreamPublish
useEffect(() => {
2021-03-11 17:26:11 +01:00
updatePublishForm({
isMarkdownPost: mode === PUBLISH_MODES.POST,
isLivestreamPublish: mode === PUBLISH_MODES.LIVESTREAM,
2021-03-11 17:26:11 +01:00
});
}, [mode, updatePublishForm]);
useEffect(() => {
if (incognito) {
updatePublishForm({ channel: undefined });
2021-03-11 17:26:11 +01:00
// Anonymous livestreams aren't supported
if (isLivestreamMode) {
2021-03-11 17:26:11 +01:00
setMode(PUBLISH_MODES.FILE);
}
} else if (activeChannelName) {
updatePublishForm({ channel: activeChannelName });
}
}, [activeChannelName, incognito, updatePublishForm, isLivestreamMode]);
// set mode based on urlParams 'type'
useEffect(() => {
// Default to standard file publish if none specified
if (!_uploadType) {
setMode(PUBLISH_MODES.FILE);
return;
}
// File publish
if (_uploadType === PUBLISH_MODES.FILE.toLowerCase()) {
setMode(PUBLISH_MODES.FILE);
return;
}
// Post publish
if (_uploadType === PUBLISH_MODES.POST.toLowerCase()) {
setMode(PUBLISH_MODES.POST);
return;
}
// LiveStream publish
if (_uploadType === PUBLISH_MODES.LIVESTREAM.toLowerCase()) {
if (enableLivestream) {
setMode(PUBLISH_MODES.LIVESTREAM);
} else {
setMode(PUBLISH_MODES.FILE);
}
return;
}
// Default to standard file publish
setMode(PUBLISH_MODES.FILE);
2021-04-14 17:56:45 +02:00
}, [_uploadType, enableLivestream]);
// if we have a type urlparam, update it? necessary?
useEffect(() => {
2021-04-14 17:56:45 +02:00
if (!_uploadType) return;
const newParams = new URLSearchParams();
newParams.set(TYPE_PARAM, mode.toLowerCase());
2021-03-26 22:11:22 +01:00
replace({ search: newParams.toString() });
2021-04-14 17:56:45 +02:00
}, [mode, _uploadType]);
2020-07-28 21:10:07 +02:00
// @if TARGET='web'
function createWebFile() {
if (fileText) {
2020-07-29 22:30:26 +02:00
const fileName = name || title;
2020-08-11 03:26:44 +02:00
if (fileName) {
return new File([fileText], `${fileName}.md`, { type: 'text/markdown' });
}
}
}
2020-07-28 21:10:07 +02:00
// @endif
2020-07-28 21:10:07 +02:00
// @if TARGET='app'
// Save file changes locally ( desktop )
function saveFileChanges() {
2020-08-11 03:26:44 +02:00
let output;
if (!output || output === '') {
// Generate a temporary file:
2020-07-29 22:30:26 +02:00
output = tempy.file({ name: 'post.md' });
2020-08-11 03:26:44 +02:00
} else if (typeof filePath === 'string') {
// Use current file
output = filePath;
}
// Create a temporary file and save file changes
2020-08-11 03:26:44 +02:00
if (output && output !== '') {
// Save file changes
return new Promise((resolve, reject) => {
fs.writeFile(output, fileText, (error, data) => {
// Handle error, cant save changes or create file
error ? reject(error) : resolve(output);
});
});
}
}
2020-07-28 21:10:07 +02:00
// @endif
async function handlePublish() {
2020-08-12 03:59:23 +02:00
let outputFile = filePath;
let runPublish = false;
2020-07-29 22:30:26 +02:00
// Publish post:
// If here is no file selected yet on desktop, show file dialog and let the
// user choose a file path. On web a new File is created
if (mode === PUBLISH_MODES.POST && !emptyPostError) {
2020-07-30 06:03:56 +02:00
// If user modified content on the text editor or editing name has changed:
2020-07-30 06:07:00 +02:00
// Save changes and update file path
2020-07-30 06:03:56 +02:00
if (fileEdited || nameEdited) {
// @if TARGET='app'
outputFile = await saveFileChanges();
// @endif
// @if TARGET='web'
outputFile = createWebFile();
// @endif
// New content stored locally and is not empty
if (outputFile) {
updatePublishForm({ filePath: outputFile });
2020-08-12 03:59:23 +02:00
runPublish = true;
}
} else {
// Only metadata has changed.
2020-08-12 03:59:23 +02:00
runPublish = true;
}
}
// Publish file
if (mode === PUBLISH_MODES.FILE || isLivestreamMode) {
2020-08-12 03:59:23 +02:00
runPublish = true;
}
if (runPublish) {
if (enablePublishPreview) {
setPreviewing(true);
2020-08-12 03:59:23 +02:00
publish(outputFile, true);
} else {
2020-08-12 03:59:23 +02:00
publish(outputFile, false);
}
}
}
// Update mode on editing
useEffect(() => {
if (autoSwitchMode && editingURI && myClaimForUri) {
2020-07-29 22:30:26 +02:00
// Change publish mode to "post" if editing content type is markdown
if (fileMimeType === 'text/markdown' && mode !== PUBLISH_MODES.POST) {
setMode(PUBLISH_MODES.POST);
// Prevent forced mode
setAutoSwitchMode(false);
}
}
}, [autoSwitchMode, editingURI, fileMimeType, myClaimForUri, mode, setMode, setAutoSwitchMode]);
2021-03-30 04:04:14 +02:00
if (publishing) {
return (
<div className="main--empty">
<h1 className="section__subtitle">{__('Publishing...')}</h1>
<Spinner delayed />
</div>
);
}
// Editing claim uri
return (
<div className="card-stack">
<ChannelSelect hideAnon={isLivestreamMode} disabled={disabled} />
<PublishFile
uri={permanentUrl}
mode={mode}
fileMimeType={fileMimeType}
disabled={disabled || publishing}
inProgress={isInProgress}
setPublishMode={setMode}
setPrevFileText={setPrevFileText}
livestreamData={livestreamData}
subtitle={customSubtitle}
setWaitForFile={setWaitForFile}
isCheckingLivestreams={isCheckingLivestreams}
checkLivestreams={fetchLivestreams}
channelId={claimChannelId}
channelSignature={signedMessage}
header={
2020-08-05 19:19:15 +02:00
<>
{AVAILABLE_MODES.map((modeName) => (
<Button
key={String(modeName)}
icon={modeName}
odysee fix replay select styling make meme a link Fix audio references get newest livestream claim in livestreamLink pin crackermilk fix livestream banner placement fix live page fix rebase fix rebase fix error nag fix darkmode blockquote style break word on livestream comment text fix dark mode snack fix live badge fix lint small fixes - word wrap, live badge wip Fix invisible snack in Odysee Light Theme Revert "wip" This reverts commit d17e477fe0e6633709ea30bdc403448825db4c71. Revert "small fixes - word wrap, live badge" This reverts commit 0e431d4038d774079c78f0de32238aac7260e4ca. fix blank pinned destiny fix badges and homepage again only get livestreams live for less than a day pinned hammy and olivia multi pin pin destiny updated pinned videos update tagline Update view.jsx pins updated destiny's video updated pinned videos removed destiny, added lie likes music pinned destiny and mason's woodshop removed hammy and olivia unpinned mason's woodshop removed pins added hammy and olivia pinned sam seder unpinned destiny and hammy and olivia Fix merge on ChannelThumbnails - sam seder, + hammy & olivia and passion for food update tagline (#6086) removed everyone, added kona and suba Theme color fixes (odysee) (#6089) * Cherry-pick master's 'base-theme.scss' * Non-functional cleanup (remove dups, re-order, etc.) * Dark: update positive Toast to --color-primary as well. This follows the intention of the refactoring, which I guess was (1) reduce the number of color names (2) reduce the number of customizations needed. The only issue I have with this is that the current Odysee primary color is pink, which can be intepreted as an error. The original (pre-refactoring color was green). For now, I follow the refactoring path. We can tweak this later. * Fix text color inside '--color-card-background-highlighted' Light: use base-theme (it was the same value anyway). Dark: use bright text. * Dark: add some contrast between the components The color for the background, header, card, placeholder, etc. is almost identical -- it looks like there are all in the same component. The almost-invisible border doesn't help. One would have to crank up the monitor's contrast setting to see separation of components. Brighten up the components a bit, somewhat following the same scale as lbry.tv's dark theme. Overall, I still think it's too dark. The Card's background color can still be brightened up further for better contrast, but I try not to make too drastic of a change for now. The original lbry.tv's gray theme is the most pleasant theme I've seen so far, but this is all subjective. changed pins removed kona and suba added destiny changed pins removed destiny pinned sgtducky changed pins removed sgtducky added hammy and olivia added chrissie mayr added the bite shot changed pins removed the bite shot added heads of tech changed pins removed hammy and olivia removed chrissie mayr changed pins removed heads of tech added crackermilk changed pins removed crackermilk added some ordinary gamer added passion for food changed pins removed some ordinary gamers removed passion for food added emmy hucker changed pins added game knights Update view.jsx Force rebuild changed pins removed emmy hucker changed pins removed game knights added crackermilk changed pins removed crackermilk added some ordinary gamer changed pins removed some ordinary gamers added passion for food added green renaissance changed pins removed passion for food removed green renaissance added expand love changed pins removed expand love added dr nora change tagline (#6122) there's so much room for activities comment out music changed pins removed dr nora added kona and suba changed pins removed kona and suba added destiny changed pins removed destiny added crackermilk changed pins removed crackermilk added someordinarygamers change tagline Drake, where's the door hole? changed pins unpinned someordinarygamers pinned kona and suba Add message for mature content changed pin changed pins removed creative model changed pins added bcpov added krish mohan added cigarvixen changed pins removed krish mohan added adrian logan bump fix footer change tagline just like the simulations changed pins removed: bcpov cigarvixen adrian logan added: someordinarygamers quick fix for reposts oops fix channel tabs changed pin removed someordinarygamers added kona and suba changed pins removed kona and suba added dirtyworkz added crackermilk
2021-06-11 19:47:56 +02:00
iconSize={18}
label={__(MODE_TO_I18N_STR[String(modeName)] || '---')}
button="alt"
onClick={() => {
2021-03-22 23:12:59 +01:00
// $FlowFixMe
setMode(modeName);
}}
className={classnames('button-toggle', { 'button-toggle--active': mode === modeName })}
/>
))}
2020-08-05 19:19:15 +02:00
</>
}
/>
{!publishing && (
<div className={classnames({ 'card--disabled': formDisabled })}>
2021-04-14 17:56:45 +02:00
{mode !== PUBLISH_MODES.POST && <PublishDescription disabled={formDisabled} />}
<Card actions={<SelectThumbnail livestreamdData={livestreamData} />} />
<TagsSelect
2021-03-30 01:05:18 +02:00
suggestMature={!SIMPLE_SITE}
disableAutoFocus
hideHeader
label={__('Selected Tags')}
empty={__('No tags added')}
limitSelect={TAGS_LIMIT}
help={__(
"Add tags that are relevant to your content so those who're looking for it can find it more easily. If your content is best suited for mature audiences, ensure it is tagged 'mature'."
)}
placeholder={__('gaming, crypto')}
2021-03-11 17:26:11 +01:00
onSelect={(newTags) => {
const validatedTags = [];
2021-03-11 17:26:11 +01:00
newTags.forEach((newTag) => {
if (!tags.some((tag) => tag.name === newTag.name)) {
validatedTags.push(newTag);
}
});
updatePublishForm({ tags: [...tags, ...validatedTags] });
}}
2021-03-11 17:26:11 +01:00
onRemove={(clickedTag) => {
const newTags = tags.slice().filter((tag) => tag.name !== clickedTag.name);
updatePublishForm({ tags: newTags });
}}
tagsChosen={tags}
/>
2019-09-27 20:56:15 +02:00
<PublishBid disabled={isStillEditing || formDisabled} />
{!isLivestreamMode && <PublishPrice disabled={formDisabled} />}
<PublishAdditionalOptions disabled={formDisabled} />
</div>
)}
<section>
2021-04-23 21:59:48 +02:00
<div className="section__actions">
<Button
button="primary"
onClick={handlePublish}
label={submitLabel}
disabled={
formDisabled ||
!formValid ||
uploadThumbnailStatus === THUMBNAIL_STATUSES.IN_PROGRESS ||
ytSignupPending ||
previewing
}
/>
2021-06-13 09:12:28 +02:00
<Button button="link" onClick={clearPublish} label={__('New --[clears Publish Form]--')} />
</div>
<p className="help">
2020-07-08 00:24:24 +02:00
{!formDisabled && !formValid ? (
<PublishFormErrors mode={mode} waitForFile={waitingForFile} />
2020-07-08 00:24:24 +02:00
) : (
<I18nMessage
tokens={{
lbry_terms_of_service: (
<Button
button="link"
href="https://www.lbry.com/termsofservice"
2020-07-24 18:20:25 +02:00
label={__('%site_name% Terms of Service', { site_name: SITE_NAME })}
2020-07-08 00:24:24 +02:00
/>
),
}}
>
By continuing, you accept the %lbry_terms_of_service%.
</I18nMessage>
)}
</p>
</section>
</div>
);
}
export default PublishForm;