From f38213fc9d694a9dda44ba7f02febb1e9e89a8d9 Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Fri, 13 Dec 2019 17:19:37 +0100 Subject: [PATCH] :zap: pseudo code for messaging box --- .../compose/components/compose_form.js | 138 ++++++++++-------- app/javascript/styles/bliss/messaging.scss | 8 + 2 files changed, 87 insertions(+), 59 deletions(-) create mode 100644 app/javascript/styles/bliss/messaging.scss diff --git a/app/javascript/mastodon/features/compose/components/compose_form.js b/app/javascript/mastodon/features/compose/components/compose_form.js index 85ef3875a..5f5bdd20e 100644 --- a/app/javascript/mastodon/features/compose/components/compose_form.js +++ b/app/javascript/mastodon/features/compose/components/compose_form.js @@ -24,10 +24,10 @@ import Icon from 'mastodon/components/icon'; const allowedAroundShortCode = '><\u0085\u0020\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029\u0009\u000a\u000b\u000c\u000d'; const messages = defineMessages({ - placeholder: { id: 'compose_form.placeholder', defaultMessage: 'What is on your mind?' }, + placeholder : { id: 'compose_form.placeholder', defaultMessage: 'What is on your mind?' }, spoiler_placeholder: { id: 'compose_form.spoiler_placeholder', defaultMessage: 'Write your warning here' }, - publish: { id: 'compose_form.publish', defaultMessage: 'Toot' }, - publishLoud: { id: 'compose_form.publish_loud', defaultMessage: '{publish}!' }, + publish : { id: 'compose_form.publish', defaultMessage: 'Toot' }, + publishLoud : { id: 'compose_form.publish_loud', defaultMessage: '{publish}!' }, }); export default @injectIntl @@ -38,29 +38,29 @@ class ComposeForm extends ImmutablePureComponent { }; static propTypes = { - intl: PropTypes.object.isRequired, - text: PropTypes.string.isRequired, - suggestions: ImmutablePropTypes.list, - spoiler: PropTypes.bool, - privacy: PropTypes.string, - spoilerText: PropTypes.string, - focusDate: PropTypes.instanceOf(Date), - caretPosition: PropTypes.number, - preselectDate: PropTypes.instanceOf(Date), - isSubmitting: PropTypes.bool, - isChangingUpload: PropTypes.bool, - isUploading: PropTypes.bool, - onChange: PropTypes.func.isRequired, - onSubmit: PropTypes.func.isRequired, - onClearSuggestions: PropTypes.func.isRequired, - onFetchSuggestions: PropTypes.func.isRequired, + intl : PropTypes.object.isRequired, + text : PropTypes.string.isRequired, + suggestions : ImmutablePropTypes.list, + spoiler : PropTypes.bool, + privacy : PropTypes.string, + spoilerText : PropTypes.string, + focusDate : PropTypes.instanceOf(Date), + caretPosition : PropTypes.number, + preselectDate : PropTypes.instanceOf(Date), + isSubmitting : PropTypes.bool, + isChangingUpload : PropTypes.bool, + isUploading : PropTypes.bool, + onChange : PropTypes.func.isRequired, + onSubmit : PropTypes.func.isRequired, + onClearSuggestions : PropTypes.func.isRequired, + onFetchSuggestions : PropTypes.func.isRequired, onSuggestionSelected: PropTypes.func.isRequired, - onChangeSpoilerText: PropTypes.func.isRequired, - onPaste: PropTypes.func.isRequired, - onPickEmoji: PropTypes.func.isRequired, - showSearch: PropTypes.bool, - anyMedia: PropTypes.bool, - singleColumn: PropTypes.bool, + onChangeSpoilerText : PropTypes.func.isRequired, + onPaste : PropTypes.func.isRequired, + onPickEmoji : PropTypes.func.isRequired, + showSearch : PropTypes.bool, + anyMedia : PropTypes.bool, + singleColumn : PropTypes.bool, }; static defaultProps = { @@ -69,13 +69,13 @@ class ComposeForm extends ImmutablePureComponent { handleChange = (e) => { this.props.onChange(e.target.value); - } + }; handleKeyDown = (e) => { if (e.keyCode === 13 && (e.ctrlKey || e.metaKey)) { this.handleSubmit(); } - } + }; handleSubmit = () => { if (this.props.text !== this.autosuggestTextarea.textarea.value) { @@ -93,27 +93,27 @@ class ComposeForm extends ImmutablePureComponent { } this.props.onSubmit(this.context.router ? this.context.router.history : null); - } + }; onSuggestionsClearRequested = () => { this.props.onClearSuggestions(); - } + }; onSuggestionsFetchRequested = (token) => { this.props.onFetchSuggestions(token); - } + }; onSuggestionSelected = (tokenStart, token, value) => { this.props.onSuggestionSelected(tokenStart, token, value, ['text']); - } + }; onSpoilerSuggestionSelected = (tokenStart, token, value) => { this.props.onSuggestionSelected(tokenStart, token, value, ['spoiler_text']); - } + }; handleChangeSpoilerText = (e) => { this.props.onChangeSpoilerText(e.target.value); - } + }; handleFocus = () => { if (this.composeForm && !this.props.singleColumn) { @@ -122,9 +122,9 @@ class ComposeForm extends ImmutablePureComponent { this.composeForm.scrollIntoView(); } } - } + }; - componentDidUpdate (prevProps) { + componentDidUpdate(prevProps) { // This statement does several things: // - If we're beginning a reply, and, // - Replying to zero or one users, places the cursor at the end of the textbox. @@ -134,19 +134,19 @@ class ComposeForm extends ImmutablePureComponent { let selectionEnd, selectionStart; if (this.props.preselectDate !== prevProps.preselectDate) { - selectionEnd = this.props.text.length; + selectionEnd = this.props.text.length; selectionStart = this.props.text.search(/\s/) + 1; } else if (typeof this.props.caretPosition === 'number') { selectionStart = this.props.caretPosition; - selectionEnd = this.props.caretPosition; + selectionEnd = this.props.caretPosition; } else { - selectionEnd = this.props.text.length; + selectionEnd = this.props.text.length; selectionStart = selectionEnd; } this.autosuggestTextarea.textarea.setSelectionRange(selectionStart, selectionEnd); this.autosuggestTextarea.textarea.focus(); - } else if(prevProps.isSubmitting && !this.props.isSubmitting) { + } else if (prevProps.isSubmitting && !this.props.isSubmitting) { this.autosuggestTextarea.textarea.focus(); } else if (this.props.spoiler !== prevProps.spoiler) { if (this.props.spoiler) { @@ -159,42 +159,43 @@ class ComposeForm extends ImmutablePureComponent { setAutosuggestTextarea = (c) => { this.autosuggestTextarea = c; - } + }; setSpoilerText = (c) => { this.spoilerText = c; - } + }; setRef = c => { this.composeForm = c; }; handleEmojiPick = (data) => { - const { text } = this.props; - const position = this.autosuggestTextarea.textarea.selectionStart; - const needsSpace = data.custom && position > 0 && !allowedAroundShortCode.includes(text[position - 1]); + const { text } = this.props; + const position = this.autosuggestTextarea.textarea.selectionStart; + const needsSpace = data.custom && position > 0 && !allowedAroundShortCode.includes(text[position - 1]); this.props.onPickEmoji(position, data, needsSpace); - } + }; - render () { + render() { const { intl, onPaste, showSearch, anyMedia } = this.props; const disabled = this.props.isSubmitting; - const text = [this.props.spoilerText, countableText(this.props.text)].join(''); + const text = [this.props.spoilerText, countableText(this.props.text)].join(''); const disabledButton = disabled || this.props.isUploading || this.props.isChangingUpload || length(text) > 7777 || (text.length !== 0 && text.trim().length === 0 && !anyMedia); let publishText = ''; if (this.props.privacy === 'private' || this.props.privacy === 'direct') { - publishText = {intl.formatMessage(messages.publish)}; + publishText = + {intl.formatMessage(messages.publish)}; } else { publishText = this.props.privacy !== 'unlisted' ? intl.formatMessage(messages.publishLoud, { publish: intl.formatMessage(messages.publish) }) : intl.formatMessage(messages.publish); } return (
- + - +
- +
- - + +
- - - - + + + +
-
+
-
+
+
+
+ Messaging box +
+

User list

+
    +
  • + someone is logged in, click on me +
  • +
  • + wulfila is here, click on me +
  • +
  • + chuck norris is here, click on me +
  • +
+
+
); diff --git a/app/javascript/styles/bliss/messaging.scss b/app/javascript/styles/bliss/messaging.scss new file mode 100644 index 000000000..739c489b0 --- /dev/null +++ b/app/javascript/styles/bliss/messaging.scss @@ -0,0 +1,8 @@ +.messaging-box { + border: solid 1px white; + padding: 1em; + position: fixed; + bottom: 0; + right: 1em; + background: grey; +}