about summary refs log tree commit diff
path: root/app/javascript
diff options
context:
space:
mode:
authorDavid Yip <yipdw@member.fsf.org>2018-03-20 10:48:33 -0500
committerGitHub <noreply@github.com>2018-03-20 10:48:33 -0500
commit2649cce3a065f3825d63b7f7be341787aa1d2f9a (patch)
treef99e6e29acf6a095faee9b440b5adf31b9b5cb6f /app/javascript
parent0fa0836e63674104cea5095c5336bab8587d8634 (diff)
parent12b0ea06670c8f94a7d8f7534708b2bc3afb99b1 (diff)
Merge pull request #396 from ThibG/glitch-soc/fixes/compose-suggestions
[Glitch] Cancel outdated pending compose suggestions
Diffstat (limited to 'app/javascript')
-rw-r--r--app/javascript/flavours/glitch/actions/compose.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/actions/compose.js b/app/javascript/flavours/glitch/actions/compose.js
index 1e9386859..8a6ca3699 100644
--- a/app/javascript/flavours/glitch/actions/compose.js
+++ b/app/javascript/flavours/glitch/actions/compose.js
@@ -1,4 +1,5 @@
 import api from 'flavours/glitch/util/api';
+import { CancelToken } from 'axios';
 import { throttle } from 'lodash';
 import { search as emojiSearch } from 'flavours/glitch/util/emoji/emoji_mart_search_light';
 import { useEmoji } from './emojis';
@@ -11,6 +12,8 @@ import {
   refreshDirectTimeline,
 } from './timelines';
 
+let cancelFetchComposeSuggestionsAccounts;
+
 export const COMPOSE_CHANGE          = 'COMPOSE_CHANGE';
 export const COMPOSE_CYCLE_ELEFRIEND = 'COMPOSE_CYCLE_ELEFRIEND';
 export const COMPOSE_SUBMIT_REQUEST  = 'COMPOSE_SUBMIT_REQUEST';
@@ -278,13 +281,22 @@ export function undoUploadCompose(media_id) {
 };
 
 export function clearComposeSuggestions() {
+  if (cancelFetchComposeSuggestionsAccounts) {
+    cancelFetchComposeSuggestionsAccounts();
+  }
   return {
     type: COMPOSE_SUGGESTIONS_CLEAR,
   };
 };
 
 const fetchComposeSuggestionsAccounts = throttle((dispatch, getState, token) => {
+  if (cancelFetchComposeSuggestionsAccounts) {
+    cancelFetchComposeSuggestionsAccounts();
+  }
   api(getState).get('/api/v1/accounts/search', {
+    cancelToken: new CancelToken(cancel => {
+      cancelFetchComposeSuggestionsAccounts = cancel;
+    }),
     params: {
       q: token.slice(1),
       resolve: false,