From 1544ac4e2798e969cb9d6d14a361f90517726cfc Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Wed, 29 Aug 2018 15:26:24 +0200 Subject: Add confirmation dialog when posting media without description Fixes #211 --- .../flavours/glitch/features/local_settings/page/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/javascript/flavours/glitch/features/local_settings') diff --git a/app/javascript/flavours/glitch/features/local_settings/page/index.js b/app/javascript/flavours/glitch/features/local_settings/page/index.js index ad5c11979..1e61c67c0 100644 --- a/app/javascript/flavours/glitch/features/local_settings/page/index.js +++ b/app/javascript/flavours/glitch/features/local_settings/page/index.js @@ -83,6 +83,14 @@ export default class LocalSettingsPage extends React.PureComponent { > + + + Date: Tue, 28 Aug 2018 14:10:26 +0200 Subject: Add a setting to automatically unfold all content warnings --- app/javascript/flavours/glitch/components/status.js | 1 + .../glitch/features/local_settings/navigation/index.js | 17 ++++++++++++----- .../glitch/features/local_settings/page/index.js | 13 +++++++++++++ app/javascript/flavours/glitch/features/status/index.js | 4 ++-- .../flavours/glitch/reducers/local_settings.js | 3 +++ 5 files changed, 31 insertions(+), 7 deletions(-) (limited to 'app/javascript/flavours/glitch/features/local_settings') diff --git a/app/javascript/flavours/glitch/components/status.js b/app/javascript/flavours/glitch/components/status.js index 1ac5a4b3e..e0d591ff6 100644 --- a/app/javascript/flavours/glitch/components/status.js +++ b/app/javascript/flavours/glitch/components/status.js @@ -56,6 +56,7 @@ export default class Status extends ImmutablePureComponent { state = { isCollapsed: false, autoCollapsed: false, + isExpanded: this.props.settings.getIn(['content_warnings', 'auto_unfold']), } // Avoid checking props that are functions (and whose equality will always diff --git a/app/javascript/flavours/glitch/features/local_settings/navigation/index.js b/app/javascript/flavours/glitch/features/local_settings/navigation/index.js index fc2167c0c..0c1040290 100644 --- a/app/javascript/flavours/glitch/features/local_settings/navigation/index.js +++ b/app/javascript/flavours/glitch/features/local_settings/navigation/index.js @@ -10,6 +10,7 @@ import LocalSettingsNavigationItem from './item'; const messages = defineMessages({ general: { id: 'settings.general', defaultMessage: 'General' }, + content_warnings: { id: 'settings.content_warnings', defaultMessage: 'Content Warnings' }, collapsed: { id: 'settings.collapsed_statuses', defaultMessage: 'Collapsed toots' }, media: { id: 'settings.media', defaultMessage: 'Media' }, preferences: { id: 'settings.preferences', defaultMessage: 'Preferences' }, @@ -42,25 +43,31 @@ export default class LocalSettingsNavigation extends React.PureComponent { active={index === 1} index={1} onNavigate={onNavigate} - title={intl.formatMessage(messages.collapsed)} + title={intl.formatMessage(messages.content_warnings)} /> + diff --git a/app/javascript/flavours/glitch/features/local_settings/page/index.js b/app/javascript/flavours/glitch/features/local_settings/page/index.js index 1e61c67c0..37396d970 100644 --- a/app/javascript/flavours/glitch/features/local_settings/page/index.js +++ b/app/javascript/flavours/glitch/features/local_settings/page/index.js @@ -122,6 +122,19 @@ export default class LocalSettingsPage extends React.PureComponent { ), + ({ onChange, settings }) => ( +
+

+ + + +
+ ), ({ onChange, settings }) => (

diff --git a/app/javascript/flavours/glitch/features/status/index.js b/app/javascript/flavours/glitch/features/status/index.js index 1fceaa5ea..060f2f345 100644 --- a/app/javascript/flavours/glitch/features/status/index.js +++ b/app/javascript/flavours/glitch/features/status/index.js @@ -82,8 +82,8 @@ export default class Status extends ImmutablePureComponent { state = { fullscreen: false, - isExpanded: false, - threadExpanded: null, + isExpanded: this.props.settings.getIn(['content_warnings', 'auto_unfold']), + threadExpanded: undefined, }; componentWillMount () { diff --git a/app/javascript/flavours/glitch/reducers/local_settings.js b/app/javascript/flavours/glitch/reducers/local_settings.js index ebe0b1292..ce33cac83 100644 --- a/app/javascript/flavours/glitch/reducers/local_settings.js +++ b/app/javascript/flavours/glitch/reducers/local_settings.js @@ -14,6 +14,9 @@ const initialState = ImmutableMap({ show_reply_count : false, always_show_spoilers_field: false, confirm_missing_media_description: false, + content_warnings : ImmutableMap({ + auto_unfold : false, + }), collapsed : ImmutableMap({ enabled : true, auto : ImmutableMap({ -- cgit From 5c400a28422121df01fc5ae73bc201f3b9aa5288 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Tue, 28 Aug 2018 17:15:50 +0200 Subject: Allow text inputs in local settings dialog --- .../features/local_settings/page/item/index.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'app/javascript/flavours/glitch/features/local_settings') diff --git a/app/javascript/flavours/glitch/features/local_settings/page/item/index.js b/app/javascript/flavours/glitch/features/local_settings/page/item/index.js index 66e84dfe1..fe237f11e 100644 --- a/app/javascript/flavours/glitch/features/local_settings/page/item/index.js +++ b/app/javascript/flavours/glitch/features/local_settings/page/item/index.js @@ -19,18 +19,20 @@ export default class LocalSettingsPageItem extends React.PureComponent { message: PropTypes.string.isRequired, })), settings: ImmutablePropTypes.map.isRequired, + placeholder: PropTypes.string, }; handleChange = e => { const { target } = e; - const { item, onChange, options } = this.props; + const { item, onChange, options, placeholder } = this.props; if (options && options.length > 0) onChange(item, target.value); + else if (placeholder) onChange(item, target.value); else onChange(item, target.checked); } render () { const { handleChange } = this; - const { settings, item, id, options, children, dependsOn, dependsOnNot } = this.props; + const { settings, item, id, options, children, dependsOn, dependsOnNot, placeholder } = this.props; let enabled = true; if (dependsOn) { @@ -70,6 +72,22 @@ export default class LocalSettingsPageItem extends React.PureComponent {

); + } else if (placeholder) { + return ( + + ); } else return (
), - ({ onChange, settings }) => ( + ({ intl, onChange, settings }) => (

+ + +
), ({ onChange, settings }) => ( diff --git a/app/javascript/flavours/glitch/features/status/index.js b/app/javascript/flavours/glitch/features/status/index.js index 060f2f345..3d309976a 100644 --- a/app/javascript/flavours/glitch/features/status/index.js +++ b/app/javascript/flavours/glitch/features/status/index.js @@ -38,6 +38,7 @@ import ImmutablePureComponent from 'react-immutable-pure-component'; import { HotKeys } from 'react-hotkeys'; import { boostModal, favouriteModal, deleteModal } from 'flavours/glitch/util/initial_state'; import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from 'flavours/glitch/util/fullscreen'; +import { autoUnfoldCW } from 'flavours/glitch/util/content_warning'; const messages = defineMessages({ deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' }, @@ -82,7 +83,7 @@ export default class Status extends ImmutablePureComponent { state = { fullscreen: false, - isExpanded: this.props.settings.getIn(['content_warnings', 'auto_unfold']), + isExpanded: undefined, threadExpanded: undefined, }; @@ -95,9 +96,14 @@ export default class Status extends ImmutablePureComponent { } componentWillReceiveProps (nextProps) { + if (this.state.isExpanded === undefined) { + const isExpanded = autoUnfoldCW(nextProps.settings, nextProps.status); + if (isExpanded !== undefined) this.setState({ isExpanded: isExpanded }); + } if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) { this._scrolledIntoView = false; this.props.dispatch(fetchStatus(nextProps.params.statusId)); + this.setState({ isExpanded: autoUnfoldCW(nextProps.settings, nextProps.status) }); } } diff --git a/app/javascript/flavours/glitch/reducers/local_settings.js b/app/javascript/flavours/glitch/reducers/local_settings.js index ce33cac83..063ae3943 100644 --- a/app/javascript/flavours/glitch/reducers/local_settings.js +++ b/app/javascript/flavours/glitch/reducers/local_settings.js @@ -16,6 +16,7 @@ const initialState = ImmutableMap({ confirm_missing_media_description: false, content_warnings : ImmutableMap({ auto_unfold : false, + filter : null, }), collapsed : ImmutableMap({ enabled : true, diff --git a/app/javascript/flavours/glitch/util/content_warning.js b/app/javascript/flavours/glitch/util/content_warning.js new file mode 100644 index 000000000..29e221c8e --- /dev/null +++ b/app/javascript/flavours/glitch/util/content_warning.js @@ -0,0 +1,19 @@ +export function autoUnfoldCW (settings, status) { + if (!settings.getIn(['content_warnings', 'auto_unfold'])) { + return false; + } + + const rawRegex = settings.getIn(['content_warnings', 'filter']); + let regex = null; + + try { + regex = rawRegex && new RegExp(rawRegex.trim(), 'i'); + } catch (e) { + // Bad regex, don't affect filters + } + + if (!(status && regex)) { + return undefined; + } + return !regex.test(status.get('spoiler_text')); +} -- cgit