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 (defn check-suggestions
[{:keys [current-chat-id] :as db} [_ text]] [{:keys [current-chat-id] :as db} [_ text]]
(assoc-in db (let [suggestions (suggestions/get-suggestions db text)]
[:command-suggestions current-chat-id] (assoc-in db [:command-suggestions current-chat-id] suggestions)))
(suggestions/get-suggestions db text)))
(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 (register-handler :set-chat-input-text
[(enrich update-command) [(enrich update-command)
(after select-suggestion!)
(enrich check-suggestions) (enrich check-suggestions)
(after #(dispatch [:animate-command-suggestions]))] (after #(dispatch [:animate-command-suggestions]))]
update-text) update-text)
@ -497,6 +503,7 @@
(assoc-in db [:edit-mode current-chat-id] mode))) (assoc-in db [:edit-mode current-chat-id] mode)))
(register-handler :command-edit-mode (register-handler :command-edit-mode
[(after #(dispatch [:set-chat-input-text ""]))]
(edit-mode-handler :command)) (edit-mode-handler :command))
(register-handler :text-edit-mode (register-handler :text-edit-mode

View File

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

View File

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