// @flow import * as MODALS from 'constants/modal_types'; import React, { useState } from 'react'; import { isNameValid } from 'util/lbryURI'; import Button from 'component/button'; import { Form, FormField } from 'component/common/form'; import { INVALID_NAME_ERROR } from 'constants/claim'; import Card from 'component/common/card'; import I18nMessage from 'component/i18nMessage'; import analytics from 'analytics'; import { sortLanguageMap } from 'util/default-languages'; import SUPPORTED_LANGUAGES from 'constants/supported_languages'; import ThumbnailBrokenImage from 'component/selectThumbnail/thumbnail-broken.png'; import { AVATAR_DEFAULT, THUMBNAIL_CDN_SIZE_LIMIT_BYTES } from 'config'; import * as ICONS from 'constants/icons'; export const DEFAULT_BID_FOR_FIRST_CHANNEL = 0.01; type Props = { createChannel: (string, number, any) => Promise, creatingChannel: boolean, createChannelError: string, claimingReward: boolean, user: User, doToggleInterestedInYoutubeSync: () => void, openModal: ( id: string, { onUpdate: (string, boolean) => void, assetName: string, helpText: string, currentValue: string, title: string } ) => void, }; function UserFirstChannel(props: Props) { const { createChannel, creatingChannel, claimingReward, user, createChannelError, doToggleInterestedInYoutubeSync, openModal, } = props; const { primary_email: primaryEmail } = user; const initialChannel = primaryEmail ? primaryEmail.split('@')[0] : ''; const [channel, setChannel] = useState(initialChannel); const [title, setTitle] = useState(initialChannel); const [isUpload, setIsUpload] = React.useState({ cover: false, thumbnail: false }); const [thumbError, setThumbError] = React.useState(false); const [params, setParams]: [any, (any) => void] = React.useState(getChannelParams()); const LANG_NONE = 'none'; const [languageParam, setLanguageParam] = useState([]); const primaryLanguage = Array.isArray(languageParam) && languageParam.length && languageParam[0]; const [nameError, setNameError] = useState(undefined); function getChannelParams() { // fill this in with sdk data const channelParams: { title: string, languages: ?Array, } = { title, languages: languageParam || [], }; return channelParams; } let thumbnailPreview; if (!params.thumbnailUrl) { thumbnailPreview = AVATAR_DEFAULT; } else if (thumbError) { thumbnailPreview = ThumbnailBrokenImage; } else { thumbnailPreview = params.thumbnailUrl; } function handleThumbnailChange(thumbnailUrl: string, uploadSelected: boolean) { setParams({ ...params, thumbnailUrl }); setIsUpload({ ...isUpload, thumbnail: uploadSelected }); setThumbError(false); } function handleLanguageChange(index, code) { let langs = [...languageParam]; if (index === 0) { if (code === LANG_NONE) { // clear all langs = []; } else { langs[0] = code; } } else { if (code === LANG_NONE || code === langs[0]) { langs.splice(1, 1); } else { langs[index] = code; } } setLanguageParam(langs); // setParams({ ...params, languages: langs }); } function handleCreateChannel() { createChannel(`@${channel}`, DEFAULT_BID_FOR_FIRST_CHANNEL, { title: title, thumbnailUrl: params.thumbnailUrl, languages: primaryLanguage, }).then((channelClaim) => { if (channelClaim) { analytics.apiLogPublish(channelClaim); } }); } function handleChannelChange(e) { const { value } = e.target; setChannel(value); if (!isNameValid(value)) { setNameError(INVALID_NAME_ERROR); } else { setNameError(); } } function handleTitleChange(e) { const { value } = e.target; setTitle(value); } return (

{__('Your channel will be used for publishing and commenting.')}

{__('You can have more than one or remove it later.')}

} actions={
@
handleLanguageChange(0, event.target.value)} value={primaryLanguage} helper={__('Your main content language')} > {sortLanguageMap(SUPPORTED_LANGUAGES).map(([langKey, langName]) => ( ))}
doToggleInterestedInYoutubeSync()} /> ), }} > Have a YouTube channel? %sync_channel%.
} />
); } export default UserFirstChannel;