]> cat aescling's git repositories - mastodon.git/commitdiff
Refactor selectComposeSuggestion so that different paths can be updated
authorThibaut Girka <thib@sitedethib.com>
Thu, 11 Apr 2019 15:07:06 +0000 (17:07 +0200)
committerThibG <thib@sitedethib.com>
Fri, 26 Apr 2019 20:38:03 +0000 (22:38 +0200)
app/javascript/flavours/glitch/actions/compose.js
app/javascript/flavours/glitch/features/compose/containers/compose_form_container.js
app/javascript/flavours/glitch/reducers/compose.js

index ef2500629f7c5ec02004c23400713e0dac07973e..f117ce771d454e85a19092b67a115406ea837300 100644 (file)
@@ -407,7 +407,7 @@ export function readyComposeSuggestionsAccounts(token, accounts) {
   };
 };
 
-export function selectComposeSuggestion(position, token, suggestion) {
+export function selectComposeSuggestion(position, token, suggestion, path) {
   return (dispatch, getState) => {
     let completion;
     if (typeof suggestion === 'object' && suggestion.id) {
@@ -424,6 +424,7 @@ export function selectComposeSuggestion(position, token, suggestion) {
       position,
       token,
       completion,
+      path,
     });
   };
 };
index 5458e0919ee076e391df7f2421fba1da1ee36077..780a10f81009bb0fb92c0f7ad9969efd3b6d804f 100644 (file)
@@ -91,7 +91,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
   },
 
   onSuggestionSelected(position, token, suggestion) {
-    dispatch(selectComposeSuggestion(position, token, suggestion));
+    dispatch(selectComposeSuggestion(position, token, suggestion, ['text']));
   },
 
   onChangeSpoilerText(text) {
index a79b0dd244010ba4f2f80ab25aa63e6eada9a305..b1dba0a181818751b40c61347f1c4c618a52d1d2 100644 (file)
@@ -41,7 +41,7 @@ import {
 import { TIMELINE_DELETE } from 'flavours/glitch/actions/timelines';
 import { STORE_HYDRATE } from 'flavours/glitch/actions/store';
 import { REDRAFT } from 'flavours/glitch/actions/statuses';
-import { Map as ImmutableMap, List as ImmutableList, OrderedSet as ImmutableOrderedSet, fromJS } from 'immutable';
+import { Map as ImmutableMap, List as ImmutableList, OrderedSet as ImmutableOrderedSet, fromJS, is } from 'immutable';
 import uuid from 'flavours/glitch/util/uuid';
 import { privacyPreference } from 'flavours/glitch/util/privacy_preference';
 import { me } from 'flavours/glitch/util/initial_state';
@@ -214,12 +214,14 @@ function removeMedia(state, mediaId) {
   });
 };
 
-const insertSuggestion = (state, position, token, completion) => {
+const insertSuggestion = (state, position, token, completion, path) => {
   return state.withMutations(map => {
-    map.update('text', oldText => `${oldText.slice(0, position)}${completion}${completion[0] === ':' ? '\u200B' : ' '}${oldText.slice(position + token.length)}`);
+    map.updateIn(path, oldText => `${oldText.slice(0, position)}${completion}${completion[0] === ':' ? '\u200B' : ' '}${oldText.slice(position + token.length)}`);
     map.set('suggestion_token', null);
-    map.update('suggestions', ImmutableList(), list => list.clear());
-    map.set('focusDate', new Date());
+    map.set('suggestions', ImmutableList());
+    if (is(path, ImmutableList(['text']))) {
+      map.set('focusDate', new Date());
+    }
     map.set('caretPosition', position + completion.length + 1);
     map.set('idempotencyKey', uuid());
   });
@@ -397,7 +399,7 @@ export default function compose(state = initialState, action) {
   case COMPOSE_SUGGESTIONS_READY:
     return state.set('suggestions', ImmutableList(action.accounts ? action.accounts.map(item => item.id) : action.emojis)).set('suggestion_token', action.token);
   case COMPOSE_SUGGESTION_SELECT:
-    return insertSuggestion(state, action.position, action.token, action.completion);
+    return insertSuggestion(state, action.position, action.token, action.completion, action.path);
   case COMPOSE_SUGGESTION_TAGS_UPDATE:
     return updateSuggestionTags(state, action.token);
   case COMPOSE_TAG_HISTORY_UPDATE: