autoselect command

Former-commit-id: 7f156a69cf
This commit is contained in:
Roman Volosovskyi 2016-06-26 12:11:23 +03:00
parent e4309050b3
commit 2493000dfb
3 changed files with 33 additions and 35 deletions

View File

@ -134,12 +134,18 @@
(defn check-suggestions
[{:keys [current-chat-id] :as db} [_ text]]
(assoc-in db
[:command-suggestions current-chat-id]
(suggestions/get-suggestions db text)))
(let [suggestions (suggestions/get-suggestions db text)]
(assoc-in db [:command-suggestions current-chat-id] suggestions)))
(defn select-suggestion!
[{:keys [current-chat-id] :as db} [_ text]]
(let [suggestions (get-in db [:command-suggestions current-chat-id])]
(when (= 1 (count suggestions))
(dispatch [:set-chat-command (ffirst suggestions)]))))
(register-handler :set-chat-input-text
[(enrich update-command)
(after select-suggestion!)
(enrich check-suggestions)
(after #(dispatch [:animate-command-suggestions]))]
update-text)
@ -497,6 +503,7 @@
(assoc-in db [:edit-mode current-chat-id] mode)))
(register-handler :command-edit-mode
[(after #(dispatch [:set-chat-input-text ""]))]
(edit-mode-handler :command))
(register-handler :text-edit-mode

View File

@ -71,8 +71,7 @@
(and over-middle-position? moving-up?)
max-height
(and under-middle-position?
moving-down?)
(and under-middle-position? moving-down?)
minimum)]
(-> db
(assoc-in [:animations height-key] new-fixed)

View File

@ -1,15 +1,11 @@
(ns status-im.chat.subs
(:require-macros [reagent.ratom :refer [reaction]])
(:require [re-frame.core :refer [register-sub dispatch subscribe path]]
[status-im.db :as db]
[status-im.chat.suggestions :refer
[get-suggestions typing-command?]]
[status-im.models.commands :as commands]
[status-im.constants :refer [response-suggesstion-resize-duration]]
[status-im.handlers.content-suggestions :refer [get-content-suggestions]]
[status-im.chat.views.plain-message :as plain-message]
[status-im.chat.views.command :as command]
[status-im.chat.constants :as c]))
[status-im.chat.views.command :as command]))
(register-sub :chat-properties
(fn [db [_ properties]]
@ -111,10 +107,6 @@
(fn [db [_ chat-id]]
(reaction (get-in @db [:chats chat-id]))))
(register-sub :typing-command?
(fn [db _]
(reaction (typing-command? @db))))
(register-sub :get-content-suggestions
(fn [db _]
(reaction (get-in @db [:suggestions (:current-chat-id @db)]))))