From 297921fce570bfab413bab4e16a4ae694ecc4f28 Mon Sep 17 00:00:00 2001 From: kibigo! Date: Wed, 12 Jul 2017 01:02:51 -0700 Subject: Moved glitch files to their own location ;) --- app/javascript/glitch/components/settings/index.js | 221 +++++++++++++++++++++ app/javascript/glitch/components/settings/item.js | 79 ++++++++ 2 files changed, 300 insertions(+) create mode 100644 app/javascript/glitch/components/settings/index.js create mode 100644 app/javascript/glitch/components/settings/item.js (limited to 'app/javascript/glitch/components/settings') diff --git a/app/javascript/glitch/components/settings/index.js b/app/javascript/glitch/components/settings/index.js new file mode 100644 index 000000000..afe7e9a87 --- /dev/null +++ b/app/javascript/glitch/components/settings/index.js @@ -0,0 +1,221 @@ +// Package imports // +import React from 'react'; +import PropTypes from 'prop-types'; +import ImmutablePropTypes from 'react-immutable-proptypes'; +import { injectIntl, defineMessages, FormattedMessage } from 'react-intl'; + +// Our imports // +import SettingsItem from './item'; + +const messages = defineMessages({ + layout_auto: { id: 'layout.auto', defaultMessage: 'Auto' }, + layout_desktop: { id: 'layout.desktop', defaultMessage: 'Desktop' }, + layout_mobile: { id: 'layout.single', defaultMessage: 'Mobile' }, +}); + +@injectIntl +export default class Settings extends React.PureComponent { + + static propTypes = { + settings: ImmutablePropTypes.map.isRequired, + toggleSetting: PropTypes.func.isRequired, + changeSetting: PropTypes.func.isRequired, + onClose: PropTypes.func.isRequired, + intl: PropTypes.object.isRequired, + }; + + state = { + currentIndex: 0, + }; + + General = () => { + const { intl } = this.props; + return ( +
+

+ + + + + + + + +
+ ); + } + + CollapsedStatuses = () => { + return ( +
+

+ + + +
+

+ + + + + + + + + + + + + + + +
+
+

+ + + + + + +
+
+ ); + } + + Media = () => { + return ( +
+

+ + + + + + +
+ ); + } + + navigateTo = (e) => + this.setState({ currentIndex: +e.currentTarget.getAttribute('data-mastodon-navigation_index') }); + + render () { + + const { General, CollapsedStatuses, Media, navigateTo } = this; + const { onClose } = this.props; + const { currentIndex } = this.state; + + return ( +
+ + + +
+ { + [ + , + , + , + ][currentIndex] || + } +
+ +
+ ); + } + +} diff --git a/app/javascript/glitch/components/settings/item.js b/app/javascript/glitch/components/settings/item.js new file mode 100644 index 000000000..4c67cc2ac --- /dev/null +++ b/app/javascript/glitch/components/settings/item.js @@ -0,0 +1,79 @@ +// Package imports // +import React from 'react'; +import PropTypes from 'prop-types'; +import ImmutablePropTypes from 'react-immutable-proptypes'; + +export default class SettingsItem extends React.PureComponent { + + static propTypes = { + settings: ImmutablePropTypes.map.isRequired, + item: PropTypes.array.isRequired, + id: PropTypes.string.isRequired, + options: PropTypes.arrayOf(PropTypes.shape({ + value: PropTypes.string.isRequired, + message: PropTypes.object.isRequired, + })), + dependsOn: PropTypes.array, + dependsOnNot: PropTypes.array, + children: PropTypes.element.isRequired, + onChange: PropTypes.func.isRequired, + }; + + handleChange = (e) => { + const { item, onChange } = this.props; + onChange(item, e); + } + + render () { + const { settings, item, id, options, children, dependsOn, dependsOnNot } = this.props; + let enabled = true; + + if (dependsOn) { + for (let i = 0; i < dependsOn.length; i++) { + enabled = enabled && settings.getIn(dependsOn[i]); + } + } + if (dependsOnNot) { + for (let i = 0; i < dependsOnNot.length; i++) { + enabled = enabled && !settings.getIn(dependsOnNot[i]); + } + } + + if (options && options.length > 0) { + const currentValue = settings.getIn(item); + const optionElems = options && options.length > 0 && options.map((opt) => ( + + )); + return ( + + ); + } else { + return ( + + ); + } + } + +} -- cgit