From 9b4cbc271251eeb8cbfdfbc3850699b62bfa8e25 Mon Sep 17 00:00:00 2001 From: Chakrit Likitkhajorn Date: Sat, 13 Oct 2018 22:49:47 +0700 Subject: [PATCH 1/3] Limit file type when upload --- .../component/common/file-selector.jsx | 7 ++++ src/renderer/component/publishForm/view.jsx | 26 +++++++-------- .../component/selectThumbnail/view.jsx | 7 ++++ src/renderer/page/settings/view.jsx | 26 ++++++++------- src/renderer/redux/actions/publish.js | 32 +++++++++++-------- src/renderer/redux/reducers/publish.js | 24 +++++++------- src/renderer/types/claim.js | 3 ++ src/renderer/types/stream.js | 8 +++++ 8 files changed, 80 insertions(+), 53 deletions(-) create mode 100644 src/renderer/types/stream.js diff --git a/src/renderer/component/common/file-selector.jsx b/src/renderer/component/common/file-selector.jsx index 3729202d0..1aea29fd2 100644 --- a/src/renderer/component/common/file-selector.jsx +++ b/src/renderer/component/common/file-selector.jsx @@ -5,12 +5,18 @@ import Button from 'component/button'; import { FormRow } from 'component/common/form'; import path from 'path'; +type FileFilters = { + name: string, + extensions: string[], +}; + type Props = { type: string, currentPath: ?string, onFileChosen: (string, string) => void, fileLabel?: string, directoryLabel?: string, + filters?: FileFilters[], }; class FileSelector extends React.PureComponent { @@ -29,6 +35,7 @@ class FileSelector extends React.PureComponent { { properties: this.props.type === 'file' ? ['openFile'] : ['openDirectory', 'createDirectory'], + filters: this.props.filters, }, paths => { if (!paths) { diff --git a/src/renderer/component/publishForm/view.jsx b/src/renderer/component/publishForm/view.jsx index 51ca29f54..901e03eac 100644 --- a/src/renderer/component/publishForm/view.jsx +++ b/src/renderer/component/publishForm/view.jsx @@ -52,7 +52,7 @@ type Props = { clearPublish: () => void, resolveUri: string => void, scrollToTop: () => void, - prepareEdit: ({}) => void, + prepareEdit: (claim: any, uri: string) => void, resetThumbnailStatus: () => void, amountNeededForTakeover: ?number, }; @@ -107,11 +107,7 @@ class PublishForm extends React.PureComponent { handleFileChange(filePath: string, fileName: string) { const { updatePublishForm, channel, name } = this.props; - const newFileParams: { - filePath: string, - name?: string, - uri?: string, - } = { filePath }; + const newFileParams: UpdatePublishFormData = { filePath }; if (!name) { const parsedFileName = fileName.replace(regexInvalidURI, ''); @@ -127,7 +123,7 @@ class PublishForm extends React.PureComponent { const { channel, updatePublishForm } = this.props; if (!name) { - updatePublishForm({ name, nameError: undefined }); + updatePublishForm({ nameError: undefined }); return; } @@ -149,7 +145,7 @@ class PublishForm extends React.PureComponent { handleChannelChange(channelName: string) { const { name, updatePublishForm } = this.props; - const form = { channel: channelName }; + const form: UpdatePublishFormData = { channel: channelName }; if (name) { form.uri = this.getNewUri(name, channelName); @@ -217,10 +213,10 @@ class PublishForm extends React.PureComponent { const publishingLicenseUrl = licenseType === COPYRIGHT ? '' : licenseUrl; - const publishParams = { - filePath, - bid: this.props.bid, - title: this.props.title, + const publishParams: PublishParams = { + filePath: filePath || undefined, + bid: this.props.bid || undefined, + title: this.props.title || '', thumbnail: this.props.thumbnail, description: this.props.description, language: this.props.language, @@ -228,16 +224,16 @@ class PublishForm extends React.PureComponent { license: publishingLicense, licenseUrl: publishingLicenseUrl, otherLicenseDescription, - name: this.props.name, + name: this.props.name || undefined, contentIsFree: this.props.contentIsFree, price: this.props.price, - uri: this.props.uri, + uri: this.props.uri || undefined, channel: this.props.channel, isStillEditing: this.props.isStillEditing, }; // Editing a claim - if (!filePath && myClaimForUri) { + if (!filePath && myClaimForUri && myClaimForUri.value) { const { source } = myClaimForUri.value.stream; publishParams.sources = source; } diff --git a/src/renderer/component/selectThumbnail/view.jsx b/src/renderer/component/selectThumbnail/view.jsx index e25c4dbb3..724f8af44 100644 --- a/src/renderer/component/selectThumbnail/view.jsx +++ b/src/renderer/component/selectThumbnail/view.jsx @@ -51,6 +51,12 @@ class SelectThumbnail extends React.PureComponent { thumbnailPath, resetThumbnailStatus, } = this.props; + const filters = [ + { + name: __('Thumbnail Image'), + extensions: ['png', 'jpg', 'jpeg', 'gif'], + }, + ]; const { thumbnailError, thumbnailErrorImage } = this.state; const thumbnailSrc = !thumbnail || thumbnailError ? Native.imagePath(thumbnailErrorImage) : thumbnail; @@ -111,6 +117,7 @@ class SelectThumbnail extends React.PureComponent { openModal({ id: MODALS.CONFIRM_THUMBNAIL_UPLOAD }, { path })} /> )} diff --git a/src/renderer/page/settings/view.jsx b/src/renderer/page/settings/view.jsx index ab844c95c..e5aa1ce73 100644 --- a/src/renderer/page/settings/view.jsx +++ b/src/renderer/page/settings/view.jsx @@ -16,6 +16,7 @@ type DaemonSettings = { download_directory: string, disable_max_key_fee: boolean, share_usage_data: boolean, + max_key_fee?: Price, }; type Props = { @@ -34,6 +35,7 @@ type Props = { autoDownload: boolean, encryptWallet: () => void, decryptWallet: () => void, + updateWalletStatus: () => void, walletEncrypted: boolean, osNotificationsEnabled: boolean, }; @@ -65,10 +67,8 @@ class SettingsPage extends React.PureComponent { } componentDidMount() { - const { props } = this; - - props.getThemes(); - props.updateWalletStatus(); + this.props.getThemes(); + this.props.updateWalletStatus(); } onRunOnStartChange(event: SyntheticInputEvent<*>) { @@ -126,18 +126,22 @@ class SettingsPage extends React.PureComponent { } onChangeEncryptWallet() { - const { props } = this; - props.walletEncrypted ? props.decryptWallet() : props.encryptWallet(); - } - - setDaemonSetting(name: string, value: boolean | string | Price) { - this.props.setDaemonSetting(name, value); + const { decryptWallet, walletEncrypted, encryptWallet } = this.props; + if (walletEncrypted) { + decryptWallet(); + } else { + encryptWallet(); + } } onDesktopNotificationsChange(event: SyntheticInputEvent<*>) { this.props.setClientSetting(settings.OS_NOTIFICATIONS_ENABLED, event.target.checked); } + setDaemonSetting(name: string, value: boolean | string | Price) { + this.props.setDaemonSetting(name, value); + } + clearCache() { this.setState({ clearingCache: true, @@ -346,7 +350,7 @@ class SettingsPage extends React.PureComponent { this.onChangeEncryptWallet(e)} + onChange={() => this.onChangeEncryptWallet()} checked={walletEncrypted} postfix={__('Encrypt my wallet with a custom password.')} helper={ diff --git a/src/renderer/redux/actions/publish.js b/src/renderer/redux/actions/publish.js index 2421375ab..489c927dc 100644 --- a/src/renderer/redux/actions/publish.js +++ b/src/renderer/redux/actions/publish.js @@ -20,6 +20,7 @@ import fs from 'fs'; import path from 'path'; import { CC_LICENSES, COPYRIGHT, OTHER } from 'constants/licenses'; import type { Dispatch, GetState } from 'types/redux'; +import { Source } from 'types/claim'; type Action = UpdatePublishFormAction | { type: ACTIONS.CLEAR_PUBLISH }; @@ -67,10 +68,12 @@ export const doClearPublish = () => (dispatch: Dispatch): Promise ( dispatch: Dispatch ): UpdatePublishFormAction => - dispatch({ - type: ACTIONS.UPDATE_PUBLISH_FORM, - data: { ...publishFormValue }, - }); + dispatch( + ({ + type: ACTIONS.UPDATE_PUBLISH_FORM, + data: { ...publishFormValue }, + }: UpdatePublishFormAction) + ); export const doUploadThumbnail = (filePath: string, nsfw: boolean) => ( dispatch: Dispatch @@ -155,7 +158,7 @@ export const doPrepareEdit = (claim: any, uri: string) => (dispatch: Dispatch ( licenseUrl, language, thumbnail, + fee: fee || undefined, + description: description || undefined, }; - if (fee) { - metadata.fee = fee; - } - - if (description) { - metadata.description = description; - } - - const publishPayload = { + const publishPayload: { + name: ?string, + channel_id: string, + bid: ?number, + metadata: ?any, + file_path?: string, + sources?: Source, + } = { name, channel_id: channelId, bid, diff --git a/src/renderer/redux/reducers/publish.js b/src/renderer/redux/reducers/publish.js index c3e728384..4b799c8c5 100644 --- a/src/renderer/redux/reducers/publish.js +++ b/src/renderer/redux/reducers/publish.js @@ -4,6 +4,7 @@ import { buildURI } from 'lbry-redux'; import * as ACTIONS from 'constants/action_types'; import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses'; import { CHANNEL_ANONYMOUS } from 'constants/claim'; +import type { StreamSource } from 'types/stream'; type PublishState = { editingURI: ?string, @@ -53,6 +54,8 @@ export type UpdatePublishFormData = { bidError?: string, otherLicenseDescription?: string, licenseUrl?: string, + licenseType?: string, + uri?: string, }; export type UpdatePublishFormAction = { @@ -61,32 +64,27 @@ export type UpdatePublishFormAction = { }; export type PublishParams = { - name: string, - bid: number, - filePath: string, + name?: string, + bid?: number, + filePath?: string, description: ?string, language: string, - publishingLicense: string, - publishingLicenseUrl: string, + publishingLicense?: string, + publishingLicenseUrl?: string, thumbnail: ?string, nsfw: boolean, channel: string, - channelId: string, + channelId?: string, title: string, contentIsFree: boolean, - uri: string, + uri?: string, license: ?string, licenseUrl: ?string, price: { currency: string, amount: number, }, - source?: { - contentType: string, - source: string, - sourceType: string, - version: string, - }, + sources?: StreamSource, }; const defaultState: PublishState = { diff --git a/src/renderer/types/claim.js b/src/renderer/types/claim.js index d45ee3bf3..f3343c476 100644 --- a/src/renderer/types/claim.js +++ b/src/renderer/types/claim.js @@ -1,5 +1,7 @@ // @flow +import type { StreamSource } from 'types/stream'; + // Currently incomplete export type Metadata = { nsfw: boolean, @@ -36,6 +38,7 @@ export type Claim = { }, stream: { metadata: Metadata, + source: StreamSource, }, }, }; diff --git a/src/renderer/types/stream.js b/src/renderer/types/stream.js new file mode 100644 index 000000000..da8435bfa --- /dev/null +++ b/src/renderer/types/stream.js @@ -0,0 +1,8 @@ +// @flow + +export type StreamSource = { + contentType: string, + source: string, + sourceType: string, + version: string, +}; From 2b464833443cd36c2b0d7ab3c3621c8a5b2b928a Mon Sep 17 00:00:00 2001 From: Chakrit Likitkhajorn Date: Sat, 13 Oct 2018 23:42:02 +0700 Subject: [PATCH 2/3] Centralized type to type/claim --- src/renderer/redux/actions/publish.js | 2 +- src/renderer/redux/reducers/publish.js | 4 ++-- src/renderer/types/claim.js | 12 +++++++++--- src/renderer/types/stream.js | 8 -------- 4 files changed, 12 insertions(+), 14 deletions(-) delete mode 100644 src/renderer/types/stream.js diff --git a/src/renderer/redux/actions/publish.js b/src/renderer/redux/actions/publish.js index 489c927dc..ca831c214 100644 --- a/src/renderer/redux/actions/publish.js +++ b/src/renderer/redux/actions/publish.js @@ -20,7 +20,7 @@ import fs from 'fs'; import path from 'path'; import { CC_LICENSES, COPYRIGHT, OTHER } from 'constants/licenses'; import type { Dispatch, GetState } from 'types/redux'; -import { Source } from 'types/claim'; +import type { Source } from 'types/claim'; type Action = UpdatePublishFormAction | { type: ACTIONS.CLEAR_PUBLISH }; diff --git a/src/renderer/redux/reducers/publish.js b/src/renderer/redux/reducers/publish.js index 4b799c8c5..53e20375c 100644 --- a/src/renderer/redux/reducers/publish.js +++ b/src/renderer/redux/reducers/publish.js @@ -4,7 +4,7 @@ import { buildURI } from 'lbry-redux'; import * as ACTIONS from 'constants/action_types'; import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses'; import { CHANNEL_ANONYMOUS } from 'constants/claim'; -import type { StreamSource } from 'types/stream'; +import type { Source } from 'types/claim'; type PublishState = { editingURI: ?string, @@ -84,7 +84,7 @@ export type PublishParams = { currency: string, amount: number, }, - sources?: StreamSource, + sources?: Source, }; const defaultState: PublishState = { diff --git a/src/renderer/types/claim.js b/src/renderer/types/claim.js index f3343c476..dcc8fef1e 100644 --- a/src/renderer/types/claim.js +++ b/src/renderer/types/claim.js @@ -1,8 +1,14 @@ // @flow -import type { StreamSource } from 'types/stream'; - // Currently incomplete + +export type Source = { + contentType: string, + source: string, + sourceType: string, + version: string, +}; + export type Metadata = { nsfw: boolean, title: string, @@ -38,7 +44,7 @@ export type Claim = { }, stream: { metadata: Metadata, - source: StreamSource, + source: Source, }, }, }; diff --git a/src/renderer/types/stream.js b/src/renderer/types/stream.js deleted file mode 100644 index da8435bfa..000000000 --- a/src/renderer/types/stream.js +++ /dev/null @@ -1,8 +0,0 @@ -// @flow - -export type StreamSource = { - contentType: string, - source: string, - sourceType: string, - version: string, -}; From 7e79323ab4e533daed3c6fdfbf7cc5e1dbd8986f Mon Sep 17 00:00:00 2001 From: Chakrit Likitkhajorn Date: Sun, 14 Oct 2018 19:03:17 +0700 Subject: [PATCH 3/3] Add changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8270fb16f..963bc6328 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,13 +10,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * Focus on search bar with {cmd,ctrl} + "l" ([#2003](https://github.com/lbryio/lbry-desktop/pull/2003)) * Add support for clickable channel names on explore page headings ([#2023](https://github.com/lbryio/lbry-desktop/pull/2023)) * Content loading placeholder styles on FileCard/FileTile ([#2022](https://github.com/lbryio/lbry-desktop/pull/2022)) - + ### Changed * Make tooltip smarter ([#1979](https://github.com/lbryio/lbry-desktop/pull/1979)) * Change channel pages to have 48 items instead of 10 ([#2002](https://github.com/lbryio/lbry-desktop/pull/2002)) * Update to https ([#2016](https://github.com/lbryio/lbry-desktop/pull/2016)) * Simplify FileCard and FileTile component styling ([#2011](https://github.com/lbryio/lbry-desktop/pull/2011)) * Credit card verification messaging ([#2025](https://github.com/lbryio/lbry-desktop/pull/2025)) + * Limit file type can be uploaded as thumbnail for publishing ([#2034](https://github.com/lbryio/lbry-desktop/pull/2034)) ### Fixed * Fixed Transactions filter menu collides with transaction table ([#2005](https://github.com/lbryio/lbry-desktop/pull/2005))