Add SETTINGS.ENABLE_PUBLISH_PREVIEW

This option allows users to bypass the "publish preview" modal. Users can disable it by checking "don't show this again" in the modal, and re-enable it in the Settings Page.
This commit is contained in:
infiinte-persistence 2020-08-11 17:54:09 +08:00 committed by Sean Yesmunt
parent 3588111938
commit 16b1605a35
9 changed files with 79 additions and 4 deletions

View file

@ -11,10 +11,12 @@ import {
doUpdatePublishForm, doUpdatePublishForm,
doPrepareEdit, doPrepareEdit,
doCheckPublishNameAvailability, doCheckPublishNameAvailability,
SETTINGS,
} from 'lbry-redux'; } from 'lbry-redux';
import { doPublishDesktop } from 'redux/actions/publish'; import { doPublishDesktop } from 'redux/actions/publish';
import { selectUnclaimedRewardValue } from 'redux/selectors/rewards'; import { selectUnclaimedRewardValue } from 'redux/selectors/rewards';
import { selectModal } from 'redux/selectors/app'; import { selectModal } from 'redux/selectors/app';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import PublishPage from './view'; import PublishPage from './view';
const select = state => ({ const select = state => ({
@ -29,6 +31,7 @@ const select = state => ({
isResolvingUri: selectIsResolvingPublishUris(state), isResolvingUri: selectIsResolvingPublishUris(state),
totalRewardValue: selectUnclaimedRewardValue(state), totalRewardValue: selectUnclaimedRewardValue(state),
modal: selectModal(state), modal: selectModal(state),
enablePublishPreview: makeSelectClientSetting(SETTINGS.ENABLE_PUBLISH_PREVIEW)(state),
}); });
const perform = dispatch => ({ const perform = dispatch => ({

View file

@ -79,6 +79,7 @@ type Props = {
checkAvailability: string => void, checkAvailability: string => void,
ytSignupPending: boolean, ytSignupPending: boolean,
modal: { id: string, modalProps: {} }, modal: { id: string, modalProps: {} },
enablePublishPreview: boolean,
}; };
function PublishForm(props: Props) { function PublishForm(props: Props) {
@ -116,6 +117,7 @@ function PublishForm(props: Props) {
checkAvailability, checkAvailability,
ytSignupPending, ytSignupPending,
modal, modal,
enablePublishPreview,
} = props; } = props;
// Used to check if name should be auto-populated from title // Used to check if name should be auto-populated from title
@ -287,7 +289,7 @@ function PublishForm(props: Props) {
} }
// Publish file // Publish file
if (mode === PUBLISH_MODES.FILE) { if (mode === PUBLISH_MODES.FILE) {
if (isStillEditing) { if (isStillEditing || !enablePublishPreview) {
publish(filePath, false); publish(filePath, false);
} else { } else {
setPreviewing(true); setPreviewing(true);

View file

@ -0,0 +1,15 @@
import { SETTINGS } from 'lbry-redux';
import { connect } from 'react-redux';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import { doSetClientSetting } from 'redux/actions/settings';
import PublishSettings from './view';
const select = state => ({
enablePublishPreview: makeSelectClientSetting(SETTINGS.ENABLE_PUBLISH_PREVIEW)(state),
});
const perform = dispatch => ({
setEnablePublishPreview: value => dispatch(doSetClientSetting(SETTINGS.ENABLE_PUBLISH_PREVIEW, value)),
});
export default connect(select, perform)(PublishSettings);

View file

@ -0,0 +1,31 @@
// @flow
import React from 'react';
import { FormField } from 'component/common/form';
import { withRouter } from 'react-router';
type Props = {
enablePublishPreview: boolean,
setEnablePublishPreview: boolean => void,
};
function PublishSettings(props: Props) {
const { enablePublishPreview, setEnablePublishPreview } = props;
function handleChange() {
setEnablePublishPreview(!enablePublishPreview);
}
return (
<div>
<FormField
type="checkbox"
name="sync_toggle"
label={__('Skip preview and confirmation')}
checked={!enablePublishPreview}
onChange={handleChange}
/>
</div>
);
}
export default withRouter(PublishSettings);

View file

@ -23,3 +23,4 @@ export const FLOATING_PLAYER = 'floating_player';
export const DARK_MODE_TIMES = 'dark_mode_times'; export const DARK_MODE_TIMES = 'dark_mode_times';
export const ENABLE_SYNC = 'enable_sync'; export const ENABLE_SYNC = 'enable_sync';
export const TO_TRAY_WHEN_CLOSED = 'to_tray_when_closed'; export const TO_TRAY_WHEN_CLOSED = 'to_tray_when_closed';
export const ENABLE_PUBLISH_PREVIEW = 'enable-publish-preview';

View file

@ -1,19 +1,22 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { doHideModal } from 'redux/actions/app'; import { doHideModal } from 'redux/actions/app';
import ModalPublishPreview from './view'; import ModalPublishPreview from './view';
import { makeSelectPublishFormValue, selectPublishFormValues } from 'lbry-redux'; import { makeSelectPublishFormValue, selectPublishFormValues, SETTINGS } from 'lbry-redux';
import { selectFfmpegStatus } from 'redux/selectors/settings'; import { selectFfmpegStatus, makeSelectClientSetting } from 'redux/selectors/settings';
import { doPublishDesktop } from 'redux/actions/publish'; import { doPublishDesktop } from 'redux/actions/publish';
import { doSetClientSetting } from 'redux/actions/settings';
const select = state => ({ const select = state => ({
...selectPublishFormValues(state), ...selectPublishFormValues(state),
isVid: makeSelectPublishFormValue('fileVid')(state), isVid: makeSelectPublishFormValue('fileVid')(state),
ffmpegStatus: selectFfmpegStatus(state), ffmpegStatus: selectFfmpegStatus(state),
enablePublishPreview: makeSelectClientSetting(SETTINGS.ENABLE_PUBLISH_PREVIEW)(state),
}); });
const perform = dispatch => ({ const perform = dispatch => ({
publish: (filePath, preview) => dispatch(doPublishDesktop(filePath, preview)), publish: (filePath, preview) => dispatch(doPublishDesktop(filePath, preview)),
closeModal: () => dispatch(doHideModal()), closeModal: () => dispatch(doHideModal()),
setEnablePublishPreview: value => dispatch(doSetClientSetting(SETTINGS.ENABLE_PUBLISH_PREVIEW, value)),
}); });
export default connect(select, perform)(ModalPublishPreview); export default connect(select, perform)(ModalPublishPreview);

View file

@ -1,7 +1,7 @@
// @flow // @flow
import React from 'react'; import React from 'react';
import Button from 'component/button'; import Button from 'component/button';
import { Form } from 'component/common/form'; import { Form, FormField } from 'component/common/form';
import { Modal } from 'modal/modal'; import { Modal } from 'modal/modal';
import Card from 'component/common/card'; import Card from 'component/common/card';
import Tag from 'component/tag'; import Tag from 'component/tag';
@ -31,6 +31,8 @@ type Props = {
previewResponse: PublishResponse, previewResponse: PublishResponse,
publish: (?string, ?boolean) => void, publish: (?string, ?boolean) => void,
closeModal: () => void, closeModal: () => void,
enablePublishPreview: boolean,
setEnablePublishPreview: boolean => void,
}; };
class ModalPublishPreview extends React.PureComponent<Props> { class ModalPublishPreview extends React.PureComponent<Props> {
@ -58,6 +60,11 @@ class ModalPublishPreview extends React.PureComponent<Props> {
); );
} }
togglePreviewEnabled() {
const { enablePublishPreview, setEnablePublishPreview } = this.props;
setEnablePublishPreview(!enablePublishPreview);
}
render() { render() {
const { const {
filePath, filePath,
@ -78,6 +85,8 @@ class ModalPublishPreview extends React.PureComponent<Props> {
ffmpegStatus = {}, ffmpegStatus = {},
previewResponse, previewResponse,
closeModal, closeModal,
enablePublishPreview,
setEnablePublishPreview,
} = this.props; } = this.props;
const modalTitle = __('Confirm Publish'); const modalTitle = __('Confirm Publish');
@ -145,6 +154,13 @@ class ModalPublishPreview extends React.PureComponent<Props> {
<Button button="link" label={__('Cancel')} onClick={closeModal} /> <Button button="link" label={__('Cancel')} onClick={closeModal} />
</div> </div>
<p className="help">{__('Once the transaction is sent, it cannot be reversed.')}</p> <p className="help">{__('Once the transaction is sent, it cannot be reversed.')}</p>
<FormField
type="checkbox"
name="sync_toggle"
label={__('Skip preview and confirmation')}
checked={!enablePublishPreview}
onChange={() => setEnablePublishPreview(!enablePublishPreview)}
/>
</> </>
} }
/> />

View file

@ -13,6 +13,7 @@ import { SETTINGS } from 'lbry-redux';
import Card from 'component/common/card'; import Card from 'component/common/card';
import { getPasswordFromCookie } from 'util/saved-passwords'; import { getPasswordFromCookie } from 'util/saved-passwords';
import Spinner from 'component/spinner'; import Spinner from 'component/spinner';
import PublishSettings from 'component/publishSettings';
// @if TARGET='app' // @if TARGET='app'
const IS_MAC = process.platform === 'darwin'; const IS_MAC = process.platform === 'darwin';
@ -506,6 +507,8 @@ class SettingsPage extends React.PureComponent<Props, State> {
/> />
)} )}
<Card title={__('Publish Settings')} actions={<PublishSettings />} />
{/* @if TARGET='app' */} {/* @if TARGET='app' */}
{/* Auto launch in a hidden state doesn't work on mac https://github.com/Teamwork/node-auto-launch/issues/81 */} {/* Auto launch in a hidden state doesn't work on mac https://github.com/Teamwork/node-auto-launch/issues/81 */}
{!IS_MAC && <Card title={__('Startup preferences')} actions={<SettingAutoLaunch />} />} {!IS_MAC && <Card title={__('Startup preferences')} actions={<SettingAutoLaunch />} />}

View file

@ -33,6 +33,7 @@ const defaultState = {
[SETTINGS.FOLLOWING_ACKNOWLEDGED]: false, [SETTINGS.FOLLOWING_ACKNOWLEDGED]: false,
[SETTINGS.TAGS_ACKNOWLEDGED]: false, [SETTINGS.TAGS_ACKNOWLEDGED]: false,
[SETTINGS.ENABLE_SYNC]: IS_WEB, [SETTINGS.ENABLE_SYNC]: IS_WEB,
[SETTINGS.ENABLE_PUBLISH_PREVIEW]: true,
// UI // UI
[SETTINGS.LANGUAGE]: settingLanguage.find(language => SUPPORTED_LANGUAGES[language]), [SETTINGS.LANGUAGE]: settingLanguage.find(language => SUPPORTED_LANGUAGES[language]),