diff --git a/src/syng_im/components/chat/plain_message_input.cljs b/src/syng_im/components/chat/plain_message_input.cljs index f90fa057cc..ad02302aa4 100644 --- a/src/syng_im/components/chat/plain_message_input.cljs +++ b/src/syng_im/components/chat/plain_message_input.cljs @@ -27,7 +27,8 @@ [view st/input-container [suggestions-view] [view st/input-view - [icon :list st/list-icon] + [touchable-highlight {:on-press #(dispatch [:switch-command-suggestions])} + [view nil [icon :list st/list-icon]]] [text-input {:style st/message-input :autoFocus (pos? (count @staged-commands-atom)) :onChangeText set-input-message diff --git a/src/syng_im/handlers.cljs b/src/syng_im/handlers.cljs index 9d6a299f56..11bc7012b8 100644 --- a/src/syng_im/handlers.cljs +++ b/src/syng_im/handlers.cljs @@ -29,7 +29,8 @@ get-command-handler load-commands apply-staged-commands - check-suggestion]] + check-suggestion + switch-command-suggestions]] [syng-im.handlers.sign-up :as sign-up-service] [syng-im.models.chats :refer [chat-exists? create-chat @@ -487,6 +488,10 @@ (register-handler :set-chat-input-text ((enrich update-command) update-text)) +(register-handler :switch-command-suggestions + (fn [db [_]] + (switch-command-suggestions db))) + (register-handler :set-chat-command (fn [db [_ command-key]] ;; todo what is going on there?! diff --git a/src/syng_im/handlers/suggestions.cljs b/src/syng_im/handlers/suggestions.cljs index 8ce337b436..046589e8bb 100644 --- a/src/syng_im/handlers/suggestions.cljs +++ b/src/syng_im/handlers/suggestions.cljs @@ -1,7 +1,9 @@ (ns syng-im.handlers.suggestions (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] [syng-im.db :as db] - [syng-im.models.chat :refer [current-chat-id]] + [syng-im.models.chat :refer [current-chat-id + set-chat-input-text + get-chat-input-text]] [syng-im.models.commands :refer [commands suggestions get-commands @@ -62,3 +64,7 @@ [suggestion] (filter #(= suggestion-text' (:text %)) (get-commands db))] suggestion))) + +(defn switch-command-suggestions [db] + (let [text (get-chat-input-text db)] + (set-chat-input-text db (if (suggestion? text) nil "!")))) diff --git a/src/syng_im/models/chat.cljs b/src/syng_im/models/chat.cljs index 920442174b..763be721db 100644 --- a/src/syng_im/models/chat.cljs +++ b/src/syng_im/models/chat.cljs @@ -43,6 +43,9 @@ (defn set-chat-input-text [db text] (assoc-in db (db/chat-input-text-path (current-chat-id db)) text)) +(defn get-chat-input-text [db] + (get-in db (db/chat-input-text-path (current-chat-id db)))) + (comment (swap! re-frame.db/app-db (fn [db]