autoselect command
This commit is contained in:
parent
28a0d10367
commit
7f156a69cf
|
@ -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
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
(register-handler name [(path :animations) middleware] handler)))
|
(register-handler name [(path :animations) middleware] handler)))
|
||||||
|
|
||||||
(animation-handler :animate-cancel-command
|
(animation-handler :animate-cancel-command
|
||||||
(after #(dispatch [:text-edit-mode]))
|
(after #(dispatch [:text-edit-mode]))
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(assoc db
|
(assoc db
|
||||||
:to-response-height input-height
|
:to-response-height input-height
|
||||||
:messages-offset? false)))
|
:messages-offset? false)))
|
||||||
|
|
||||||
(def response-height (+ input-height response-height-normal))
|
(def response-height (+ input-height response-height-normal))
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@
|
||||||
(register-handler :animate-command-suggestions
|
(register-handler :animate-command-suggestions
|
||||||
(fn [{:keys [current-chat-id] :as db} _]
|
(fn [{:keys [current-chat-id] :as db} _]
|
||||||
(let [suggestions? (seq (get-in db [:command-suggestions current-chat-id]))
|
(let [suggestions? (seq (get-in db [:command-suggestions current-chat-id]))
|
||||||
current (get-in db [:animations :command-suggestions-height])
|
current (get-in db [:animations :command-suggestions-height])
|
||||||
height (if suggestions? middle-height 0.1)]
|
height (if suggestions? middle-height 0.1)]
|
||||||
(-> db
|
(-> db
|
||||||
(update :animations assoc
|
(update :animations assoc
|
||||||
:messages-offset? suggestions?
|
:messages-offset? suggestions?
|
||||||
|
@ -53,27 +53,26 @@
|
||||||
(defn fix-height
|
(defn fix-height
|
||||||
[height-key height-signal-key suggestions-key minimum]
|
[height-key height-signal-key suggestions-key minimum]
|
||||||
(fn [{:keys [current-chat-id] :as db} [_ vy current]]
|
(fn [{:keys [current-chat-id] :as db} [_ vy current]]
|
||||||
(let [max-height (get-in db [:layout-height])
|
(let [max-height (get-in db [:layout-height])
|
||||||
moving-down? (pos? vy)
|
moving-down? (pos? vy)
|
||||||
moving-up? (not moving-down?)
|
moving-up? (not moving-down?)
|
||||||
under-middle-position? (<= current middle-height)
|
under-middle-position? (<= current middle-height)
|
||||||
over-middle-position? (not under-middle-position?)
|
over-middle-position? (not under-middle-position?)
|
||||||
suggestions (get-in db [suggestions-key current-chat-id])
|
suggestions (get-in db [suggestions-key current-chat-id])
|
||||||
new-fixed (cond (not suggestions)
|
new-fixed (cond (not suggestions)
|
||||||
minimum
|
minimum
|
||||||
|
|
||||||
(and under-middle-position? moving-up?)
|
(and under-middle-position? moving-up?)
|
||||||
middle-height
|
middle-height
|
||||||
|
|
||||||
(and over-middle-position? moving-down?)
|
(and over-middle-position? moving-down?)
|
||||||
middle-height
|
middle-height
|
||||||
|
|
||||||
(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)
|
||||||
(update-in [:animations height-signal-key] inc)))))
|
(update-in [:animations height-signal-key] inc)))))
|
||||||
|
|
|
@ -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)]))))
|
||||||
|
|
Loading…
Reference in New Issue