Merge branch 'configurable-md' into 'develop'
Make Markdown posting configurable, use text/plain by default See merge request soapbox-pub/soapbox-fe!399
This commit is contained in:
commit
64845b1c6e
4 changed files with 47 additions and 12 deletions
|
@ -21,6 +21,7 @@ export const defaultSettings = ImmutableMap({
|
||||||
boostModal: false,
|
boostModal: false,
|
||||||
deleteModal: true,
|
deleteModal: true,
|
||||||
defaultPrivacy: 'public',
|
defaultPrivacy: 'public',
|
||||||
|
defaultContentType: 'text/plain',
|
||||||
themeMode: 'light',
|
themeMode: 'light',
|
||||||
locale: navigator.language.split(/[-_]/)[0] || 'en',
|
locale: navigator.language.split(/[-_]/)[0] || 'en',
|
||||||
explanationBox: true,
|
explanationBox: true,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import { changeSetting } from 'soapbox/actions/settings';
|
import { getSettings, changeSetting } from 'soapbox/actions/settings';
|
||||||
import Column from '../ui/components/column';
|
import Column from '../ui/components/column';
|
||||||
import {
|
import {
|
||||||
SimpleForm,
|
SimpleForm,
|
||||||
|
@ -85,7 +85,7 @@ const messages = defineMessages({
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
settings: state.get('settings'),
|
settings: getSettings(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default @connect(mapStateToProps)
|
export default @connect(mapStateToProps)
|
||||||
|
@ -109,6 +109,11 @@ class Preferences extends ImmutablePureComponent {
|
||||||
dispatch(changeSetting(['defaultPrivacy'], e.target.value));
|
dispatch(changeSetting(['defaultPrivacy'], e.target.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDefaultContentTypeChange = e => {
|
||||||
|
const { dispatch } = this.props;
|
||||||
|
dispatch(changeSetting(['defaultContentType'], e.target.value));
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { settings, intl } = this.props;
|
const { settings, intl } = this.props;
|
||||||
|
|
||||||
|
@ -165,6 +170,24 @@ class Preferences extends ImmutablePureComponent {
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
</FieldsGroup>
|
</FieldsGroup>
|
||||||
|
|
||||||
|
<FieldsGroup>
|
||||||
|
<RadioGroup
|
||||||
|
label={<FormattedMessage id='preferences.fields.content_type_label' defaultMessage='Post format' />}
|
||||||
|
onChange={this.onDefaultContentTypeChange}
|
||||||
|
>
|
||||||
|
<RadioItem
|
||||||
|
label={<FormattedMessage id='preferences.options.content_type_plaintext' defaultMessage='Plain text' />}
|
||||||
|
checked={settings.get('defaultContentType') === 'text/plain'}
|
||||||
|
value='text/plain'
|
||||||
|
/>
|
||||||
|
<RadioItem
|
||||||
|
label={<FormattedMessage id='preferences.options.content_type_markdown' defaultMessage='Markdown' />}
|
||||||
|
checked={settings.get('defaultContentType') === 'text/markdown'}
|
||||||
|
value='text/markdown'
|
||||||
|
/>
|
||||||
|
</RadioGroup>
|
||||||
|
</FieldsGroup>
|
||||||
|
|
||||||
<FieldsGroup>
|
<FieldsGroup>
|
||||||
<SettingsCheckbox
|
<SettingsCheckbox
|
||||||
label={<FormattedMessage id='preferences.fields.unfollow_modal_label' defaultMessage='Show confirmation dialog before unfollowing someone' />}
|
label={<FormattedMessage id='preferences.fields.unfollow_modal_label' defaultMessage='Show confirmation dialog before unfollowing someone' />}
|
||||||
|
|
|
@ -31,7 +31,7 @@ describe('compose reducer', () => {
|
||||||
default_privacy: 'public',
|
default_privacy: 'public',
|
||||||
default_sensitive: false,
|
default_sensitive: false,
|
||||||
tagHistory: [],
|
tagHistory: [],
|
||||||
content_type: 'text/markdown',
|
content_type: 'text/plain',
|
||||||
});
|
});
|
||||||
expect(state.get('idempotencyKey').length === 36);
|
expect(state.get('idempotencyKey').length === 36);
|
||||||
});
|
});
|
||||||
|
|
|
@ -52,7 +52,7 @@ const initialState = ImmutableMap({
|
||||||
sensitive: false,
|
sensitive: false,
|
||||||
spoiler: false,
|
spoiler: false,
|
||||||
spoiler_text: '',
|
spoiler_text: '',
|
||||||
content_type: 'text/markdown',
|
content_type: 'text/plain',
|
||||||
privacy: 'public',
|
privacy: 'public',
|
||||||
text: '',
|
text: '',
|
||||||
focusDate: null,
|
focusDate: null,
|
||||||
|
@ -69,6 +69,7 @@ const initialState = ImmutableMap({
|
||||||
suggestions: ImmutableList(),
|
suggestions: ImmutableList(),
|
||||||
default_privacy: 'public',
|
default_privacy: 'public',
|
||||||
default_sensitive: false,
|
default_sensitive: false,
|
||||||
|
default_content_type: 'text/plain',
|
||||||
resetFileKey: Math.floor((Math.random() * 0x10000)),
|
resetFileKey: Math.floor((Math.random() * 0x10000)),
|
||||||
idempotencyKey: uuid(),
|
idempotencyKey: uuid(),
|
||||||
tagHistory: ImmutableList(),
|
tagHistory: ImmutableList(),
|
||||||
|
@ -97,7 +98,7 @@ function clearAll(state) {
|
||||||
map.set('text', '');
|
map.set('text', '');
|
||||||
map.set('spoiler', false);
|
map.set('spoiler', false);
|
||||||
map.set('spoiler_text', '');
|
map.set('spoiler_text', '');
|
||||||
map.set('content_type', 'text/markdown');
|
map.set('content_type', state.get('default_content_type'));
|
||||||
map.set('is_submitting', false);
|
map.set('is_submitting', false);
|
||||||
map.set('is_changing_upload', false);
|
map.set('is_changing_upload', false);
|
||||||
map.set('in_reply_to', null);
|
map.set('in_reply_to', null);
|
||||||
|
@ -193,7 +194,7 @@ const expandMentions = status => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function compose(state = initialState, action) {
|
export default function compose(state = initialState, action) {
|
||||||
let me, defaultPrivacy;
|
let me, defaultPrivacy, defaultContentType;
|
||||||
switch(action.type) {
|
switch(action.type) {
|
||||||
case COMPOSE_MOUNT:
|
case COMPOSE_MOUNT:
|
||||||
return state.set('mounted', state.get('mounted') + 1);
|
return state.set('mounted', state.get('mounted') + 1);
|
||||||
|
@ -246,7 +247,7 @@ export default function compose(state = initialState, action) {
|
||||||
map.set('focusDate', new Date());
|
map.set('focusDate', new Date());
|
||||||
map.set('caretPosition', null);
|
map.set('caretPosition', null);
|
||||||
map.set('idempotencyKey', uuid());
|
map.set('idempotencyKey', uuid());
|
||||||
map.set('content_type', 'text/markdown');
|
map.set('content_type', state.get('default_content_type'));
|
||||||
|
|
||||||
if (action.status.get('spoiler_text', '').length > 0) {
|
if (action.status.get('spoiler_text', '').length > 0) {
|
||||||
map.set('spoiler', true);
|
map.set('spoiler', true);
|
||||||
|
@ -331,7 +332,7 @@ export default function compose(state = initialState, action) {
|
||||||
map.set('focusDate', new Date());
|
map.set('focusDate', new Date());
|
||||||
map.set('caretPosition', null);
|
map.set('caretPosition', null);
|
||||||
map.set('idempotencyKey', uuid());
|
map.set('idempotencyKey', uuid());
|
||||||
map.set('content_type', 'text/markdown');
|
map.set('content_type', action.status.get('content_type'));
|
||||||
|
|
||||||
if (action.status.get('spoiler_text').length > 0) {
|
if (action.status.get('spoiler_text').length > 0) {
|
||||||
map.set('spoiler', true);
|
map.set('spoiler', true);
|
||||||
|
@ -364,21 +365,31 @@ export default function compose(state = initialState, action) {
|
||||||
case ME_FETCH_SUCCESS:
|
case ME_FETCH_SUCCESS:
|
||||||
me = fromJS(action.me);
|
me = fromJS(action.me);
|
||||||
defaultPrivacy = me.getIn(['pleroma', 'settings_store', FE_NAME, 'defaultPrivacy'], 'public');
|
defaultPrivacy = me.getIn(['pleroma', 'settings_store', FE_NAME, 'defaultPrivacy'], 'public');
|
||||||
|
defaultContentType = me.getIn(['pleroma', 'settings_store', FE_NAME, 'defaultContentType'], 'text/plain');
|
||||||
return state.merge({
|
return state.merge({
|
||||||
default_privacy: defaultPrivacy,
|
default_privacy: defaultPrivacy,
|
||||||
privacy: defaultPrivacy,
|
privacy: defaultPrivacy,
|
||||||
|
default_content_type: defaultContentType,
|
||||||
|
content_type: defaultContentType,
|
||||||
tagHistory: ImmutableList(tagHistory.get(action.me.id)),
|
tagHistory: ImmutableList(tagHistory.get(action.me.id)),
|
||||||
});
|
});
|
||||||
case ME_PATCH_SUCCESS:
|
case ME_PATCH_SUCCESS:
|
||||||
me = fromJS(action.me);
|
me = fromJS(action.me);
|
||||||
defaultPrivacy = me.getIn(['pleroma', 'settings_store', FE_NAME, 'defaultPrivacy']);
|
defaultPrivacy = me.getIn(['pleroma', 'settings_store', FE_NAME, 'defaultPrivacy']);
|
||||||
if (!defaultPrivacy) return state;
|
defaultContentType = me.getIn(['pleroma', 'settings_store', FE_NAME, 'defaultContentType']);
|
||||||
return state.set('default_privacy', defaultPrivacy);
|
if (defaultPrivacy) state = state.set('default_privacy', defaultPrivacy);
|
||||||
|
if (defaultContentType) state = state.set('default_content_type', defaultContentType);
|
||||||
|
return state;
|
||||||
case SETTING_CHANGE:
|
case SETTING_CHANGE:
|
||||||
const pathString = action.path.join(',');
|
const pathString = action.path.join(',');
|
||||||
if (pathString === 'defaultPrivacy')
|
switch (pathString) {
|
||||||
|
case 'defaultPrivacy':
|
||||||
return state.set('default_privacy', action.value).set('privacy', action.value);
|
return state.set('default_privacy', action.value).set('privacy', action.value);
|
||||||
return state;
|
case 'defaultContentType':
|
||||||
|
return state.set('default_content_type', action.value).set('content_type', action.value);
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue