about summary refs log tree commit diff
path: root/app/assets/javascripts/components/actions
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-11-12 14:33:21 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-11-12 14:36:10 +0100
commit09218d4c0152013750dd1c127d3c8267dc45f880 (patch)
tree7cd9975b84a28de92403c80f483d08e471b10155 /app/assets/javascripts/components/actions
parentcd765f26a9610e160ffd347637fca40d7b80164e (diff)
Use full-text search for autosuggestions
Diffstat (limited to 'app/assets/javascripts/components/actions')
-rw-r--r--app/assets/javascripts/components/actions/compose.jsx30
1 files changed, 23 insertions, 7 deletions
diff --git a/app/assets/javascripts/components/actions/compose.jsx b/app/assets/javascripts/components/actions/compose.jsx
index d343867dd..c9be895f1 100644
--- a/app/assets/javascripts/components/actions/compose.jsx
+++ b/app/assets/javascripts/components/actions/compose.jsx
@@ -17,6 +17,7 @@ export const COMPOSE_UPLOAD_UNDO     = 'COMPOSE_UPLOAD_UNDO';
 
 export const COMPOSE_SUGGESTIONS_CLEAR = 'COMPOSE_SUGGESTIONS_CLEAR';
 export const COMPOSE_SUGGESTIONS_READY = 'COMPOSE_SUGGESTIONS_READY';
+export const COMPOSE_SUGGESTION_SELECT = 'COMPOSE_SUGGESTION_SELECT';
 
 export function changeCompose(text) {
   return {
@@ -144,18 +145,33 @@ export function clearComposeSuggestions() {
 
 export function fetchComposeSuggestions(token) {
   return (dispatch, getState) => {
-    const loadedCandidates = getState().get('accounts').filter(item => item.get('acct').toLowerCase().slice(0, token.length) === token).map(item => ({
-      label: item.get('acct'),
-      completion: item.get('acct').slice(token.length)
-    })).toList().toJS();
-
-    dispatch(readyComposeSuggestions(loadedCandidates));
+    api(getState).get('/api/v1/accounts/search', {
+      params: {
+        q: token,
+        resolve: false
+      }
+    }).then(response => {
+      dispatch(readyComposeSuggestions(token, response.data));
+    });
   };
 };
 
-export function readyComposeSuggestions(accounts) {
+export function readyComposeSuggestions(token, accounts) {
   return {
     type: COMPOSE_SUGGESTIONS_READY,
+    token,
     accounts
   };
 };
+
+export function selectComposeSuggestion(position, accountId) {
+  return (dispatch, getState) => {
+    const completion = getState().getIn(['accounts', accountId, 'acct']);
+
+    dispatch({
+      type: COMPOSE_SUGGESTION_SELECT,
+      position,
+      completion
+    });
+  };
+};