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