From 4ed06ff622ffaecdb33f5e2ec4d9a8f3a04fc950 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Sat, 25 Jun 2016 18:44:37 +0300 Subject: [PATCH 01/27] first attempt Former-commit-id: 6cd5e29c8aba3f47e612b1b1127bf5b826bb7dbf --- src/status_im/chat/constants.cljs | 1 + src/status_im/chat/handlers.cljs | 26 +++-- src/status_im/chat/handlers/animation.cljs | 74 ++++++++------ src/status_im/chat/screen.cljs | 36 ++++--- src/status_im/chat/styles/suggestions.cljs | 34 +++--- src/status_im/chat/subs.cljs | 7 +- src/status_im/chat/views/new_message.cljs | 6 +- src/status_im/chat/views/plain_message.cljs | 2 +- src/status_im/chat/views/suggestions.cljs | 108 +++++++++++++++++--- src/status_im/db.cljs | 1 - 10 files changed, 201 insertions(+), 94 deletions(-) diff --git a/src/status_im/chat/constants.cljs b/src/status_im/chat/constants.cljs index e9d95a4ed9..f37aff957e 100644 --- a/src/status_im/chat/constants.cljs +++ b/src/status_im/chat/constants.cljs @@ -4,3 +4,4 @@ (def request-info-height 61) (def response-height-normal 211) (def minimum-suggestion-height (+ input-height request-info-height)) +(def minimum-command-suggestions-height (+ input-height 22)) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index c1627a957e..3d1d213cab 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -19,6 +19,7 @@ [status-im.utils.phone-number :refer [format-phone-number]] [status-im.utils.datetime :as time] [status-im.components.jail :as j] + [status-im.utils.types :refer [json->clj]] [status-im.commands.utils :refer [generate-hiccup]])) (register-handler :set-show-actions @@ -93,7 +94,7 @@ (register-handler :stage-command (after invoke-command-preview!) (fn [{:keys [current-chat-id] :as db} _] - (let [db (update-input-text db nil) + (let [db (update-input-text db nil) {:keys [command content]} (get-in db [:chats current-chat-id :command-input]) command-info {:command command @@ -115,9 +116,7 @@ (register-handler :set-response-chat-command [(after invoke-suggestions-handler!) - (after #(dispatch [:command-edit-mode])) - ;(after #(dispatch [:animate-show-response])) - ] + (after #(dispatch [:command-edit-mode]))] (fn [db [_ to-msg-id command-key]] (commands/set-response-chat-command db to-msg-id command-key))) @@ -133,8 +132,17 @@ db)) db)) +(defn check-suggestions + [{:keys [current-chat-id] :as db} [_ text]] + (assoc-in db + [:command-suggestions current-chat-id] + (suggestions/get-suggestions db text))) + (register-handler :set-chat-input-text - ((enrich update-command) update-text)) + [(enrich update-command) + (enrich check-suggestions) + (after #(dispatch [:animate-command-suggestions]))] + update-text) (defn console? [s] (= "console" s)) @@ -437,9 +445,11 @@ ((after save-chat!)) ((after open-chat!)))) -(register-handler :switch-command-suggestions - (fn [db [_]] - (suggestions/switch-command-suggestions db))) +(register-handler :switch-command-suggestions! + (u/side-effect! + (fn [db] + (let [text (if (suggestions/typing-command? db) "" "!")] + (dispatch [:set-chat-input-text text]))))) (defn remove-chat [{:keys [current-chat-id] :as db} _] diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index a1ea5c98a5..80ca0ac379 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -3,6 +3,7 @@ [re-frame.middleware :refer [path]] [status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.chat.constants :refer [input-height request-info-height + minimum-command-suggestions-height response-height-normal minimum-suggestion-height]] [status-im.constants :refer [response-input-hiding-duration]])) @@ -19,45 +20,45 @@ (fn [db _] (assoc db :to-response-height input-height - :messages-offset 0))) + :messages-offset? false))) -(defn get-response-height - [{:keys [current-chat-id] :as db}] - (let [suggestions (get-in db [:suggestions current-chat-id]) - suggestions-height (if suggestions middle-height 0)] - (+ input-height - (min response-height-normal (+ suggestions-height request-info-height))))) +(def response-height (+ input-height response-height-normal)) (defn update-response-height [db] - (assoc-in db [:animations :to-response-height] (get-response-height db))) + (assoc-in db [:animations :to-response-height] response-height)) -(register-handler :animate-show-response +(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)] + (-> db + (update :animations assoc + :messages-offset? suggestions? + :messages-offset-max 22 + :command-suggestions-height height) + (update-in [:animations :commands-height-changed] + (if (and suggestions? (not= 0.1 current)) + identity inc)))))) + +(animation-handler :animate-show-response [(after #(dispatch [:command-edit-mode]))] - (fn [db _] - (-> db - (assoc-in [:animations :messages-offset] request-info-height) - (update-response-height)))) + (fn [db] + (assoc db :messages-offset? true + :messages-offset-max request-info-height + :to-response-height response-height))) -(animation-handler :set-response-max-height - (fn [db [_ height]] - (let [prev-height (:response-height-max db)] - (if (not= height prev-height) - (let [db (assoc db :response-height-max height)] - (if (= prev-height (:to-response-height db)) - (assoc db :to-response-height height) - db)) - db)))) - -(register-handler :fix-response-height +(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 [:animations :response-height-max]) + (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 current-chat-id]) + suggestions (get-in db [suggestions-key current-chat-id]) new-fixed (cond (not suggestions) - minimum-suggestion-height + minimum (and under-middle-position? moving-up?) middle-height @@ -70,7 +71,20 @@ (and under-middle-position? moving-down?) - minimum-suggestion-height)] + minimum)] + (println height-key new-fixed) (-> db - (assoc-in [:animations :to-response-height] new-fixed) - (update-in [:animations :response-height-changed] inc))))) + (assoc-in [:animations height-key] new-fixed) + (update-in [:animations height-signal-key] inc))))) + +(register-handler :fix-commands-suggestions-height + (fix-height :command-suggestions-height + :commands-height-changed + :command-suggestions + minimum-command-suggestions-height)) + +(register-handler :fix-response-height + (fix-height :to-response-height + :response-height-changed + :suggestions + minimum-suggestion-height)) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index f9394aeb5a..71718746cf 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -18,7 +18,7 @@ [status-im.components.invertible-scroll-view :refer [invertible-scroll-view]] [status-im.components.toolbar :refer [toolbar]] [status-im.chat.views.message :refer [chat-message]] - [status-im.chat.views.suggestions :refer [suggestions-view]] + [status-im.chat.views.suggestions :refer [suggestion-container]] [status-im.chat.views.response :refer [response-view]] [status-im.chat.views.new-message :refer [chat-message-new]] [status-im.i18n :refer [label label-pluralize]] @@ -228,20 +228,19 @@ :keyboardShouldPersistTaps true :dataSource (to-datasource-inverted messages)}])) -(defn messages-container-animation-logic [{:keys [to-value val]}] +(defn messages-container-animation-logic + [{:keys [offset? val max]}] (fn [_] - (let [to-value @to-value] - (anim/start (anim/spring val {:toValue to-value}) - (fn [arg] - (when (.-finished arg) - (dispatch [:set-animation ::messages-offset-current to-value]))))))) + (let [to-value (if @offset? @max 0)] + (anim/start (anim/spring val {:toValue to-value}))))) (defn messages-container [messages] - (let [to-messages-offset (subscribe [:animations :messages-offset]) - cur-messages-offset (subscribe [:animations ::messages-offset-current]) - messages-offset (anim/create-value (or @cur-messages-offset 0)) - context {:to-value to-messages-offset - :val messages-offset} + (let [messages-offset? (subscribe [:animations :messages-offset?]) + maximum-offset (subscribe [:animations :messages-offset-max]) + messages-offset (anim/create-value 0) + context {:offset? messages-offset? + :val messages-offset + :max maximum-offset} on-update (messages-container-animation-logic context)] (r/create-class {:component-did-mount @@ -250,7 +249,7 @@ on-update :reagent-render (fn [messages] - @to-messages-offset + @messages-offset? [animated-view {:style (st/messages-container messages-offset)} messages])}))) @@ -259,16 +258,19 @@ show-actions-atom [:show-actions] command [:get-chat-command] command? [:command?] - to-msg-id [:get-chat-command-to-msg-id]] - [view {:style st/chat-view + suggestions [:get-suggestions] + to-msg-id [:get-chat-command-to-msg-id] + layout-height [:get :layout-height]] + [view {:style st/chat-view :onLayout (fn [event] (let [height (.. event -nativeEvent -layout -height)] - (dispatch [:set-response-max-height height])))} + (when (not= height layout-height) + (dispatch [:set :layout-height height]))))} [chat-toolbar] [messages-container [messages-view group-chat]] (when group-chat [typing-all]) [response-view] - (when-not command? [suggestions-view]) + (when-not command? [suggestion-container]) [chat-message-new] (when show-actions-atom [actions-view])]) diff --git a/src/status_im/chat/styles/suggestions.cljs b/src/status_im/chat/styles/suggestions.cljs index 0c35347f79..2d1d89525f 100644 --- a/src/status_im/chat/styles/suggestions.cljs +++ b/src/status_im/chat/styles/suggestions.cljs @@ -1,16 +1,16 @@ (ns status-im.chat.styles.suggestions (:require [status-im.components.styles :refer [font - color-light-blue-transparent - color-white - color-black - color-blue - color-blue-transparent - selected-message-color - online-color - separator-color - text1-color - text2-color - text3-color]])) + color-light-blue-transparent + color-white + color-black + color-blue + color-blue-transparent + selected-message-color + online-color + separator-color + text1-color + text2-color + text3-color]])) (def suggestion-height 88) @@ -59,11 +59,19 @@ :backgroundColor color-white :borderRadius 5}) -(def container - {:backgroundColor color-white}) +(defn container [height] + {:flexDirection :column + :position :absolute + :left 0 + :right 0 + :bottom 0 + :height height + :backgroundColor color-white + :elevation 2}) (def drag-down-touchable {:height 22 + :background-color color-white :alignItems :center :justifyContent :center}) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 20bcf239ce..4d197b1aad 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -43,11 +43,8 @@ (register-sub :get-suggestions (fn [db _] - (let [input-text (->> (:current-chat-id @db) - db/chat-input-text-path - (get-in @db) - (reaction))] - (reaction (get-suggestions @db @input-text))))) + (let [chat-id (subscribe [:get-current-chat-id])] + (reaction (get-in @db [:command-suggestions @chat-id]))))) (register-sub :get-commands (fn [db _] diff --git a/src/status_im/chat/views/new_message.cljs b/src/status_im/chat/views/new_message.cljs index 67280885c4..1434651b1f 100644 --- a/src/status_im/chat/views/new_message.cljs +++ b/src/status_im/chat/views/new_message.cljs @@ -21,19 +21,19 @@ command? [:command?]] [plain-message-input-view (when command? - (case (:command command) + (case (keyword (:name command)) :phone {:input-options {:keyboardType :phone-pad} :validator valid-mobile-number?} :keypair {:input-options {:secureTextEntry true}} :confirmation-code {:input-options {:keyboardType :numeric}} :money {:input-options {:keyboardType :numeric}} :request {:input-options {:keyboardType :numeric}} - ;; todo maybe nil is finr for now :) + ;; todo maybe nil is fine for now :) nil #_(throw (js/Error. "Uknown command type"))))]) (defview chat-message-new [] [staged-commands [:get-chat-staged-commands]] [view st/new-message-container - (when (and staged-commands (pos? (count staged-commands))) + (when (seq staged-commands) [staged-commands-view staged-commands]) [show-input]]) diff --git a/src/status_im/chat/views/plain_message.cljs b/src/status_im/chat/views/plain_message.cljs index f9abe83f25..12ccadd664 100644 --- a/src/status_im/chat/views/plain_message.cljs +++ b/src/status_im/chat/views/plain_message.cljs @@ -52,7 +52,7 @@ on-update :reagent-render (fn [] - [touchable-highlight {:on-press #(dispatch [:switch-command-suggestions]) + [touchable-highlight {:on-press #(dispatch [:switch-command-suggestions!]) :disabled @command?} [animated-view {:style (st/message-input-button-touchable container-width)} diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 202150423f..3eba75a4ea 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -6,9 +6,14 @@ icon touchable-highlight list-view - list-item]] + list-item + animated-view]] [status-im.utils.listview :refer [to-datasource]] - [status-im.chat.styles.suggestions :as st])) + [status-im.chat.styles.suggestions :as st] + [reagent.core :as r] + [status-im.components.animation :as anim] + [status-im.components.drag-drop :as drag] + [status-im.components.react :as react])) (defn set-command-input [command] (dispatch [:set-chat-command command])) @@ -31,18 +36,89 @@ (list-item [suggestion-list-item row])) -(defview suggestions-view [] - [suggestions [:get-suggestions]] - (when (seq suggestions) - [view st/container - [touchable-highlight {:style st/drag-down-touchable - :onPress (fn [] - ;; TODO hide suggestions? - )} +(defn suggestions-view [] + (let + [suggestions (subscribe [:get-suggestions])] + (r/create-class + {:reagent-render + (fn [] + [view (st/suggestions-container (count @suggestions)) + [list-view {:dataSource (to-datasource @suggestions) + :enableEmptySections true + :keyboardShouldPersistTaps true + :renderRow render-row}]])}))) + +;; todo bad name. Ideas? +(defn enough-dy [gesture] + (> (Math/abs (.-dy gesture)) 10)) + +(defn on-move [response-height kb-height orientation] + (fn [_ gesture] + (when (enough-dy gesture) + (let [w (react/get-dimensions "window") + ;; depending on orientation use height or width of screen + prop (if (= :portrait @orientation) + :height + :width) + ;; subtract keyboard height to get "real height" of screen + ;; then subtract gesture position to get suggestions height + ;; todo maybe it is better to use margin-top instead height + ;; it is not obvious + to-value (- (prop w) @kb-height (.-moveY gesture))] + (anim/start + (anim/spring response-height {:toValue to-value})))))) + +(defn on-release [response-height] + (fn [_ gesture] + (when (enough-dy gesture) + (dispatch [:fix-commands-suggestions-height + (.-vy gesture) + ;; todo access to "private" property + ;; better to find another way... + (.-_value response-height)])))) + +(defn pan-responder [response-height kb-height orientation] + (drag/create-pan-responder + {:on-move (on-move response-height kb-height orientation) + :on-release (on-release response-height)})) + +(defn header [h] + (let [orientation (subscribe [:get :orientation]) + kb-height (subscribe [:get :keyboard-height]) + pan-responder (pan-responder h kb-height orientation)] + (fn [_] [view - [icon :drag_down st/drag-down-icon]]] - [view (st/suggestions-container (count suggestions)) - [list-view {:dataSource (to-datasource suggestions) - :enableEmptySections true - :keyboardShouldPersistTaps true - :renderRow render-row}]]])) + (merge (drag/pan-handlers pan-responder) + {:style st/drag-down-touchable}) + [icon :drag_down st/drag-down-icon]]))) + +(defn container-animation-logic [{:keys [to-value val]}] + (fn [_] + (let [to-value @to-value] + (anim/start (anim/spring val {:toValue to-value + :tension 50 + :friction 10}))))) + +(defn container [h & elements] + (let [;; todo to-response-height, cur-response-height must be specific + ;; for each chat + to-response-height (subscribe [:animations :command-suggestions-height]) + changed (subscribe [:animations :commands-height-changed]) + context {:to-value to-response-height + :val h} + on-update (container-animation-logic context)] + (r/create-class + {:component-did-mount + on-update + :component-did-update + on-update + :reagent-render + (fn [h & elements] + @changed + (into [animated-view {:style (st/container h)}] elements))}))) + +(defn suggestion-container [] + (let [h (anim/create-value 0)] + [container h + [header h] + [suggestions-view] ])) diff --git a/src/status_im/db.cljs b/src/status_im/db.cljs index 7c07c77636..08f3e8abf0 100644 --- a/src/status_im/db.cljs +++ b/src/status_im/db.cljs @@ -38,7 +38,6 @@ :phone-number ""} :disable-group-creation false :animations {:to-response-height 0.1 - :messages-offset 0 ;; todo clear this :tabs-bar-value (anim/create-value 0)}}) From e4309050b35c7178673728f05894e85668dd5365 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Sat, 25 Jun 2016 21:30:43 +0300 Subject: [PATCH 02/27] some improvements Former-commit-id: 28a0d10367a52b3949592af80e672e808a4bbafd --- src/status_im/chat/handlers.cljs | 5 ++--- src/status_im/chat/handlers/animation.cljs | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 3d1d213cab..b7ff184891 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -305,9 +305,8 @@ (commands/unstage-command db staged-command))) (register-handler :set-chat-command - [(after #(dispatch [:command-edit-mode])) - ;(after #(dispatch [:animate-show-response])) - ] + [(after invoke-suggestions-handler!) + (after #(dispatch [:command-edit-mode]))] (fn [db [_ command-key]] (commands/set-chat-command db command-key))) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 80ca0ac379..b3faa364c4 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -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)) @@ -41,12 +41,14 @@ (if (and suggestions? (not= 0.1 current)) identity inc)))))) -(animation-handler :animate-show-response +(register-handler :animate-show-response [(after #(dispatch [:command-edit-mode]))] - (fn [db] - (assoc db :messages-offset? true + (fn [{:keys [current-chat-id] :as db}] + (let [suggestions? (seq (get-in db [:suggestions current-chat-id])) + height (if suggestions? middle-height minimum-suggestion-height)] + (update db :animations assoc :messages-offset? true :messages-offset-max request-info-height - :to-response-height response-height))) + :to-response-height height)))) (defn fix-height [height-key height-signal-key suggestions-key minimum] @@ -72,7 +74,6 @@ (and under-middle-position? moving-down?) minimum)] - (println height-key new-fixed) (-> db (assoc-in [:animations height-key] new-fixed) (update-in [:animations height-signal-key] inc))))) From 2493000dfb8fb729928f9497125a8a5f4bbcb4f4 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Sun, 26 Jun 2016 12:11:23 +0300 Subject: [PATCH 03/27] autoselect command Former-commit-id: 7f156a69cf6b28e43bf8e5de28cc0a8f28cfce1a --- src/status_im/chat/handlers.cljs | 13 +++++-- src/status_im/chat/handlers/animation.cljs | 45 +++++++++++----------- src/status_im/chat/subs.cljs | 10 +---- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index b7ff184891..cca8759284 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -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 diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index b3faa364c4..4dd4af37dc 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -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))))) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 4d197b1aad..0c878b8057 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -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)])))) From eedd1c118622095d8137a1cc02d126224d005883 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 12:07:14 +0300 Subject: [PATCH 04/27] custom register-handler & response icon animation Former-commit-id: e7b328aa2742fa6645ff19fcaf8e93a052681026 --- src/status_im/chat/handlers.cljs | 4 +- src/status_im/chat/handlers/animation.cljs | 3 +- src/status_im/chat/styles/message.cljs | 8 +-- src/status_im/chat/views/message.cljs | 21 +------- src/status_im/chat/views/request_message.cljs | 50 +++++++------------ src/status_im/chat/views/response.cljs | 11 ++-- src/status_im/chat/views/suggestions.cljs | 11 ++-- src/status_im/commands/handlers/jail.cljs | 3 +- src/status_im/commands/utils.cljs | 5 +- src/status_im/handlers.cljs | 4 +- src/status_im/utils/handlers.cljs | 8 ++- 11 files changed, 51 insertions(+), 77 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index cca8759284..4181c2c587 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -1,5 +1,5 @@ (ns status-im.chat.handlers - (:require [re-frame.core :refer [register-handler enrich after debug dispatch]] + (:require [re-frame.core :refer [enrich after debug dispatch]] [status-im.models.commands :as commands] [clojure.string :as str] [status-im.components.styles :refer [default-chat-color]] @@ -12,7 +12,7 @@ [status-im.chat.sign-up :as sign-up-service] [status-im.models.chats :as chats] [status-im.navigation.handlers :as nav] - [status-im.utils.handlers :as u] + [status-im.utils.handlers :refer [register-handler] :as u] [status-im.persistence.realm :as r] [status-im.handlers.server :as server] [status-im.handlers.content-suggestions :refer [get-content-suggestions]] diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 4dd4af37dc..48715ee0a1 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -1,5 +1,6 @@ (ns status-im.chat.handlers.animation - (:require [re-frame.core :refer [register-handler after dispatch debug]] + (:require [re-frame.core :refer [after dispatch debug]] + [status-im.utils.handlers :refer [register-handler]] [re-frame.middleware :refer [path]] [status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.chat.constants :refer [input-height request-info-height diff --git a/src/status_im/chat/styles/message.cljs b/src/status_im/chat/styles/message.cljs index 5bb60573d4..76d4a91904 100644 --- a/src/status_im/chat/styles/message.cljs +++ b/src/status_im/chat/styles/message.cljs @@ -153,15 +153,13 @@ :backgroundColor (:color command) :transform [{:scale scale}]}) -(defn command-image-view - [command] +(def command-image-view {:position :absolute :top 0 :right 0 :width 24 :height 24 :borderRadius 50 - :backgroundColor (:color command) :alignItems :center}) (def command-request-image @@ -198,7 +196,9 @@ (def command-image {:margin-top 5 :width 12 - :height 13}) + :height 13 + :tintColor :#a9a9a9cc}) + (def command-text (merge style-message-text {:marginTop 8 diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index 656cb72631..069a18e9da 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -69,7 +69,7 @@ (str "!" (:name command))]]] ;; todo doesn't reflect design (when-let [icon (:icon command)] - [view (st/command-image-view command) + [view st/command-image-view [image {:source {:uri icon} :style st/command-image}]]) (if preview @@ -84,25 +84,6 @@ (->> (when command (name command)) (str "request-"))) -;; todo remove (merging leftover) -#_(defview message-content-command-request - [{:keys [msg-id content from incoming-group]}] - [commands [:get-responses]] - (let [{:keys [command content]} (parse-command-request commands content)] - [touchable-highlight {:onPress #(set-chat-command msg-id command) - :accessibility-label (label command)} - [view st/comand-request-view - [view st/command-request-message-view - (when incoming-group - [text {:style st/command-request-from-text} from]) - [text {:style st/style-message-text} content]] - [view (st/command-request-image-view command) - [image {:source {:uri (:icon command)} - :style st/command-request-image}]] - (when-let [request-text (:request-text command)] - [view st/command-request-text-view - [text {:style st/style-sub-text} request-text]])]])) - (defn message-view [message content] [view (st/message-view message) diff --git a/src/status_im/chat/views/request_message.cljs b/src/status_im/chat/views/request_message.cljs index 0e5117769a..77e5834327 100644 --- a/src/status_im/chat/views/request_message.cljs +++ b/src/status_im/chat/views/request_message.cljs @@ -19,49 +19,37 @@ (->> (name command) (str "request-"))) -(defn request-button-animation-logic [{:keys [to-value val loop?]}] - (fn [_] - (let [loop? @loop? - minimum 1 - maximum 1.3 - to-scale (if loop? - (or @to-value maximum) - minimum)] - (anim/start - (anim/anim-sequence - [(anim/anim-delay (if loop? request-message-icon-scale-delay 0)) - (anim/spring val {:toValue to-scale})]) - (fn [arg] - (when (.-finished arg) - (dispatch [:set-animation ::request-button-scale-current to-scale]) - (when loop? - (dispatch [:set-animation ::request-button-scale (if (= to-scale minimum) - maximum - minimum)])))))))) +(def min-scale 1) +(def max-scale 1.3) + +(defn request-button-animation-logic + [{:keys [to-value val loop?] :as context}] + (anim/start + (anim/anim-sequence + [(anim/anim-delay (if @loop? request-message-icon-scale-delay 0)) + (anim/spring val {:toValue to-value})]) + #(when @loop? + (let [new-value (if (= to-value min-scale) max-scale min-scale) + context' (assoc context :to-value new-value)] + (request-button-animation-logic context'))))) (defn request-button [msg-id command] - (let [to-scale (subscribe [:animations ::request-button-scale]) - cur-scale (subscribe [:animations ::request-button-scale-current]) - scale-anim-val (anim/create-value (or @cur-scale 1)) + (let [scale-anim-val (anim/create-value min-scale) loop? (r/atom true) - context {:to-value to-scale + context {:to-value max-scale :val scale-anim-val - :loop? loop?} - on-update (request-button-animation-logic context)] + :loop? loop?}] (r/create-class {:component-did-mount - on-update - :component-did-update - on-update + #(request-button-animation-logic context) + :component-will-unmount + #(reset! loop? false) :reagent-render (fn [msg-id command] - @to-scale [touchable-highlight {:on-press (fn [] (reset! loop? false) (set-chat-command msg-id command)) :style st/command-request-image-touchable} - ;:accessibility-label (label command) - [animated-view {:style (st/command-request-image-view command scale-anim-val)} [image {:source {:uri (:icon command)} :style st/command-request-image}]]])}))) diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index 71933d6d8d..03f5e3ce7c 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -83,11 +83,10 @@ [icon :close-white st/cancel-icon]]]]]))) (defn container-animation-logic [{:keys [to-value val]}] - (fn [_] - (let [to-value @to-value] - (anim/start (anim/spring val {:toValue to-value - :tension 50 - :friction 10}))))) + (let [to-value @to-value] + (anim/start (anim/spring val {:toValue to-value + :tension 50 + :friction 10})))) (defn container [response-height & children] (let [;; todo to-response-height, cur-response-height must be specific @@ -96,7 +95,7 @@ changed (subscribe [:animations :response-height-changed]) context {:to-value to-response-height :val response-height} - on-update (container-animation-logic context)] + on-update #(container-animation-logic context)] (r/create-class {:component-did-mount on-update diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 3eba75a4ea..26b0cc7f94 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -93,11 +93,10 @@ [icon :drag_down st/drag-down-icon]]))) (defn container-animation-logic [{:keys [to-value val]}] - (fn [_] - (let [to-value @to-value] - (anim/start (anim/spring val {:toValue to-value - :tension 50 - :friction 10}))))) + (let [to-value @to-value] + (anim/start (anim/spring val {:toValue to-value + :tension 50 + :friction 10})))) (defn container [h & elements] (let [;; todo to-response-height, cur-response-height must be specific @@ -106,7 +105,7 @@ changed (subscribe [:animations :commands-height-changed]) context {:to-value to-response-height :val h} - on-update (container-animation-logic context)] + on-update #(container-animation-logic context)] (r/create-class {:component-did-mount on-update diff --git a/src/status_im/commands/handlers/jail.cljs b/src/status_im/commands/handlers/jail.cljs index b2d1ac67af..d5852f5ee7 100644 --- a/src/status_im/commands/handlers/jail.cljs +++ b/src/status_im/commands/handlers/jail.cljs @@ -1,6 +1,5 @@ (ns status-im.commands.handlers.jail - (:require [re-frame.core :refer [register-handler after dispatch subscribe - trim-v debug]] + (:require [re-frame.core :refer [after dispatch subscribe trim-v debug]] [status-im.utils.handlers :as u] [status-im.utils.utils :refer [http-get toast]] [status-im.components.jail :as j] diff --git a/src/status_im/commands/utils.cljs b/src/status_im/commands/utils.cljs index 8ae48bf0e7..ca03a910cf 100644 --- a/src/status_im/commands/utils.cljs +++ b/src/status_im/commands/utils.cljs @@ -3,7 +3,8 @@ [clojure.walk :as w] [status-im.components.react :refer [text scroll-view view image touchable-highlight]] - [re-frame.core :refer [register-handler dispatch trim-v debug]])) + [re-frame.core :refer [register-handler dispatch trim-v debug]] + [status-im.utils.handlers :refer [register-handler]])) (defn json->clj [json] (if (= json "undefined") @@ -44,4 +45,4 @@ (defn reg-handler ([name handler] (reg-handler name nil handler)) ([name middleware handler] - (register-handler name [#_debug trim-v middleware] handler))) + (register-handler name [trim-v middleware] handler))) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index f229403e07..789d2256e0 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -1,13 +1,13 @@ (ns status-im.handlers (:require - [re-frame.core :refer [register-handler after dispatch debug]] + [re-frame.core :refer [after dispatch debug]] [schema.core :as s :include-macros true] [status-im.db :refer [app-db schema]] [status-im.persistence.simple-kv-store :as kv] [status-im.protocol.state.storage :as storage] [status-im.utils.logging :as log] [status-im.utils.crypt :refer [gen-random-bytes]] - [status-im.utils.handlers :as u] + [status-im.utils.handlers :refer [register-handler] :as u] status-im.chat.handlers status-im.chat.handlers.animation status-im.group-settings.handlers diff --git a/src/status_im/utils/handlers.cljs b/src/status_im/utils/handlers.cljs index f14ce02a79..083196375e 100644 --- a/src/status_im/utils/handlers.cljs +++ b/src/status_im/utils/handlers.cljs @@ -1,4 +1,5 @@ -(ns status-im.utils.handlers) +(ns status-im.utils.handlers + (:require [re-frame.core :refer [after dispatch debug] :as re-core])) (defn side-effect! "Middleware for handlers that will not affect db." @@ -6,3 +7,8 @@ (fn [db params] (handler db params) db)) + +(defn register-handler + ([name handler] (register-handler name nil handler)) + ([name middleware handler] + (re-core/register-handler name [#_debug middleware] handler))) From f382e543c49c98b43dc4b1ccd2009c6c5f55cee4 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 14:35:33 +0300 Subject: [PATCH 05/27] cleanup debug & simplify messages-offset Former-commit-id: de5eb9bee0ea89eca46a5b55e593c94a56b7029f --- src/status_im/chat/constants.cljs | 4 +- src/status_im/chat/handlers.cljs | 3 +- src/status_im/chat/handlers/animation.cljs | 21 +++------ src/status_im/chat/screen.cljs | 55 ++++++++++------------ src/status_im/chat/subs.cljs | 12 ++++- src/status_im/handlers.cljs | 8 +--- src/status_im/utils/handlers.cljs | 2 +- 7 files changed, 51 insertions(+), 54 deletions(-) diff --git a/src/status_im/chat/constants.cljs b/src/status_im/chat/constants.cljs index f37aff957e..d61bd707ca 100644 --- a/src/status_im/chat/constants.cljs +++ b/src/status_im/chat/constants.cljs @@ -4,4 +4,6 @@ (def request-info-height 61) (def response-height-normal 211) (def minimum-suggestion-height (+ input-height request-info-height)) -(def minimum-command-suggestions-height (+ input-height 22)) +(def suggestions-header-height 22) +(def minimum-command-suggestions-height + (+ input-height suggestions-header-height)) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 4181c2c587..70c7f50de7 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -366,8 +366,7 @@ (register-handler :init-chat (-> load-messages! ((enrich init-chat)) - ((after load-commands!)) - debug)) + ((after load-commands!)))) (defn initialize-chats [{:keys [loaded-chats] :as db} _] diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 48715ee0a1..76047831af 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -19,9 +19,7 @@ (animation-handler :animate-cancel-command (after #(dispatch [:text-edit-mode])) (fn [db _] - (assoc db - :to-response-height input-height - :messages-offset? false))) + (assoc db :to-response-height input-height))) (def response-height (+ input-height response-height-normal)) @@ -32,24 +30,19 @@ (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)] + height (if suggestions? middle-height 0.1) + changed? (if (and suggestions? (not= 0.1 current)) + identity inc)] (-> db - (update :animations assoc - :messages-offset? suggestions? - :messages-offset-max 22 - :command-suggestions-height height) - (update-in [:animations :commands-height-changed] - (if (and suggestions? (not= 0.1 current)) - identity inc)))))) + (update :animations assoc :command-suggestions-height height) + (update-in [:animations :commands-height-changed] changed?))))) (register-handler :animate-show-response [(after #(dispatch [:command-edit-mode]))] (fn [{:keys [current-chat-id] :as db}] (let [suggestions? (seq (get-in db [:suggestions current-chat-id])) height (if suggestions? middle-height minimum-suggestion-height)] - (update db :animations assoc :messages-offset? true - :messages-offset-max request-info-height - :to-response-height height)))) + (assoc-in db [:animations :to-response-height] height)))) (defn fix-height [height-key height-signal-key suggestions-key minimum] diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 71718746cf..0652d5109d 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -41,10 +41,10 @@ :background-color background-color)))) (defview chat-icon [] - [chat-id [:chat :chat-id] + [chat-id [:chat :chat-id] group-chat [:chat :group-chat] - name [:chat :name] - color [:chat :color]] + name [:chat :name] + color [:chat :color]] ;; TODO stub data ('online' property) [chat-icon-view-action chat-id group-chat name color true]) @@ -98,10 +98,10 @@ subtitle])]]]) (defview menu-item-icon-profile [] - [chat-id [:chat :chat-id] + [chat-id [:chat :chat-id] group-chat [:chat :group-chat] - name [:chat :name] - color [:chat :color]] + name [:chat :name] + color [:chat :color]] ;; TODO stub data ('online' property) [chat-icon-view-menu-item chat-id group-chat name color true]) @@ -140,12 +140,12 @@ :icon-style {:width 20 :height 13} :handler #(dispatch [:show-group-settings])}] - [{:title (label :t/profile) + [{:title (label :t/profile) :custom-icon [menu-item-icon-profile] - :icon :menu_group - :icon-style {:width 25 - :height 19} - :handler #(dispatch [:show-profile @chat-id])} + :icon :menu_group + :icon-style {:width 25 + :height 19} + :handler #(dispatch [:show-profile @chat-id])} {:title (label :t/search-chat) :subtitle (label :t/not-implemented) :icon :search_gray_copy @@ -218,29 +218,26 @@ :custom-action [toolbar-action]}]))) (defview messages-view [group-chat] - [messages [:chat :messages] - contacts [:chat :contacts]] - (let [contacts' (contacts-by-identity contacts)] - [list-view {:renderRow (message-row contacts' group-chat (count messages)) - :renderScrollComponent #(invertible-scroll-view (js->clj %)) - :onEndReached #(dispatch [:load-more-messages]) - :enableEmptySections true - :keyboardShouldPersistTaps true - :dataSource (to-datasource-inverted messages)}])) + [messages [:chat :messages] + contacts [:chat :contacts]] + (let [contacts' (contacts-by-identity contacts)] + [list-view {:renderRow (message-row contacts' group-chat (count messages)) + :renderScrollComponent #(invertible-scroll-view (js->clj %)) + :onEndReached #(dispatch [:load-more-messages]) + :enableEmptySections true + :keyboardShouldPersistTaps true + :dataSource (to-datasource-inverted messages)}])) (defn messages-container-animation-logic - [{:keys [offset? val max]}] + [{:keys [offset val]}] (fn [_] - (let [to-value (if @offset? @max 0)] - (anim/start (anim/spring val {:toValue to-value}))))) + (anim/start (anim/spring val {:toValue @offset})))) (defn messages-container [messages] - (let [messages-offset? (subscribe [:animations :messages-offset?]) - maximum-offset (subscribe [:animations :messages-offset-max]) + (let [offset (subscribe [:messages-offset]) messages-offset (anim/create-value 0) - context {:offset? messages-offset? - :val messages-offset - :max maximum-offset} + context {:offset offset + :val messages-offset} on-update (messages-container-animation-logic context)] (r/create-class {:component-did-mount @@ -249,7 +246,7 @@ on-update :reagent-render (fn [messages] - @messages-offset? + @offset [animated-view {:style (st/messages-container messages-offset)} messages])}))) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 0c878b8057..c5340917e0 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -3,6 +3,7 @@ (:require [re-frame.core :refer [register-sub dispatch subscribe path]] [status-im.models.commands :as commands] [status-im.constants :refer [response-suggesstion-resize-duration]] + [status-im.chat.constants :as c] [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])) @@ -72,7 +73,7 @@ (register-sub :valid-plain-message? (fn [_ _] - (let [input-message (subscribe [:get-chat-input-text]) + (let [input-message (subscribe [:get-chat-input-text]) staged-commands (subscribe [:get-chat-staged-commands])] (reaction (plain-message/message-valid? @staged-commands @input-message))))) @@ -116,3 +117,12 @@ (->> (get-in @db [:edit-mode (:current-chat-id @db)]) (= :command) (reaction)))) + +(register-sub :messages-offset + (fn [] + (let [command? (subscribe [:command?]) + suggestions (subscribe [:get-suggestions])] + ;; todo fix magic values + (reaction (cond @command? c/request-info-height + (seq @suggestions) c/suggestions-header-height + :else 0))))) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 789d2256e0..7829563fe5 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -40,16 +40,12 @@ (defn set-el [db [_ k v]] (assoc db k v)) -(register-handler :set - debug - set-el) +(register-handler :set set-el) (defn set-in [db [_ path v]] (assoc-in db path v)) -(register-handler :set-in - debug - set-in) +(register-handler :set-in set-in) (register-handler :set-animation (fn [db [_ k v]] diff --git a/src/status_im/utils/handlers.cljs b/src/status_im/utils/handlers.cljs index 083196375e..4d2777e335 100644 --- a/src/status_im/utils/handlers.cljs +++ b/src/status_im/utils/handlers.cljs @@ -11,4 +11,4 @@ (defn register-handler ([name handler] (register-handler name nil handler)) ([name middleware handler] - (re-core/register-handler name [#_debug middleware] handler))) + (re-core/register-handler name [debug middleware] handler))) From bebe03fca9565948ea59b34580f23b80995b5c46 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 14:58:37 +0300 Subject: [PATCH 06/27] fix duplication a bit Former-commit-id: 103b6ba0eb331c30b329be00cbd693a148132e44 --- src/status_im/chat/suggestions_responder.cljs | 39 ++++++++++++ src/status_im/chat/views/response.cljs | 59 ++++-------------- src/status_im/chat/views/suggestions.cljs | 60 +++++-------------- src/status_im/utils/handlers.cljs | 2 +- 4 files changed, 67 insertions(+), 93 deletions(-) create mode 100644 src/status_im/chat/suggestions_responder.cljs diff --git a/src/status_im/chat/suggestions_responder.cljs b/src/status_im/chat/suggestions_responder.cljs new file mode 100644 index 0000000000..eebdd45608 --- /dev/null +++ b/src/status_im/chat/suggestions_responder.cljs @@ -0,0 +1,39 @@ +(ns status-im.chat.suggestions-responder + (:require [status-im.components.drag-drop :as drag] + [status-im.components.animation :as anim] + [status-im.components.react :as react] + [re-frame.core :refer [dispatch]])) + +;; todo bad name. Ideas? +(defn enough-dy [gesture] + (> (Math/abs (.-dy gesture)) 10)) + +(defn on-move [response-height kb-height orientation] + (fn [_ gesture] + (when (enough-dy gesture) + (let [w (react/get-dimensions "window") + ;; depending on orientation use height or width of screen + prop (if (= :portrait @orientation) + :height + :width) + ;; subtract keyboard height to get "real height" of screen + ;; then subtract gesture position to get suggestions height + ;; todo maybe it is better to use margin-top instead height + ;; it is not obvious + to-value (- (prop w) @kb-height (.-moveY gesture))] + (anim/start + (anim/spring response-height {:toValue to-value})))))) + +(defn on-release [response-height handler-name] + (fn [_ gesture] + (when (enough-dy gesture) + (dispatch [handler-name + (.-vy gesture) + ;; todo access to "private" property + ;; better to find another way... + (.-_value response-height)])))) + +(defn pan-responder [response-height kb-height orientation handler-name] + (drag/create-pan-responder + {:on-move (on-move response-height kb-height orientation) + :on-release (on-release response-height handler-name)})) diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index 03f5e3ce7c..b81763c9f6 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -13,7 +13,7 @@ [status-im.components.drag-drop :as drag] [status-im.chat.styles.response :as st] [status-im.components.animation :as anim] - [status-im.components.react :as react])) + [status-im.chat.suggestions-responder :as resp])) (defn drag-icon [] [view st/drag-container @@ -32,45 +32,14 @@ ;; TODO stub data: request message info "By ???, MMM 1st at HH:mm"]]) -;; todo bad name. Ideas? -(defn enough-dy [gesture] - (> (Math/abs (.-dy gesture)) 10)) - -(defn on-move [response-height kb-height orientation] - (fn [_ gesture] - (when (enough-dy gesture) - (let [w (react/get-dimensions "window") - ;; depending on orientation use height or width of screen - prop (if (= :portrait @orientation) - :height - :width) - ;; subtract keyboard height to get "real height" of screen - ;; then subtract gesture position to get suggestions height - ;; todo maybe it is better to use margin-top instead height - ;; it is not obvious - to-value (- (prop w) @kb-height (.-moveY gesture))] - (anim/start - (anim/spring response-height {:toValue to-value})))))) - -(defn on-release [response-height] - (fn [_ gesture] - (when (enough-dy gesture) - (dispatch [:fix-response-height - (.-vy gesture) - ;; todo access to "private" property - ;; better to find another way... - (.-_value response-height)])))) - -(defn pan-responder [response-height kb-height orientation] - (drag/create-pan-responder - {:on-move (on-move response-height kb-height orientation) - :on-release (on-release response-height)})) - (defn request-info [response-height] - (let [orientation (subscribe [:get :orientation]) - kb-height (subscribe [:get :keyboard-height]) - pan-responder (pan-responder response-height kb-height orientation) - command (subscribe [:get-chat-command])] + (let [orientation (subscribe [:get :orientation]) + kb-height (subscribe [:get :keyboard-height]) + pan-responder (resp/pan-responder response-height + kb-height + orientation + :fix-response-height) + command (subscribe [:get-chat-command])] (fn [response-height] [view (merge (drag/pan-handlers pan-responder) {:style (st/request-info (:color @command))}) @@ -84,18 +53,16 @@ (defn container-animation-logic [{:keys [to-value val]}] (let [to-value @to-value] - (anim/start (anim/spring val {:toValue to-value - :tension 50 - :friction 10})))) + (anim/start (anim/spring val {:toValue to-value})))) (defn container [response-height & children] (let [;; todo to-response-height, cur-response-height must be specific ;; for each chat to-response-height (subscribe [:animations :to-response-height]) - changed (subscribe [:animations :response-height-changed]) - context {:to-value to-response-height - :val response-height} - on-update #(container-animation-logic context)] + changed (subscribe [:animations :response-height-changed]) + context {:to-value to-response-height + :val response-height} + on-update #(container-animation-logic context)] (r/create-class {:component-did-mount on-update diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 26b0cc7f94..38336670fc 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -13,7 +13,8 @@ [reagent.core :as r] [status-im.components.animation :as anim] [status-im.components.drag-drop :as drag] - [status-im.components.react :as react])) + [status-im.components.react :as react] + [status-im.chat.suggestions-responder :as resp])) (defn set-command-input [command] (dispatch [:set-chat-command command])) @@ -48,64 +49,31 @@ :keyboardShouldPersistTaps true :renderRow render-row}]])}))) -;; todo bad name. Ideas? -(defn enough-dy [gesture] - (> (Math/abs (.-dy gesture)) 10)) - -(defn on-move [response-height kb-height orientation] - (fn [_ gesture] - (when (enough-dy gesture) - (let [w (react/get-dimensions "window") - ;; depending on orientation use height or width of screen - prop (if (= :portrait @orientation) - :height - :width) - ;; subtract keyboard height to get "real height" of screen - ;; then subtract gesture position to get suggestions height - ;; todo maybe it is better to use margin-top instead height - ;; it is not obvious - to-value (- (prop w) @kb-height (.-moveY gesture))] - (anim/start - (anim/spring response-height {:toValue to-value})))))) - -(defn on-release [response-height] - (fn [_ gesture] - (when (enough-dy gesture) - (dispatch [:fix-commands-suggestions-height - (.-vy gesture) - ;; todo access to "private" property - ;; better to find another way... - (.-_value response-height)])))) - -(defn pan-responder [response-height kb-height orientation] - (drag/create-pan-responder - {:on-move (on-move response-height kb-height orientation) - :on-release (on-release response-height)})) - (defn header [h] (let [orientation (subscribe [:get :orientation]) - kb-height (subscribe [:get :keyboard-height]) - pan-responder (pan-responder h kb-height orientation)] + kb-height (subscribe [:get :keyboard-height]) + pan-responder (resp/pan-responder h + kb-height + orientation + :fix-commands-suggestions-height)] (fn [_] [view (merge (drag/pan-handlers pan-responder) - {:style st/drag-down-touchable}) + {:style st/drag-down-touchable}) [icon :drag_down st/drag-down-icon]]))) (defn container-animation-logic [{:keys [to-value val]}] (let [to-value @to-value] - (anim/start (anim/spring val {:toValue to-value - :tension 50 - :friction 10})))) + (anim/start (anim/spring val {:toValue to-value})))) (defn container [h & elements] (let [;; todo to-response-height, cur-response-height must be specific ;; for each chat to-response-height (subscribe [:animations :command-suggestions-height]) - changed (subscribe [:animations :commands-height-changed]) - context {:to-value to-response-height - :val h} - on-update #(container-animation-logic context)] + changed (subscribe [:animations :commands-height-changed]) + context {:to-value to-response-height + :val h} + on-update #(container-animation-logic context)] (r/create-class {:component-did-mount on-update @@ -120,4 +88,4 @@ (let [h (anim/create-value 0)] [container h [header h] - [suggestions-view] ])) + [suggestions-view]])) diff --git a/src/status_im/utils/handlers.cljs b/src/status_im/utils/handlers.cljs index 4d2777e335..083196375e 100644 --- a/src/status_im/utils/handlers.cljs +++ b/src/status_im/utils/handlers.cljs @@ -11,4 +11,4 @@ (defn register-handler ([name handler] (register-handler name nil handler)) ([name middleware handler] - (re-core/register-handler name [debug middleware] handler))) + (re-core/register-handler name [#_debug middleware] handler))) From a987ffee7ce1249764077df4699aa4187b374cdf Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 16:44:54 +0300 Subject: [PATCH 07/27] missed conflict Former-commit-id: 8d13f5dc3686e7b98548593ae1b0d2089bf74f8b --- src/status_im/models/messages.cljs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/status_im/models/messages.cljs b/src/status_im/models/messages.cljs index 8bf815e520..c010719ab1 100644 --- a/src/status_im/models/messages.cljs +++ b/src/status_im/models/messages.cljs @@ -47,24 +47,6 @@ #{c/content-type-command c/content-type-command-request} type)) -<<<<<<< HEAD -(defn get-messages [chat-id] - (->> (-> (r/get-by-field :msgs :chat-id chat-id) - (r/sorted :timestamp :desc) - (r/collection->map)) - (into '()) - ;; todo why reverse? - reverse - (map (fn [{:keys [content-type preview] :as message}] - (if (command-type? content-type) - (-> message - (update :content str-to-map) - (assoc :rendered-preview (when preview - (generate-hiccup - (read-string preview)))) - (dissoc :preview)) - message))))) -======= (defn get-messages ([chat-id] (get-messages chat-id 0)) ([chat-id from] @@ -78,7 +60,6 @@ (if (command-type? content-type) (update message :content str-to-map) message)))))) ->>>>>>> develop (defn update-message! [{:keys [msg-id] :as msg}] (log/debug "update-message!" msg) From 5e94fb9b7b255fd9534ad49c2d7594787f8b42b6 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 18:38:44 +0300 Subject: [PATCH 08/27] first parameter Former-commit-id: 013e4e79ae3c7336c5b6a4d502cd7aa25e1bc1c5 --- resources/commands.js | 10 +++++---- resources/status.js | 5 +++-- src/status_im/android/core.cljs | 1 - src/status_im/chat/subs.cljs | 9 ++++++++ src/status_im/chat/views/new_message.cljs | 26 +++++++++++++---------- src/status_im/models/commands.cljs | 7 +++--- 6 files changed, 37 insertions(+), 21 deletions(-) diff --git a/resources/commands.js b/resources/commands.js index 94c631b979..ee5cac345b 100644 --- a/resources/commands.js +++ b/resources/commands.js @@ -4,7 +4,8 @@ status.command({ color: "#9a5dcf" }).param({ name: "address", - type: status.types.STRING + type: status.types.TEXT, + placeholder: "Address" }); var phones = [ @@ -110,8 +111,9 @@ status.response({ color: "#5fc48d", params: [{ name: "phone", - type: status.types.PHONE_NUMBER, - suggestions: phoneSuggestions + type: status.types.PHONE, + suggestions: phoneSuggestions, + placeholder: "Phone number" }], handler: function (params) { return { @@ -127,7 +129,7 @@ status.command({ color: "#7099e6", params: [{ name: "query", - type: status.types.STRING + type: status.types.TEXT }] }); diff --git a/resources/status.js b/resources/status.js index 924decbf47..2eec9a3d44 100644 --- a/resources/status.js +++ b/resources/status.js @@ -92,8 +92,9 @@ var status = { return response.create(n, d, h); }, types: { - STRING: 'string', - PHONE_NUMBER: 'phone-number', + TEXT: 'text', + NUMBER: 'number', + PHONE: 'phone', PASSWORD: 'password' }, events: { diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index e20c9fcfc1..e69e22cc2f 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -82,7 +82,6 @@ (dispatch [:initialize-protocol]) (dispatch [:load-user-phone-number]) (dispatch [:load-contacts]) - ;; load commands from remote server (todo: uncomment) (dispatch [:init-console-chat]) (dispatch [:init-chat]) (init-back-button-handler!) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index c5340917e0..b9f08f0402 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -87,6 +87,15 @@ (fn [db _] (reaction (commands/get-chat-command @db)))) +(register-sub :get-command-parameter + (fn [db] + (let [command (subscribe [:get-chat-command]) + chat-id (subscribe [:get-current-chat-id])] + (reaction + (let [path [:chats @chat-id :command-input :parameter-idx] + n (get-in @db path)] + (when n (nth (:params @command) n))))))) + (register-sub :get-chat-command-content (fn [db _] (reaction (commands/get-chat-command-content @db)))) diff --git a/src/status_im/chat/views/new_message.cljs b/src/status_im/chat/views/new_message.cljs index 1434651b1f..2a1e2cd892 100644 --- a/src/status_im/chat/views/new_message.cljs +++ b/src/status_im/chat/views/new_message.cljs @@ -16,20 +16,24 @@ (for [command staged-commands] ^{:key command} [staged-command-view command])]) +(defn get-options [{:keys [type placeholder]}] + (let [options (case (keyword type) + :phone {:input-options {:keyboardType :phone-pad} + :validator valid-mobile-number?} + :password {:input-options {:secureTextEntry true}} + :number {:input-options {:keyboardType :numeric}} + ;; todo maybe nil is fine for now :) + nil #_(throw (js/Error. "Uknown command type")))] + (println :plc placeholder) + (if placeholder + (assoc-in options [:input-options :placeholder] placeholder) + options))) + (defview show-input [] - [command [:get-chat-command] + [parameter [:get-command-parameter] command? [:command?]] [plain-message-input-view - (when command? - (case (keyword (:name command)) - :phone {:input-options {:keyboardType :phone-pad} - :validator valid-mobile-number?} - :keypair {:input-options {:secureTextEntry true}} - :confirmation-code {:input-options {:keyboardType :numeric}} - :money {:input-options {:keyboardType :numeric}} - :request {:input-options {:keyboardType :numeric}} - ;; todo maybe nil is fine for now :) - nil #_(throw (js/Error. "Uknown command type"))))]) + (when command? (get-options parameter))]) (defview chat-message-new [] [staged-commands [:get-chat-staged-commands]] diff --git a/src/status_im/models/commands.cljs b/src/status_im/models/commands.cljs index aa426640eb..1ebb70dccb 100644 --- a/src/status_im/models/commands.cljs +++ b/src/status_im/models/commands.cljs @@ -34,9 +34,10 @@ (defn set-response-chat-command [{:keys [current-chat-id] :as db} msg-id command-key] (update-in db [:chats current-chat-id :command-input] merge - {:content nil - :command (get-command db command-key) - :to-msg-id msg-id})) + {:content nil + :command (get-command db command-key) + :parameter-idx 0 + :to-msg-id msg-id})) (defn set-chat-command [db command-key] (set-response-chat-command db nil command-key)) From 7c50d95cef097389b6644fbb642b71d853915bb7 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 09:27:21 +0300 Subject: [PATCH 09/27] commands input Former-commit-id: e6414c7101ccc6ece44a059e07e49e7d68f580c1 --- src/status_im/chat/handlers/animation.cljs | 20 ++++++++++++---- .../chat/styles/content_suggestions.cljs | 9 -------- src/status_im/chat/styles/dragdown.cljs | 12 ++++++++++ src/status_im/chat/styles/input.cljs | 4 ++-- src/status_im/chat/styles/suggestions.cljs | 10 -------- src/status_im/chat/subs.cljs | 10 +++++--- src/status_im/chat/views/command.cljs | 2 +- src/status_im/chat/views/message_input.cljs | 3 +++ src/status_im/chat/views/response.cljs | 23 +++++++++++-------- src/status_im/chat/views/suggestions.cljs | 5 ++-- 10 files changed, 57 insertions(+), 41 deletions(-) create mode 100644 src/status_im/chat/styles/dragdown.cljs diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 76047831af..837991d98b 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -37,11 +37,21 @@ (update :animations assoc :command-suggestions-height height) (update-in [:animations :commands-height-changed] changed?))))) +(defn get-minimum-height + [{:keys [current-chat-id] :as db}] + (let [path [:chats current-chat-id :command-input :command :type] + type (get-in db path)] + (if (= :response type) + minimum-suggestion-height + minimum-command-suggestions-height))) + (register-handler :animate-show-response [(after #(dispatch [:command-edit-mode]))] (fn [{:keys [current-chat-id] :as db}] (let [suggestions? (seq (get-in db [:suggestions current-chat-id])) - height (if suggestions? middle-height minimum-suggestion-height)] + height (if suggestions? + middle-height + (get-minimum-height db))] (assoc-in db [:animations :to-response-height] height)))) (defn fix-height @@ -54,7 +64,7 @@ over-middle-position? (not under-middle-position?) suggestions (get-in db [suggestions-key current-chat-id]) new-fixed (cond (not suggestions) - minimum + (minimum db) (and under-middle-position? moving-up?) middle-height @@ -66,7 +76,7 @@ max-height (and under-middle-position? moving-down?) - minimum)] + (minimum db))] (-> db (assoc-in [:animations height-key] new-fixed) (update-in [:animations height-signal-key] inc))))) @@ -75,10 +85,10 @@ (fix-height :command-suggestions-height :commands-height-changed :command-suggestions - minimum-command-suggestions-height)) + (constantly minimum-command-suggestions-height))) (register-handler :fix-response-height (fix-height :to-response-height :response-height-changed :suggestions - minimum-suggestion-height)) + get-minimum-height)) diff --git a/src/status_im/chat/styles/content_suggestions.cljs b/src/status_im/chat/styles/content_suggestions.cljs index 99c64afc20..97c403bca7 100644 --- a/src/status_im/chat/styles/content_suggestions.cljs +++ b/src/status_im/chat/styles/content_suggestions.cljs @@ -45,12 +45,3 @@ (def container {:backgroundColor color-white}) - -(def drag-down-touchable - {:height 22 - :alignItems :center - :justifyContent :center}) - -(def drag-down-icon - {:width 16 - :height 16}) diff --git a/src/status_im/chat/styles/dragdown.cljs b/src/status_im/chat/styles/dragdown.cljs new file mode 100644 index 0000000000..7505021a6f --- /dev/null +++ b/src/status_im/chat/styles/dragdown.cljs @@ -0,0 +1,12 @@ +(ns status-im.chat.styles.dragdown + (:require [status-im.components.styles :refer [color-white]])) + +(def drag-down-touchable + {:height 22 + :background-color color-white + :alignItems :center + :justifyContent :center}) + +(def drag-down-icon + {:width 16 + :height 16}) diff --git a/src/status_im/chat/styles/input.cljs b/src/status_im/chat/styles/input.cljs index 53e02cb16e..50f6fbfba7 100644 --- a/src/status_im/chat/styles/input.cljs +++ b/src/status_im/chat/styles/input.cljs @@ -21,8 +21,8 @@ {:flexDirection :column :marginTop 16 :marginBottom 16 - :marginLeft 16 - :marginRight 0 + :marginLeft 0 + :marginRight 8 :backgroundColor color :height 24 :borderRadius 50}) diff --git a/src/status_im/chat/styles/suggestions.cljs b/src/status_im/chat/styles/suggestions.cljs index 2d1d89525f..2e97d206b1 100644 --- a/src/status_im/chat/styles/suggestions.cljs +++ b/src/status_im/chat/styles/suggestions.cljs @@ -68,13 +68,3 @@ :height height :backgroundColor color-white :elevation 2}) - -(def drag-down-touchable - {:height 22 - :background-color color-white - :alignItems :center - :justifyContent :center}) - -(def drag-down-icon - {:width 16 - :height 16}) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index c5340917e0..5ca88dd550 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -121,8 +121,12 @@ (register-sub :messages-offset (fn [] (let [command? (subscribe [:command?]) + command (subscribe [:get-chat-command]) suggestions (subscribe [:get-suggestions])] ;; todo fix magic values - (reaction (cond @command? c/request-info-height - (seq @suggestions) c/suggestions-header-height - :else 0))))) + (reaction + (let [type (:type @command)] + (cond (and @command? (= type :response)) c/request-info-height + (and @command? (= type :command)) c/suggestions-header-height + (seq @suggestions) c/suggestions-header-height + :else 0)))))) diff --git a/src/status_im/chat/views/command.cljs b/src/status_im/chat/views/command.cljs index 21951d0bc7..c5f65f0130 100644 --- a/src/status_im/chat/views/command.cljs +++ b/src/status_im/chat/views/command.cljs @@ -29,7 +29,7 @@ (defn command-icon [command] [view (st/command-text-container command) - [text {:style st/command-text} (:text command)]]) + [text {:style st/command-text} (str "!" (:name command))]]) (defn cancel-button [] [touchable-highlight {:on-press cancel-command-input} diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index 1df66f9c3d..fcf0ce6492 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -47,12 +47,15 @@ (defview plain-message-input-view [{:keys [input-options validator]}] [command? [:command?] + {:keys [type] :as command} [:get-chat-command] input-command [:get-chat-command-content] valid-plain-message? [:valid-plain-message?] valid-command? [:valid-command? validator]] [view st/input-container [view st/input-view [plain-message/commands-button] + (when (and command? (= :command type)) + [command/command-icon command]) [message-input-container [message-input input-options validator]] ;; TODO emoticons: not implemented diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index b81763c9f6..eaad55d093 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -12,6 +12,7 @@ touchable-highlight]] [status-im.components.drag-drop :as drag] [status-im.chat.styles.response :as st] + [status-im.chat.styles.dragdown :as ddst] [status-im.components.animation :as anim] [status-im.chat.suggestions-responder :as resp])) @@ -41,15 +42,19 @@ :fix-response-height) command (subscribe [:get-chat-command])] (fn [response-height] - [view (merge (drag/pan-handlers pan-responder) - {:style (st/request-info (:color @command))}) - [drag-icon] - [view st/inner-container - [command-icon nil] - [info-container @command] - [touchable-highlight {:on-press #(dispatch [:start-cancel-command])} - [view st/cancel-container - [icon :close-white st/cancel-icon]]]]]))) + (if (= :response (:type @command)) + [view (merge (drag/pan-handlers pan-responder) + {:style (st/request-info (:color @command))}) + [drag-icon] + [view st/inner-container + [command-icon nil] + [info-container @command] + [touchable-highlight {:on-press #(dispatch [:start-cancel-command])} + [view st/cancel-container + [icon :close-white st/cancel-icon]]]]] + [view (merge (drag/pan-handlers pan-responder) + {:style ddst/drag-down-touchable}) + [icon :drag_down ddst/drag-down-icon]])))) (defn container-animation-logic [{:keys [to-value val]}] (let [to-value @to-value] diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 38336670fc..6004eb56ac 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -10,6 +10,7 @@ animated-view]] [status-im.utils.listview :refer [to-datasource]] [status-im.chat.styles.suggestions :as st] + [status-im.chat.styles.dragdown :as ddst] [reagent.core :as r] [status-im.components.animation :as anim] [status-im.components.drag-drop :as drag] @@ -59,8 +60,8 @@ (fn [_] [view (merge (drag/pan-handlers pan-responder) - {:style st/drag-down-touchable}) - [icon :drag_down st/drag-down-icon]]))) + {:style ddst/drag-down-touchable}) + [icon :drag_down ddst/drag-down-icon]]))) (defn container-animation-logic [{:keys [to-value val]}] (let [to-value @to-value] From 579269ebca8dcc57fb7635dadd37d814943c61ef Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 09:36:03 +0300 Subject: [PATCH 10/27] fix message offset Former-commit-id: 026b678e2079a1e0216307a41a0efba8e064bdab --- src/status_im/chat/handlers/animation.cljs | 2 +- src/status_im/chat/subs.cljs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 837991d98b..ec9f40289c 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -43,7 +43,7 @@ type (get-in db path)] (if (= :response type) minimum-suggestion-height - minimum-command-suggestions-height))) + 0.1))) (register-handler :animate-show-response [(after #(dispatch [:command-edit-mode]))] diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index ee803b5cd7..d8c5b545cb 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -131,11 +131,12 @@ (fn [] (let [command? (subscribe [:command?]) command (subscribe [:get-chat-command]) + command-suggestions (subscribe [:get-content-suggestions]) suggestions (subscribe [:get-suggestions])] - ;; todo fix magic values (reaction (let [type (:type @command)] (cond (and @command? (= type :response)) c/request-info-height - (and @command? (= type :command)) c/suggestions-header-height + (and @command? (= type :command) (seq @command-suggestions)) + c/suggestions-header-height (seq @suggestions) c/suggestions-header-height :else 0)))))) From 3fc913b682d5c1d8b4b2d42354b38edefe1b7540 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 11:24:46 +0300 Subject: [PATCH 11/27] commands canceling Former-commit-id: 471f637e0d420666dce3c807f011b25c371ab63b --- src/status_im/chat/handlers.cljs | 85 ++++++++++++-------- src/status_im/chat/styles/input.cljs | 7 +- src/status_im/chat/styles/message_input.cljs | 2 +- src/status_im/chat/styles/response.cljs | 5 +- src/status_im/chat/subs.cljs | 31 +++++-- src/status_im/chat/views/command.cljs | 12 ++- src/status_im/chat/views/message_input.cljs | 23 +++--- src/status_im/chat/views/new_message.cljs | 5 +- src/status_im/chat/views/plain_message.cljs | 3 +- 9 files changed, 110 insertions(+), 63 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index db9f710d26..a5af15c8a1 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -45,33 +45,44 @@ (update-in [:chats current-chat-id :input-text] safe-trim)))) (defn invoke-suggestions-handler! - [{:keys [current-chat-id] :as db} _] - (let [{:keys [command content]} (get-in db [:chats current-chat-id :command-input]) - {:keys [name type]} command - path [(if (= :command type) :commands :responses) - name - :params - 0 - :suggestions] - params {:value content}] - (j/call current-chat-id - path - params - #(dispatch [:suggestions-handler {:command command - :content content - :chat-id current-chat-id} %])))) + [{:keys [current-chat-id canceled-command] :as db} _] + (when-not canceled-command + (let [{:keys [command content]} (get-in db [:chats current-chat-id :command-input]) + {:keys [name type]} command + path [(if (= :command type) :commands :responses) + name + :params + 0 + :suggestions] + params {:value content}] + (j/call current-chat-id + path + params + #(dispatch [:suggestions-handler {:command command + :content content + :chat-id current-chat-id} %]))))) (register-handler :start-cancel-command (u/side-effect! (fn [db _] (dispatch [:animate-cancel-command])))) +(def command-prefix "c ") + +(defn cancel-command! + [{:keys [canceled-command]}] + (when canceled-command + (dispatch [:start-cancel-command]))) + (register-handler :set-chat-command-content - [(after invoke-suggestions-handler!)] + [(after invoke-suggestions-handler!) + (after cancel-command!)] (fn [{:keys [current-chat-id] :as db} [_ content]] - (as-> db db - (commands/set-chat-command-content db content) - (assoc-in db [:chats current-chat-id :input-text] nil)))) + (let [starts-as-command? (str/starts-with? content command-prefix)] + (as-> db db + (commands/set-chat-command-content db content) + (assoc-in db [:chats current-chat-id :input-text] nil) + (assoc db :canceled-command (not starts-as-command?)))))) (defn update-input-text [{:keys [current-chat-id] :as db} text] @@ -81,10 +92,10 @@ [{:keys [current-chat-id staged-command]} _] (let [{:keys [command content]} staged-command {:keys [name type]} command - path [(if (= :command type) :commands :responses) - name - :preview] - params {:value content}] + path [(if (= :command type) :commands :responses) + name + :preview] + params {:value content}] (j/call current-chat-id path params @@ -93,7 +104,7 @@ (register-handler :stage-command (after invoke-command-preview!) (fn [{:keys [current-chat-id] :as db} _] - (let [db (update-input-text db nil) + (let [db (update-input-text db nil) {:keys [command content]} (get-in db [:chats current-chat-id :command-input]) command-info {:command command @@ -120,8 +131,12 @@ (commands/set-response-chat-command db to-msg-id command-key))) (defn update-text - [db [_ text]] - (update-input-text db text)) + [{:keys [current-chat-id] :as db} [_ text]] + (let [suggestions (get-in db [:command-suggestions current-chat-id])] + (println :hui (count suggestions) text :bla) + (if-not (= 1 (count suggestions)) + (update-input-text db text) + db))) (defn update-command [db [_ text]] (if-not (commands/get-chat-command db) @@ -145,9 +160,8 @@ (register-handler :set-chat-input-text [(enrich update-command) (after select-suggestion!) - (enrich check-suggestions) (after #(dispatch [:animate-command-suggestions]))] - update-text) + ((enrich update-text) check-suggestions)) (defn console? [s] (= "console" s)) @@ -187,7 +201,7 @@ (defn prepare-message [{:keys [identity current-chat-id] :as db} _] - (let [text (get-in db [:chats current-chat-id :input-text]) + (let [text (get-in db [:chats current-chat-id :input-text]) [command] (suggestions/check-suggestion db (str text " ")) message (check-author-direction db current-chat-id @@ -312,8 +326,11 @@ (register-handler :set-chat-command [(after invoke-suggestions-handler!) (after #(dispatch [:command-edit-mode]))] - (fn [db [_ command-key]] - (commands/set-chat-command db command-key))) + (fn [{:keys [current-chat-id] :as db} [_ command-key]] + (-> db + (commands/set-chat-command command-key) + (assoc-in [:chats current-chat-id :command-input :content] "c ") + (assoc :disable-input true)))) (register-handler :init-console-chat (fn [db [_]] @@ -406,9 +423,9 @@ (defmethod nav/preload-data! :chat [{:keys [current-chat-id] :as db} [_ _ id]] - (let [chat-id (or id current-chat-id) + (let [chat-id (or id current-chat-id) messages (get-in db [:chats chat-id :messages]) - db' (assoc db :current-chat-id chat-id)] + db' (assoc db :current-chat-id chat-id)] (if (seq messages) db' (-> db' @@ -499,8 +516,8 @@ (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 + (after #(dispatch [:set-chat-input-text ""])) (edit-mode-handler :text)) diff --git a/src/status_im/chat/styles/input.cljs b/src/status_im/chat/styles/input.cljs index 50f6fbfba7..6dd49b23be 100644 --- a/src/status_im/chat/styles/input.cljs +++ b/src/status_im/chat/styles/input.cljs @@ -16,12 +16,17 @@ :backgroundColor color-white :elevation 4}) +(def command-container + {:left 0 + :backgroundColor :white + :position :absolute}) + (defn command-text-container [{:keys [color]}] {:flexDirection :column :marginTop 16 :marginBottom 16 - :marginLeft 0 + :marginLeft 16 :marginRight 8 :backgroundColor color :height 24 diff --git a/src/status_im/chat/styles/message_input.cljs b/src/status_im/chat/styles/message_input.cljs index e999f749a9..c27a359646 100644 --- a/src/status_im/chat/styles/message_input.cljs +++ b/src/status_im/chat/styles/message_input.cljs @@ -4,7 +4,7 @@ [status-im.chat.constants :refer [input-height]])) (def message-input-container - {:flex 1 + {:flex 1 :marginRight 0}) (def input-container diff --git a/src/status_im/chat/styles/response.cljs b/src/status_im/chat/styles/response.cljs index 8963f8a1fe..a0a5c08cd5 100644 --- a/src/status_im/chat/styles/response.cljs +++ b/src/status_im/chat/styles/response.cljs @@ -83,11 +83,12 @@ :width 12 :height 12}) -(def command-input +(defn command-input [ml disbale?] {:flex 1 :marginRight 16 + :margin-left (- ml 5) :marginTop -2 :padding 0 :fontSize 14 :fontFamily font - :color text1-color}) + :color (if disbale? color-white text1-color)}) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index d8c5b545cb..eee09009cf 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -127,16 +127,33 @@ (= :command) (reaction)))) +(register-sub :command-type + (fn [] + (let [command (subscribe [:get-chat-command])] + (reaction (:type @command))))) + (register-sub :messages-offset (fn [] (let [command? (subscribe [:command?]) - command (subscribe [:get-chat-command]) + type (subscribe [:command-type]) command-suggestions (subscribe [:get-content-suggestions]) suggestions (subscribe [:get-suggestions])] (reaction - (let [type (:type @command)] - (cond (and @command? (= type :response)) c/request-info-height - (and @command? (= type :command) (seq @command-suggestions)) - c/suggestions-header-height - (seq @suggestions) c/suggestions-header-height - :else 0)))))) + (cond (and @command? (= @type :response)) + c/request-info-height + + (and @command? (= @type :command) (seq @command-suggestions)) + c/suggestions-header-height + + (and (not @command?) (seq @suggestions)) + c/suggestions-header-height + + :else 0))))) + +(register-sub :command-icon-width + (fn [] + (let [width (subscribe [:get :command-icon-width]) + type (subscribe [:command-type])] + (reaction (if (= :command @type) + @width + 0))))) diff --git a/src/status_im/chat/views/command.cljs b/src/status_im/chat/views/command.cljs index c5f65f0130..49f5135b7e 100644 --- a/src/status_im/chat/views/command.cljs +++ b/src/status_im/chat/views/command.cljs @@ -27,9 +27,15 @@ (when (valid? message validator) (send-command))) -(defn command-icon [command] - [view (st/command-text-container command) - [text {:style st/command-text} (str "!" (:name command))]]) +(defview command-icon [command] + [icon-width [:get :command-icon-width]] + [view st/command-container + [view {:style (st/command-text-container command) + :onLayout (fn [event] + (let [width (.. event -nativeEvent -layout -width)] + (when (not= icon-width width) + (dispatch [:set :command-icon-width width]))))} + [text {:style st/command-text} (str "!" (:name command))]]]) (defn cancel-button [] [touchable-highlight {:on-press cancel-command-input} diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index fcf0ce6492..f9c5676ee5 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -21,24 +21,27 @@ (defn message-input-container [input] [view st/message-input-container input]) -(def plain-input-options +(defn plain-input-options [disbale?] {:style st-message/message-input - :onChangeText plain-message/set-input-message + :onChangeText (when-not disbale? plain-message/set-input-message) + :editable (not disbale?) :onSubmitEditing plain-message/send}) -(def command-input-options - {:style st-response/command-input +(defn command-input-options [icon-width disbale?] + {:style (st-response/command-input icon-width disbale?) :onChangeText command/set-input-message :onSubmitEditing command/send-command}) (defview message-input [input-options] [command? [:command?] input-message [:get-chat-input-text] - input-command [:get-chat-command-content]] + input-command [:get-chat-command-content] + icon-width [:command-icon-width] + disbale? [:get :disable-input]] [text-input (merge (if command? - command-input-options - plain-input-options) + (command-input-options icon-width disbale?) + (plain-input-options disbale?)) {:autoFocus false :blurOnSubmit false :accessibility-label :input} @@ -54,8 +57,6 @@ [view st/input-container [view st/input-view [plain-message/commands-button] - (when (and command? (= :command type)) - [command/command-icon command]) [message-input-container [message-input input-options validator]] ;; TODO emoticons: not implemented @@ -65,4 +66,6 @@ command/send-command plain-message/send)] [send-button {:on-press on-press - :accessibility-label :send-message}]))]]) + :accessibility-label :send-message}])) + (when (and command? (= :command type)) + [command/command-icon command])]]) diff --git a/src/status_im/chat/views/new_message.cljs b/src/status_im/chat/views/new_message.cljs index 2a1e2cd892..737a3f1344 100644 --- a/src/status_im/chat/views/new_message.cljs +++ b/src/status_im/chat/views/new_message.cljs @@ -24,10 +24,7 @@ :number {:input-options {:keyboardType :numeric}} ;; todo maybe nil is fine for now :) nil #_(throw (js/Error. "Uknown command type")))] - (println :plc placeholder) - (if placeholder - (assoc-in options [:input-options :placeholder] placeholder) - options))) + (assoc-in options [:input-options :placeholder] ""))) (defview show-input [] [parameter [:get-command-parameter] diff --git a/src/status_im/chat/views/plain_message.cljs b/src/status_im/chat/views/plain_message.cljs index 12ccadd664..86f06a7e6a 100644 --- a/src/status_im/chat/views/plain_message.cljs +++ b/src/status_im/chat/views/plain_message.cljs @@ -33,7 +33,8 @@ delay (if @command? 100 0)] (anim/start (anim/timing width {:toValue n-width :duration response-input-hiding-duration - :delay delay}))))) + :delay delay}) + #(dispatch [:set :disable-input false]))))) (defn commands-button [] (let [command? (subscribe [:command?]) From 00384bc79a59d240b9b01b86e67671381c1a32d8 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 11:55:56 +0300 Subject: [PATCH 12/27] fix responses animation Former-commit-id: 5af33a99caa3840d9865bd15b92e78918ebff59e --- src/status_im/chat/handlers.cljs | 10 +++++++--- src/status_im/chat/handlers/animation.cljs | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index a5af15c8a1..d5d5a1d63b 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -78,11 +78,13 @@ [(after invoke-suggestions-handler!) (after cancel-command!)] (fn [{:keys [current-chat-id] :as db} [_ content]] - (let [starts-as-command? (str/starts-with? content command-prefix)] + (let [starts-as-command? (str/starts-with? content command-prefix) + path [:chats current-chat-id :command-input :command :type] + command? (= :command (get-in db path))] (as-> db db (commands/set-chat-command-content db content) (assoc-in db [:chats current-chat-id :input-text] nil) - (assoc db :canceled-command (not starts-as-command?)))))) + (assoc db :canceled-command (and command? (not starts-as-command?))))))) (defn update-input-text [{:keys [current-chat-id] :as db} text] @@ -128,7 +130,9 @@ [(after invoke-suggestions-handler!) (after #(dispatch [:command-edit-mode]))] (fn [db [_ to-msg-id command-key]] - (commands/set-response-chat-command db to-msg-id command-key))) + (-> db + (commands/set-response-chat-command to-msg-id command-key) + (assoc :canceled-command false)))) (defn update-text [{:keys [current-chat-id] :as db} [_ text]] diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index ec9f40289c..4ae299dc71 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -52,6 +52,7 @@ height (if suggestions? middle-height (get-minimum-height db))] + (println "hei" suggestions? ) (assoc-in db [:animations :to-response-height] height)))) (defn fix-height From e4e30b85e44998d347fec6a0031cdf9197b532a0 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 11:58:37 +0300 Subject: [PATCH 13/27] prevent command cancelling Former-commit-id: e8d79e2efa1158ff1a27b3606b5e41d524229332 --- src/status_im/chat/views/message_input.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index f9c5676ee5..c96b36f22e 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -29,7 +29,7 @@ (defn command-input-options [icon-width disbale?] {:style (st-response/command-input icon-width disbale?) - :onChangeText command/set-input-message + :onChangeText (when-not disbale? command/set-input-message) :onSubmitEditing command/send-command}) (defview message-input [input-options] From cc850f3d7c6ff27ae215dcafbc6b1b860186efe3 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 12:10:06 +0300 Subject: [PATCH 14/27] placeholders Former-commit-id: dfaf0806a0afd7bc33300ef8020f7006ccb3ca56 --- src/status_im/chat/views/new_message.cljs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/status_im/chat/views/new_message.cljs b/src/status_im/chat/views/new_message.cljs index 737a3f1344..54bb81f2d7 100644 --- a/src/status_im/chat/views/new_message.cljs +++ b/src/status_im/chat/views/new_message.cljs @@ -16,7 +16,7 @@ (for [command staged-commands] ^{:key command} [staged-command-view command])]) -(defn get-options [{:keys [type placeholder]}] +(defn get-options [{:keys [type placeholder]} command-type] (let [options (case (keyword type) :phone {:input-options {:keyboardType :phone-pad} :validator valid-mobile-number?} @@ -24,13 +24,18 @@ :number {:input-options {:keyboardType :numeric}} ;; todo maybe nil is fine for now :) nil #_(throw (js/Error. "Uknown command type")))] - (assoc-in options [:input-options :placeholder] ""))) + (if (= :response command-type) + (if placeholder + (assoc-in options [:input-options :placeholder] placeholder) + options) + (assoc-in options [:input-options :placeholder] "")))) (defview show-input [] [parameter [:get-command-parameter] - command? [:command?]] + command? [:command?] + type [:command-type]] [plain-message-input-view - (when command? (get-options parameter))]) + (when command? (get-options parameter type))]) (defview chat-message-new [] [staged-commands [:get-chat-staged-commands]] From 5c5406021709b91c2aaa8cd7b12daed8429b4ba7 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 13:48:53 +0300 Subject: [PATCH 15/27] staged command content Former-commit-id: fe8ef287aab19af92bc01cda54382f8605a66949 --- src/status_im/chat/handlers.cljs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index d5d5a1d63b..26f7683ac1 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -107,10 +107,11 @@ (after invoke-command-preview!) (fn [{:keys [current-chat-id] :as db} _] (let [db (update-input-text db nil) - {:keys [command content]} - (get-in db [:chats current-chat-id :command-input]) - command-info {:command command - :content content}] + {:keys [command content]} (get-in db [:chats current-chat-id :command-input]) + content' (if (= :command (:type command)) + (subs content 2) + content) + command-info {:command command :content content'}] (-> db ;(assoc-in [:chats current-chat-id :command-input :command] nil) (commands/stage-command command-info) From 63fb7dce9491bf45e988278c5d97d285a8e8925b Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 14:28:43 +0300 Subject: [PATCH 16/27] locations Former-commit-id: 58675d5509a140b64934d6fd1ad04f1d098ad4f3 --- resources/commands.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/resources/commands.js b/resources/commands.js index ee5cac345b..1191fdd311 100644 --- a/resources/commands.js +++ b/resources/commands.js @@ -1,7 +1,36 @@ status.command({ name: "location", description: "Send location", - color: "#9a5dcf" + color: "#9a5dcf", + preview: function (params) { + var text = status.components.text( + { + style: { + marginTop: 5, + marginHorizontal: 0, + fontSize: 14, + fontFamily: "font", + color: "black" + } + }, params.value); + var uri = "https://maps.googleapis.com/maps/api/staticmap?center=" + + params.value + + "&size=100x100&maptype=roadmap&key=AIzaSyBNsj1qoQEYPb3IllmWMAscuXW0eeuYqAA&language=en" + + "&markers=size:mid%7Ccolor:0xff0000%7Clabel:%7C" + + params.value; + + var image = status.components.image( + { + source: {uri: uri}, + style: { + width: 100, + height: 100 + } + } + ); + + return status.components.view({}, [text, image]); + } }).param({ name: "address", type: status.types.TEXT, From 989309aa8c358440b4950878846f957709d04ae9 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 16:30:59 +0300 Subject: [PATCH 17/27] command suggestions design Former-commit-id: a1556ee3357c7dc05450791e33780ec62aecb36b --- src/status_im/chat/handlers.cljs | 2 - src/status_im/chat/handlers/animation.cljs | 9 ++-- src/status_im/chat/styles/suggestions.cljs | 16 ++++--- src/status_im/chat/views/suggestions.cljs | 53 ++++++++++++++-------- src/status_im/utils/handlers.cljs | 2 +- 5 files changed, 48 insertions(+), 34 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 26f7683ac1..ae8f747d2b 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -113,7 +113,6 @@ content) command-info {:command command :content content'}] (-> db - ;(assoc-in [:chats current-chat-id :command-input :command] nil) (commands/stage-command command-info) (assoc :staged-command command-info))))) @@ -138,7 +137,6 @@ (defn update-text [{:keys [current-chat-id] :as db} [_ text]] (let [suggestions (get-in db [:command-suggestions current-chat-id])] - (println :hui (count suggestions) text :bla) (if-not (= 1 (count suggestions)) (update-input-text db text) db))) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 4ae299dc71..9a98c088f0 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -30,8 +30,10 @@ (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) - changed? (if (and suggestions? (not= 0.1 current)) + height (if suggestions? middle-height 10) + changed? (if (and suggestions? + (not (nil? current)) + (not= 10 current)) identity inc)] (-> db (update :animations assoc :command-suggestions-height height) @@ -43,7 +45,7 @@ type (get-in db path)] (if (= :response type) minimum-suggestion-height - 0.1))) + 10))) (register-handler :animate-show-response [(after #(dispatch [:command-edit-mode]))] @@ -52,7 +54,6 @@ height (if suggestions? middle-height (get-minimum-height db))] - (println "hei" suggestions? ) (assoc-in db [:animations :to-response-height] height)))) (defn fix-height diff --git a/src/status_im/chat/styles/suggestions.cljs b/src/status_im/chat/styles/suggestions.cljs index 2e97d206b1..15ae5a1b9a 100644 --- a/src/status_im/chat/styles/suggestions.cljs +++ b/src/status_im/chat/styles/suggestions.cljs @@ -12,22 +12,23 @@ text2-color text3-color]])) -(def suggestion-height 88) +(def suggestion-height 60) + +(def suggestion-highlight + {:margin-left 57}) (def suggestion-container - {:flexDirection :column - :paddingLeft 16 - :backgroundColor color-white}) + {:backgroundColor color-white}) (def suggestion-sub-container {:height suggestion-height :borderBottomWidth 1 - :borderBottomColor separator-color}) + :borderBottomColor separator-color + :flex-direction :row}) (defn suggestion-background [{:keys [color]}] - {:alignSelf :flex-start - :marginTop 10 + {:marginTop 10 :height 24 :backgroundColor color :borderRadius 50}) @@ -55,6 +56,7 @@ {:flexDirection :row :marginVertical 1 :marginHorizontal 0 + :flex 1 :height (min 168 (* suggestion-height suggestions-count)) :backgroundColor color-white :borderRadius 5}) diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 6004eb56ac..53f7f68b5c 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -2,6 +2,7 @@ (:require-macros [status-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe dispatch]] [status-im.components.react :refer [view + scroll-view text icon touchable-highlight @@ -15,7 +16,8 @@ [status-im.components.animation :as anim] [status-im.components.drag-drop :as drag] [status-im.components.react :as react] - [status-im.chat.suggestions-responder :as resp])) + [status-im.chat.suggestions-responder :as resp] + [status-im.chat.constants :as c])) (defn set-command-input [command] (dispatch [:set-chat-command command])) @@ -26,29 +28,39 @@ :as suggestion}]] (let [label (str "!" name)] [touchable-highlight - {:onPress #(set-command-input command)} + {:onPress #(set-command-input command) + :style st/suggestion-highlight} [view st/suggestion-container [view st/suggestion-sub-container - [view (st/suggestion-background suggestion) - [text {:style st/suggestion-text} label]] - [text {:style st/value-text} label] - [text {:style st/description-text} description]]]])) + [view {:flex 0.6} + [text {:style st/value-text} label] + [text {:style st/description-text} description]] + [view {:flex 0.4 + :flex-direction :column + :align-items :flex-end + :margin-right 16} + [view (st/suggestion-background suggestion) + [text {:style st/suggestion-text} label]]]]]])) (defn render-row [row _ _] (list-item [suggestion-list-item row])) +(defn title [s] + [view {:margin-left 57 + :margin-bottom 16} + [text {:style {:font-size 13 + :color :#8f838c93}} s]]) -(defn suggestions-view [] - (let - [suggestions (subscribe [:get-suggestions])] - (r/create-class - {:reagent-render - (fn [] - [view (st/suggestions-container (count @suggestions)) - [list-view {:dataSource (to-datasource @suggestions) - :enableEmptySections true - :keyboardShouldPersistTaps true - :renderRow render-row}]])}))) +(defview suggestions-view [] + [suggestions [:get-suggestions] + requests [:get :chat-requests]] + [scroll-view + (when requests [title "Requests"]) + [title "Commands"] + [view (st/suggestions-container (count suggestions)) + [list-view {:dataSource (to-datasource suggestions) + :keyboardShouldPersistTaps true + :renderRow render-row}]]]) (defn header [h] (let [orientation (subscribe [:get :orientation]) @@ -64,7 +76,7 @@ [icon :drag_down ddst/drag-down-icon]]))) (defn container-animation-logic [{:keys [to-value val]}] - (let [to-value @to-value] + (when-let [to-value @to-value] (anim/start (anim/spring val {:toValue to-value})))) (defn container [h & elements] @@ -86,7 +98,8 @@ (into [animated-view {:style (st/container h)}] elements))}))) (defn suggestion-container [] - (let [h (anim/create-value 0)] + (let [h (anim/create-value 10)] [container h [header h] - [suggestions-view]])) + [suggestions-view] + [view {:height c/input-height}]])) diff --git a/src/status_im/utils/handlers.cljs b/src/status_im/utils/handlers.cljs index 083196375e..4d2777e335 100644 --- a/src/status_im/utils/handlers.cljs +++ b/src/status_im/utils/handlers.cljs @@ -11,4 +11,4 @@ (defn register-handler ([name handler] (register-handler name nil handler)) ([name middleware handler] - (re-core/register-handler name [#_debug middleware] handler))) + (re-core/register-handler name [debug middleware] handler))) From d6fd77697d3f8f6061e7a873f435725638254b87 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 18:54:01 +0300 Subject: [PATCH 18/27] requests in suggestions window Former-commit-id: 0761a1da1b881561edcc0e05465894b105d5ad9d --- src/status_im/chat/handlers.cljs | 15 ++++-- src/status_im/chat/handlers/animation.cljs | 3 +- src/status_im/chat/handlers/requests.cljs | 41 ++++++++++++++ src/status_im/chat/styles/suggestions.cljs | 62 ++++++++++++++++++---- src/status_im/chat/subs.cljs | 10 ++++ src/status_im/chat/views/suggestions.cljs | 44 ++++++++++----- src/status_im/constants.cljs | 2 +- src/status_im/handlers.cljs | 3 +- src/status_im/persistence/realm.cljs | 22 +++++++- 9 files changed, 171 insertions(+), 31 deletions(-) create mode 100644 src/status_im/chat/handlers/requests.cljs diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index ae8f747d2b..7015df6723 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -7,7 +7,8 @@ [status-im.protocol.api :as api] [status-im.models.messages :as messages] [status-im.constants :refer [text-content-type - content-type-command]] + content-type-command + content-type-command-request]] [status-im.utils.random :as random] [status-im.chat.sign-up :as sign-up-service] [status-im.models.chats :as chats] @@ -381,6 +382,7 @@ (dispatch [:load-commands! current-chat-id])) (register-handler :init-chat + (after #(dispatch [:load-requests!])) (-> load-messages! ((enrich init-chat)) ((after load-commands!)))) @@ -408,6 +410,11 @@ [{:keys [new-message]} [_ {chat-id :from}]] (messages/save-message chat-id new-message)) +(defn dispatch-request! + [{:keys [new-message]} [_ {chat-id :from}]] + (when (= (:content-type new-message) content-type-command-request) + (dispatch [:add-request chat-id new-message]))) + (defn receive-message [db [_ {chat-id :from :as message}]] (let [message' (check-author-direction db chat-id message)] @@ -416,8 +423,9 @@ (assoc :new-message message')))) (register-handler :received-msg - (-> receive-message - ((after store-message!)))) + [(after store-message!) + (after dispatch-request!)] + receive-message) (register-handler :group-received-msg (u/side-effect! @@ -429,6 +437,7 @@ (let [chat-id (or id current-chat-id) messages (get-in db [:chats chat-id :messages]) db' (assoc db :current-chat-id chat-id)] + (dispatch [:load-requests! chat-id]) (if (seq messages) db' (-> db' diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 9a98c088f0..dd5218ac0a 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -1,7 +1,6 @@ (ns status-im.chat.handlers.animation - (:require [re-frame.core :refer [after dispatch debug]] + (:require [re-frame.core :refer [after dispatch debug path]] [status-im.utils.handlers :refer [register-handler]] - [re-frame.middleware :refer [path]] [status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.chat.constants :refer [input-height request-info-height minimum-command-suggestions-height diff --git a/src/status_im/chat/handlers/requests.cljs b/src/status_im/chat/handlers/requests.cljs new file mode 100644 index 0000000000..828e952b81 --- /dev/null +++ b/src/status_im/chat/handlers/requests.cljs @@ -0,0 +1,41 @@ +(ns status-im.chat.handlers.requests + (:require [re-frame.core :refer [after]] + [status-im.utils.handlers :refer [register-handler]] + [status-im.persistence.realm :as realm])) + +(defn store-request! + [{:keys [new-request]}] + (realm/write + (fn [] + (realm/create :requests new-request)))) + +(defn add-request + [db [_ chat-id {:keys [msg-id content]}]] + (let [request {:chat-id chat-id + :message-id msg-id + :type (:command content) + :added (js/Date.)} + request' (update request :type keyword)] + (-> db + (update-in [:chats chat-id :requests] conj request') + (assoc :new-request request)))) + +(defn load-requests! + [{:keys [current-chat-id] :as db} [_ chat-id]] + (let [chat-id' (or chat-id current-chat-id) + requests (-> :requests + ;; todo maybe limit is needed + (realm/get-by-fieds {:chat-id chat-id' + :status "open"}) + (realm/sorted :added :desc) + (realm/collection->map)) + requests' (->> requests + (map #(update % :type keyword)) + (into '()))] + (assoc-in db [:chats chat-id' :requests] requests'))) + +(register-handler :add-request + (after store-request!) + add-request) + +(register-handler :load-requests! load-requests!) diff --git a/src/status_im/chat/styles/suggestions.cljs b/src/status_im/chat/styles/suggestions.cljs index 15ae5a1b9a..e21cd4c620 100644 --- a/src/status_im/chat/styles/suggestions.cljs +++ b/src/status_im/chat/styles/suggestions.cljs @@ -3,6 +3,7 @@ color-light-blue-transparent color-white color-black + color-gray color-blue color-blue-transparent selected-message-color @@ -26,6 +27,15 @@ :borderBottomColor separator-color :flex-direction :row}) +(def command-description-container + {:flex 0.6}) + +(def command-label-container + {:flex 0.4 + :flex-direction :column + :align-items :flex-end + :margin-right 16}) + (defn suggestion-background [{:keys [color]}] {:marginTop 10 @@ -40,6 +50,14 @@ :fontFamily font :color color-white}) +(def title-container + {:margin-left 57 + :margin-bottom 16}) + +(def title-text + {:font-size 13 + :color :#8f838c93}) + (def value-text {:marginTop 6 :fontSize 14 @@ -52,15 +70,6 @@ :fontFamily font :color text2-color}) -(defn suggestions-container [suggestions-count] - {:flexDirection :row - :marginVertical 1 - :marginHorizontal 0 - :flex 1 - :height (min 168 (* suggestion-height suggestions-count)) - :backgroundColor color-white - :borderRadius 5}) - (defn container [height] {:flexDirection :column :position :absolute @@ -70,3 +79,38 @@ :height height :backgroundColor color-white :elevation 2}) + +(def request-container + {:height 56 + :flex-direction :row}) + +(def request-icon-container + {:height 56 + :width 57 + :align-items :center + :justifyContent :center}) + +(defn request-icon-background [color] + {:height 32 + :width 32 + :border-radius 32 + :background-color color + :align-items :center + :justifyContent :center}) + +(def request-icon + {:width 12 + :height 12}) + +(def request-info-container + {:height 56 + :padding-top 10}) + +(def request-info-description + {:font-size 12 + :color color-black}) + +(def request-message-info + {:font-size 12 + :margin-top 2 + :color color-gray}) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index eee09009cf..0a8d999432 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -157,3 +157,13 @@ (reaction (if (= :command @type) @width 0))))) + +(register-sub :get-requests + (fn [db] + (let [chat-id (subscribe [:get-current-chat-id])] + (reaction (get-in @db [:chats @chat-id :requests]))))) + +(register-sub :get-response + (fn [db [_ n]] + (let [chat-id (subscribe [:get-current-chat-id])] + (reaction (get-in @db [:chats @chat-id :responses n]))))) diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 53f7f68b5c..1c91b8d89f 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -5,6 +5,7 @@ scroll-view text icon + image touchable-highlight list-view list-item @@ -15,13 +16,30 @@ [reagent.core :as r] [status-im.components.animation :as anim] [status-im.components.drag-drop :as drag] - [status-im.components.react :as react] [status-im.chat.suggestions-responder :as resp] [status-im.chat.constants :as c])) (defn set-command-input [command] (dispatch [:set-chat-command command])) +(defview request-item [{:keys [type message-id]}] + [{:keys [color icon description] :as response} [:get-response type]] + [touchable-highlight + {:on-press #(dispatch [:set-response-chat-command message-id type])} + [view st/request-container + [view st/request-icon-container + [view (st/request-icon-background color) + [image {:source {:uri icon} + :style st/request-icon}]]] + [view st/request-info-container + [text {:style st/request-info-description} description] + ;; todo stub + [text {:style st/request-message-info} + "By console, today at 14:50"]]]]) + +(defn render-request-row [row _ _] + (list-item [request-item row])) + (defn suggestion-list-item [[command {:keys [description] name :name @@ -29,16 +47,13 @@ (let [label (str "!" name)] [touchable-highlight {:onPress #(set-command-input command) - :style st/suggestion-highlight} + :style st/suggestion-highlight} [view st/suggestion-container [view st/suggestion-sub-container - [view {:flex 0.6} + [view st/command-description-container [text {:style st/value-text} label] [text {:style st/description-text} description]] - [view {:flex 0.4 - :flex-direction :column - :align-items :flex-end - :margin-right 16} + [view st/command-label-container [view (st/suggestion-background suggestion) [text {:style st/suggestion-text} label]]]]]])) @@ -46,18 +61,21 @@ (list-item [suggestion-list-item row])) (defn title [s] - [view {:margin-left 57 - :margin-bottom 16} - [text {:style {:font-size 13 - :color :#8f838c93}} s]]) + [view st/title-container + [text {:style st/title-text} s]]) (defview suggestions-view [] [suggestions [:get-suggestions] - requests [:get :chat-requests]] + requests [:get-requests]] [scroll-view (when requests [title "Requests"]) + (when requests + [view + [list-view {:dataSource (to-datasource requests) + :keyboardShouldPersistTaps true + :renderRow render-request-row}]]) [title "Commands"] - [view (st/suggestions-container (count suggestions)) + [view [list-view {:dataSource (to-datasource suggestions) :keyboardShouldPersistTaps true :renderRow render-row}]]]) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index fa6e3a7632..d01788d834 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -16,4 +16,4 @@ (def response-input-hiding-duration 100) (def response-suggesstion-resize-duration 100) -(def default-number-of-messages 10) +(def default-number-of-messages 20) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 7829563fe5..1c656f5514 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -19,7 +19,8 @@ status-im.commands.handlers.loading status-im.commands.handlers.jail status-im.qr-scanner.handlers - status-im.protocol.handlers)) + status-im.protocol.handlers + status-im.chat.handlers.requests)) ;; -- Middleware ------------------------------------------------------------ ;; diff --git a/src/status_im/persistence/realm.cljs b/src/status_im/persistence/realm.cljs index 8ed342537a..277da95dc3 100644 --- a/src/status_im/persistence/realm.cljs +++ b/src/status_im/persistence/realm.cljs @@ -2,7 +2,8 @@ (:require [cljs.reader :refer [read-string]] [status-im.components.styles :refer [default-chat-color]] [status-im.utils.types :refer [to-string]] - [status-im.utils.utils :as u]) + [status-im.utils.utils :as u] + [clojure.string :as str]) (:refer-clojure :exclude [exists?])) (def opts {:schema [{:name :contacts @@ -14,6 +15,13 @@ :optional true} :photo-path {:type "string" :optinal true}}} + {:name :requests + :properties {:message-id :string + :chat-id :string + :type :string + :status {:type :string + :default "open"} + :added :date}} {:name :kv-store :primaryKey :key :properties {:key "string" @@ -107,12 +115,16 @@ [schema-name obj] (write (fn [] (create schema-name obj true)))) +(defn and-q [queries] + (str/join " and " queries)) + (defmulti to-query (fn [schema-name operator field value] operator)) (defmethod to-query :eq [schema-name operator field value] (let [value (to-string value) - query (str (name field) "=" (if (= "string" (field-type schema-name field)) + query (str (name field) "=" (if (= "string" (name (field-type + schema-name field))) (str "\"" value "\"") value))] query)) @@ -125,6 +137,12 @@ (let [q (to-query schema-name :eq field value)] (.filtered (.objects realm (name schema-name)) q))) +(defn get-by-fieds [schema-name fields] + (let [queries (map (fn [[k v]] + (to-query schema-name :eq k v)) + fields)] + (.filtered (.objects realm (name schema-name)) (and-q queries)))) + (defn get-all [schema-name] (.objects realm (to-string schema-name))) From 0ce1e185810d211aa2d5a32c066841f3a85da7c0 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 11:12:10 +0300 Subject: [PATCH 19/27] rendering of a new request in list Former-commit-id: 952d3736c8ef4218769d7cd0d2f500281f416892 --- src/status_im/chat/handlers/requests.cljs | 4 +--- src/status_im/chat/views/suggestions.cljs | 7 +++++-- src/status_im/commands/handlers/loading.cljs | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/status_im/chat/handlers/requests.cljs b/src/status_im/chat/handlers/requests.cljs index 828e952b81..534a84cf6c 100644 --- a/src/status_im/chat/handlers/requests.cljs +++ b/src/status_im/chat/handlers/requests.cljs @@ -29,9 +29,7 @@ :status "open"}) (realm/sorted :added :desc) (realm/collection->map)) - requests' (->> requests - (map #(update % :type keyword)) - (into '()))] + requests' (map #(update % :type keyword) requests)] (assoc-in db [:chats chat-id' :requests] requests'))) (register-handler :add-request diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 1c91b8d89f..4438fe5865 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -37,8 +37,11 @@ [text {:style st/request-message-info} "By console, today at 14:50"]]]]) -(defn render-request-row [row _ _] - (list-item [request-item row])) +(defn render-request-row + [{:keys [chat-id message-id] :as row} _ _] + (list-item + ^{:key [chat-id message-id]} + [request-item row])) (defn suggestion-list-item [[command {:keys [description] diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index 2291ade0fc..b7b26589fe 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -91,13 +91,13 @@ (reg-handler ::fetch-commands! (u/side-effect! fetch-commands!)) (reg-handler ::validate-hash - (after dispatch-loaded!) - validate-hash) + (after dispatch-loaded!) + validate-hash) (reg-handler ::parse-commands! (u/side-effect! parse-commands!)) (reg-handler ::add-commands - (after save-commands-js!) - add-commands) + (after save-commands-js!) + add-commands) (reg-handler ::loading-failed! (u/side-effect! loading-failed!)) From b763d5d9c907a0a87ddd8f8a3b8602eab1958fd7 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 11:48:56 +0300 Subject: [PATCH 20/27] commands button Former-commit-id: e728c155a12139daf977397fb0ea7a6de5339b57 --- .../res/drawable-hdpi/icon_input_list.png | Bin 0 -> 469 bytes .../res/drawable-mdpi/icon_input_list.png | Bin 0 -> 247 bytes .../res/drawable-xhdpi/icon_input_list.png | Bin 0 -> 333 bytes .../res/drawable-xxhdpi/icon_input_list.png | Bin 0 -> 651 bytes .../res/drawable-xxxhdpi/icon_input_list.png | Bin 0 -> 823 bytes src/status_im/chat/styles/plain_message.cljs | 19 +++++++-- src/status_im/chat/views/plain_message.cljs | 40 +++++++++++------- 7 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 android/app/src/main/res/drawable-hdpi/icon_input_list.png create mode 100644 android/app/src/main/res/drawable-mdpi/icon_input_list.png create mode 100644 android/app/src/main/res/drawable-xhdpi/icon_input_list.png create mode 100644 android/app/src/main/res/drawable-xxhdpi/icon_input_list.png create mode 100644 android/app/src/main/res/drawable-xxxhdpi/icon_input_list.png diff --git a/android/app/src/main/res/drawable-hdpi/icon_input_list.png b/android/app/src/main/res/drawable-hdpi/icon_input_list.png new file mode 100644 index 0000000000000000000000000000000000000000..033344a21f021a20db58e5af74c97984f30c8fec GIT binary patch literal 469 zcmV;`0V@89P)Px$k4Z#9R5%gs6g^8qQS_X9uR=p04J{2i*qTH%H}nVcCkR0#MJNs>H5p2vMkqRo zKf&5v+6`)Mv3`M5p}y5-gUs~0ze!LbZ-jhdBWXO zxo;;(o^Tlf5Cv*@l{+2sQ!LdQuVgr7^(4r2v5U6I&YcRKpoF#t)+3jz`F zopt#w@>Q<3jyQ4|iS{lpPCl8pIyM8LrwB{cMxDI5MUJRw%GTko(^;R6zUv0ewvEUO zDZ()zwyyJMPhJ_*iprd!PFfrTF+H86iFjZJ8P8D59WR9bH>;w7eF7VPFL(|R@v%nCe-x6Ni!OhiJXp4ZE3NCJ+NTbnOl{)!Hq z0SseZvv*sYP}a5m9(6@Olyz+#(1h%TvaZ86w4sQ&Ybov;*ef~9ZRs?1{39t zjVF#A`0`&~_;O;v0Y&SXFC6|H|G+O%@c$rVdmh6zhm>F6&x@_-6kI0pj7g&Y!vz<1 vr7(5oVC9RA9ak9=vQ+F{uACuL|d!n>e8f=y(QCS3j3^P6Px$2T4RhR7eeDT(xQy+s((Xniv`W$1woGe+I@y>at>WVPRpvKzv#Q7Ler(|Noc& zhuieO94H3jRltRSjMn~Xp8x*-odsmdAd8d1e!|Sim|j(!vkjz|3FdQTgRqHF$#Rf2 zGJpU7p9!;%3C0*Gnh6x==$2y>0|gsU-4k@RWbmIbF*B#Z^f3-}B7`|)lpeVuFyM)h zq>}Lezkf6T|Nk#bWPE|MTXkX9c6{ndDhWxj9Au{qwDiPhKf}-|38AGI(Ip`xBjaP_ z5)W4}40s~M<*-rlkrM&~o(PF93EO(7ctM*|l(q?B(F<-H5?vBf*>aF0z-_~!Qxa0K fO^6Z&1D*&0^;fc{?`V4|00000NkvXXu0mjf5;uyo literal 0 HcmV?d00001 diff --git a/android/app/src/main/res/drawable-xxhdpi/icon_input_list.png b/android/app/src/main/res/drawable-xxhdpi/icon_input_list.png new file mode 100644 index 0000000000000000000000000000000000000000..9e4fd528b3052cec72c432a4092e9f297d4b997f GIT binary patch literal 651 zcmV;60(AX}P)Px%MM*?KR9Fe^SiLVqK@gwWcS1))f<#G0N3D=(XzyPTL2^ezg3?DwxJwZ6FI-DQ z6k19uO2rYHQ#$YMnmsld&pFH9yWC6OHoH4JyYsPcXMS%Gs1*tY@9zG2L4isG!T>0^ zMZiLTU*}Fboenflvo`!t{^^{Q9}O!>MqKpwb&b_BVm)`%4Z+)_MAZ}CU(dNvSWLC5 zlcl-2B0o3v>G@GkG-GX)UZ?rCq49og_i#kY@+r|e=++`_k_5cH;>$*Ue|$MJdufD; z%4cI{Rr;FiD#+2f9aXkPLLyz-10Qnya8dc@IVC*SZ{mkWP9OSVDLOL3AU|B_2g?cH z#2W9{&|58WDxS zYdK!YPCa}vKu_YF2e>iGIPpN@fy4ui_W&ifc!yEvM5f`il>P*O?ER1b1qdYpibAAL z!b!^JJSRB4nLilzgYuaRB9%buQzKYjB6vQ&IzN47qqyO5g402u@-E67B`Up!E ztH`U<+yGvwc7oGN2K9r}TtkbosZ=|`X##RzD#aFZ>&rs&n+i_<)jAEoo#1rCtJB;< l4dcN_Fh>z&pIia(Xk^e@_4a002ovPDHLkV1h)hEa3nE literal 0 HcmV?d00001 diff --git a/android/app/src/main/res/drawable-xxxhdpi/icon_input_list.png b/android/app/src/main/res/drawable-xxxhdpi/icon_input_list.png new file mode 100644 index 0000000000000000000000000000000000000000..d136f96ef87a84076a4bf075d92ad4491c369a98 GIT binary patch literal 823 zcmV-71IYY|P)Px%@kvBMRA>e5TFq+{Q4pV5n{5s%=s{?!7q2SqMXwe`6!hfTLqY4ofP$s*QctD_ zD~%vT(Y7Zg)w58cSgoEsh)}`5K&`!4!Bb33o-<35w&P1TOE=x!zPAvv^TEEE-@cF8 zAA?Z8lv0?>KfD4;T?T|Bo?5{dK%5!7d2JdIRl|2D{Uawce*bZgs#Ts62&Z+)QSu9J z8ZTutnH8Nq$+|9n^W*tK%j7vZ2ButsXY_xjotbd=!PLQW`OiI?G$)mUo@fEW6^i2> zfHOKalKCoQ+10i8z%XTaLmD*l;rAatet$bZ_eo=Gs=VYYr6p1vr{A8YA-bF0H1tuL z>O-f_o-e+cpZmQ&6vtch>ouF*^Zwv-RVt+kP_W;}ZQIQX)IOTQ6LMgux#3BRPHt?D zI@_9VaP2l;cf2HJM2=LLCesq2qpsbn4PV+*X~T)_wJ0N_C4e(h*-~!9mrjW+0{&|G zjHnC0QJ+#(W`+i-$nFhy zLE$oUeEemn`?v`@R!2C&YPI~Cl0QMgbb=G)XCAB8{tlhHaIyIM)yoYWUr+#&%Lx+i z$jo!lgr$F?IYAxAClmCOEhm_8PH@rh4g1+c=LB81dz7g5Rlk9^YA4?Dr;g(b`rObt zK|Y$8e&(=!o^DYttdjAPLFLdf`1*nh@Z4~u|Bz#?D~un1TLb}9nK z7edCD!kys+CkuzTBZ~=(==%ia;@#Lch<7Fn)F)VbBHgqyI#+LxWTv#Xx-v(}Q?tPm zx20|77q!i66O3D*;D347`vwu50gl!9Ldf`1_#gZjvG^HO7#siq002ovPDHLkV1fbj Bg_r;U literal 0 HcmV?d00001 diff --git a/src/status_im/chat/styles/plain_message.cljs b/src/status_im/chat/styles/plain_message.cljs index b85dea9a97..fa639b39fa 100644 --- a/src/status_im/chat/styles/plain_message.cljs +++ b/src/status_im/chat/styles/plain_message.cljs @@ -9,11 +9,24 @@ :justifyContent :center}) (defn message-input-button [scale] - {:transform [{:scale scale}]}) + {:transform [{:scale scale}] + :width 24 + :height 24 + :alignItems :center + :justifyContent :center}) (def list-icon - {:width 13 - :height 12}) + {:width 16 + :height 16}) + +(def requests-icon + {:background-color :#7099e6 + :width 8 + :height 8 + :border-radius 8 + :left 0 + :top 0 + :position :absolute}) (def close-icon {:width 12 diff --git a/src/status_im/chat/views/plain_message.cljs b/src/status_im/chat/views/plain_message.cljs index 86f06a7e6a..f1dc3a0cde 100644 --- a/src/status_im/chat/views/plain_message.cljs +++ b/src/status_im/chat/views/plain_message.cljs @@ -5,6 +5,7 @@ [status-im.components.react :refer [view animated-view icon + text touchable-highlight]] [status-im.components.animation :as anim] [status-im.chat.styles.plain-message :as st] @@ -30,22 +31,24 @@ (defn list-container [min] (fn [{:keys [command? width]}] (let [n-width (if @command? min 56) - delay (if @command? 100 0)] + delay (if @command? 100 0)] (anim/start (anim/timing width {:toValue n-width :duration response-input-hiding-duration :delay delay}) #(dispatch [:set :disable-input false]))))) (defn commands-button [] - (let [command? (subscribe [:command?]) - buttons-scale (anim/create-value (if @command? 1 0)) + (let [command? (subscribe [:command?]) + requests (subscribe [:get-requests]) + suggestions (subscribe [:get-suggestions]) + buttons-scale (anim/create-value (if @command? 1 0)) container-width (anim/create-value (if @command? 20 56)) - context {:command? command? - :val buttons-scale - :width container-width} - on-update (fn [_] - ((button-animation-logic context)) - ((list-container 20) context))] + context {:command? command? + :val buttons-scale + :width container-width} + on-update (fn [_] + ((button-animation-logic context)) + ((list-container 20) context))] (r/create-class {:component-did-mount on-update @@ -58,7 +61,12 @@ [animated-view {:style (st/message-input-button-touchable container-width)} [animated-view {:style (st/message-input-button buttons-scale)} - [icon :list st/list-icon]]]])}))) + (if (seq @suggestions) + [icon :close_gray st/close-icon] + [icon :input_list st/list-icon]) + (when (and (seq @requests) + (not (seq @suggestions))) + [view st/requests-icon])]]])}))) (defn smile-animation-logic [{:keys [command? val width]}] (fn [_] @@ -71,13 +79,13 @@ (anim/set-value width 0.1))))))) (defn smile-button [] - (let [command? (subscribe [:command?]) - buttons-scale (anim/create-value (if @command? 1 0)) + (let [command? (subscribe [:command?]) + buttons-scale (anim/create-value (if @command? 1 0)) container-width (anim/create-value (if @command? 0.1 56)) - context {:command? command? - :val buttons-scale - :width container-width} - on-update (smile-animation-logic context)] + context {:command? command? + :val buttons-scale + :width container-width} + on-update (smile-animation-logic context)] (r/create-class {:component-did-mount on-update From d0e9eb04eab91668654e5e419ffa640086189b28 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 13:52:04 +0300 Subject: [PATCH 21/27] remove request after answering & request icon animation Former-commit-id: b7426f7eba106f10115b7beb909bd308a18b0efa --- src/status_im/chat/handlers.cljs | 28 ++++++++++----- src/status_im/chat/handlers/requests.cljs | 26 +++++++++++--- src/status_im/chat/subs.cljs | 5 +++ src/status_im/chat/views/request_message.cljs | 36 ++++++++++++------- src/status_im/chat/views/suggestions.cljs | 4 +-- src/status_im/persistence/realm.cljs | 2 +- 6 files changed, 73 insertions(+), 28 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 7015df6723..68b8a79eac 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -108,11 +108,14 @@ (after invoke-command-preview!) (fn [{:keys [current-chat-id] :as db} _] (let [db (update-input-text db nil) - {:keys [command content]} (get-in db [:chats current-chat-id :command-input]) + {:keys [command content to-msg-id]} + (get-in db [:chats current-chat-id :command-input]) content' (if (= :command (:type command)) - (subs content 2) - content) - command-info {:command command :content content'}] + (subs content 2) + content) + command-info {:command command + :content content' + :to-message to-msg-id}] (-> db (commands/stage-command command-info) (assoc :staged-command command-info))))) @@ -222,7 +225,7 @@ (assoc db :new-message (when-not (str/blank? text) message))))) (defn prepare-command - [identity chat-id {:keys [preview preview-string content command]}] + [identity chat-id {:keys [preview preview-string content command to-message]}] (let [content {:command (command :name) :content content}] {:msg-id (random/id) @@ -232,7 +235,8 @@ :content-type content-type-command :outgoing true :preview preview-string - :rendered-preview preview})) + :rendered-preview preview + :to-message to-message})) (defn prepare-staged-commans [{:keys [current-chat-id identity] :as db} _] @@ -285,8 +289,15 @@ (defn save-commands-to-realm! [{:keys [new-commands current-chat-id]} _] (doseq [new-command new-commands] - (messages/save-message current-chat-id - (dissoc new-command :rendered-preview)))) + (messages/save-message + current-chat-id + (dissoc new-command :rendered-preview :to-message)))) + +(defn dispatch-responded-requests! + [{:keys [new-commands current-chat-id]} _] + (doseq [{:keys [to-message]} new-commands] + (when to-message + (dispatch [:request-answered! current-chat-id to-message])))) (defn invoke-commands-handlers! [{:keys [new-commands current-chat-id]}] @@ -319,6 +330,7 @@ ((after send-message!)) ((after save-message-to-realm!)) ((after save-commands-to-realm!)) + ((after dispatch-responded-requests!)) ;; todo maybe it is better to track if it was handled or not ((after invoke-commands-handlers!)) ((after handle-commands)))) diff --git a/src/status_im/chat/handlers/requests.cljs b/src/status_im/chat/handlers/requests.cljs index 534a84cf6c..d229b0dc94 100644 --- a/src/status_im/chat/handlers/requests.cljs +++ b/src/status_im/chat/handlers/requests.cljs @@ -1,7 +1,8 @@ (ns status-im.chat.handlers.requests - (:require [re-frame.core :refer [after]] + (:require [re-frame.core :refer [after dispatch enrich]] [status-im.utils.handlers :refer [register-handler]] - [status-im.persistence.realm :as realm])) + [status-im.persistence.realm :as realm] + [status-im.utils.handlers :as u])) (defn store-request! [{:keys [new-request]}] @@ -25,15 +26,32 @@ (let [chat-id' (or chat-id current-chat-id) requests (-> :requests ;; todo maybe limit is needed - (realm/get-by-fieds {:chat-id chat-id' - :status "open"}) + (realm/get-by-fields {:chat-id chat-id' + :status "open"}) (realm/sorted :added :desc) (realm/collection->map)) requests' (map #(update % :type keyword) requests)] (assoc-in db [:chats chat-id' :requests] requests'))) +(defn mark-request-as-answered! + [_ [_ chat-id message-id]] + (realm/write + (fn [] + (-> :requests + (realm/get-by-fields + {:chat-id chat-id + :message-id message-id}) + (realm/single) + (.-status) + (set! "answered"))))) + (register-handler :add-request (after store-request!) add-request) (register-handler :load-requests! load-requests!) + +(register-handler :request-answered! + (after (fn [_ [_ chat-id]] + (dispatch [:load-requests! chat-id]))) + (u/side-effect! mark-request-as-answered!)) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 0a8d999432..ae90e45bc0 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -167,3 +167,8 @@ (fn [db [_ n]] (let [chat-id (subscribe [:get-current-chat-id])] (reaction (get-in @db [:chats @chat-id :responses n]))))) + +(register-sub :is-request-answered? + (fn [_ [_ message-id]] + (let [requests (subscribe [:get-requests])] + (reaction (not (some #(= message-id (:message-id %)) @requests)))))) diff --git a/src/status_im/chat/views/request_message.cljs b/src/status_im/chat/views/request_message.cljs index 77e5834327..38b9237137 100644 --- a/src/status_im/chat/views/request_message.cljs +++ b/src/status_im/chat/views/request_message.cljs @@ -22,23 +22,33 @@ (def min-scale 1) (def max-scale 1.3) +(defn button-animation [val to-value loop? answered?] + (anim/anim-sequence + [(anim/anim-delay + (if (and @loop? (not @answered?)) + request-message-icon-scale-delay + 0)) + (anim/spring val {:toValue to-value})])) + (defn request-button-animation-logic - [{:keys [to-value val loop?] :as context}] + [{:keys [to-value val loop? answered?] :as context}] (anim/start - (anim/anim-sequence - [(anim/anim-delay (if @loop? request-message-icon-scale-delay 0)) - (anim/spring val {:toValue to-value})]) - #(when @loop? + (button-animation val to-value loop? answered?) + #(if (and @loop? (not @answered?)) (let [new-value (if (= to-value min-scale) max-scale min-scale) context' (assoc context :to-value new-value)] - (request-button-animation-logic context'))))) + (request-button-animation-logic context')) + (anim/start + (button-animation val min-scale loop? answered?))))) (defn request-button [msg-id command] (let [scale-anim-val (anim/create-value min-scale) + answered? (subscribe [:is-request-answered? msg-id]) loop? (r/atom true) - context {:to-value max-scale - :val scale-anim-val - :loop? loop?}] + context {:to-value max-scale + :val scale-anim-val + :answered? answered? + :loop? loop?}] (r/create-class {:component-did-mount #(request-button-animation-logic context) @@ -46,10 +56,10 @@ #(reset! loop? false) :reagent-render (fn [msg-id command] - [touchable-highlight {:on-press (fn [] - (reset! loop? false) - (set-chat-command msg-id command)) - :style st/command-request-image-touchable} + [touchable-highlight + {:on-press (when-not @answered? + #(set-chat-command msg-id command)) + :style st/command-request-image-touchable} [animated-view {:style (st/command-request-image-view command scale-anim-val)} [image {:source {:uri (:icon command)} :style st/command-request-image}]]])}))) diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 4438fe5865..d946c5fa8d 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -71,8 +71,8 @@ [suggestions [:get-suggestions] requests [:get-requests]] [scroll-view - (when requests [title "Requests"]) - (when requests + (when (seq requests) [title "Requests"]) + (when (seq requests) [view [list-view {:dataSource (to-datasource requests) :keyboardShouldPersistTaps true diff --git a/src/status_im/persistence/realm.cljs b/src/status_im/persistence/realm.cljs index 277da95dc3..e0ee29a606 100644 --- a/src/status_im/persistence/realm.cljs +++ b/src/status_im/persistence/realm.cljs @@ -137,7 +137,7 @@ (let [q (to-query schema-name :eq field value)] (.filtered (.objects realm (name schema-name)) q))) -(defn get-by-fieds [schema-name fields] +(defn get-by-fields [schema-name fields] (let [queries (map (fn [[k v]] (to-query schema-name :eq k v)) fields)] From e830ecdb394386b6e863f3d701c76a8eebde79a7 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 14:06:00 +0300 Subject: [PATCH 22/27] commands suggestions header icon Former-commit-id: ac80ae632f1097082769a362df86d67787ec9009 --- src/status_im/chat/styles/suggestions.cljs | 6 ++++++ src/status_im/chat/views/request_message.cljs | 2 +- src/status_im/chat/views/suggestions.cljs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/status_im/chat/styles/suggestions.cljs b/src/status_im/chat/styles/suggestions.cljs index e21cd4c620..2985922cd7 100644 --- a/src/status_im/chat/styles/suggestions.cljs +++ b/src/status_im/chat/styles/suggestions.cljs @@ -114,3 +114,9 @@ {:font-size 12 :margin-top 2 :color color-gray}) + +(def header-icon + {:background-color :#838c93 + :width 14 + :border-radius 1 + :height 3}) diff --git a/src/status_im/chat/views/request_message.cljs b/src/status_im/chat/views/request_message.cljs index 38b9237137..2bbd4e11df 100644 --- a/src/status_im/chat/views/request_message.cljs +++ b/src/status_im/chat/views/request_message.cljs @@ -51,7 +51,7 @@ :loop? loop?}] (r/create-class {:component-did-mount - #(request-button-animation-logic context) + (when-not @answered? #(request-button-animation-logic context)) :component-will-unmount #(reset! loop? false) :reagent-render diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index d946c5fa8d..c9a7615317 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -94,7 +94,7 @@ [view (merge (drag/pan-handlers pan-responder) {:style ddst/drag-down-touchable}) - [icon :drag_down ddst/drag-down-icon]]))) + [view st/header-icon]]))) (defn container-animation-logic [{:keys [to-value val]}] (when-let [to-value @to-value] From cbca3803c18758d0de003a8d87076e981111785f Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 15:23:31 +0300 Subject: [PATCH 23/27] persist tap Former-commit-id: aa22c975c811f6cd64371657322fb02455b7b531 --- src/status_im/chat/views/suggestions.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index c9a7615317..98f3e9e3e5 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -70,7 +70,7 @@ (defview suggestions-view [] [suggestions [:get-suggestions] requests [:get-requests]] - [scroll-view + [scroll-view {:keyboardShouldPersistTaps true} (when (seq requests) [title "Requests"]) (when (seq requests) [view From 2280fd71243de2ff777f28e6d9c8a25e3011a739 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 15:54:44 +0300 Subject: [PATCH 24/27] improve animation Former-commit-id: b4a1e9afd63105ceb59aece1dd1c1a13367ae29b --- src/status_im/android/core.cljs | 9 +++++--- src/status_im/chat/handlers.cljs | 21 ++++++++++++++++-- src/status_im/chat/handlers/animation.cljs | 25 ++++++++++++++++++---- src/status_im/chat/screen.cljs | 2 +- src/status_im/chat/views/suggestions.cljs | 2 +- 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index e69e22cc2f..5405f58393 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -39,7 +39,8 @@ (defn app-root [] (let [signed-up (subscribe [:get :signed-up]) - view-id (subscribe [:get :view-id])] + view-id (subscribe [:get :view-id]) + keyboard-height (subscribe [:get :keyboard-height])] (r/create-class {:component-will-mount (fn [] @@ -53,10 +54,12 @@ "keyboardDidShow" (fn [e] (let [h (.. e -endCoordinates -height)] - (dispatch [:set :keyboard-height h])))) + (when-not (= h keyboard-height) + (dispatch [:set :keyboard-height h]))))) (.addListener device-event-emitter "keyboardDidHide" - #(dispatch [:set :keyboard-height 0]))) + (when-not (= 0 keyboard-height) + #(dispatch [:set :keyboard-height 0])))) :render (fn [] (case (if @signed-up @view-id :chat) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 68b8a79eac..248520ca44 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -132,7 +132,8 @@ (register-handler :set-response-chat-command [(after invoke-suggestions-handler!) - (after #(dispatch [:command-edit-mode]))] + (after #(dispatch [:command-edit-mode])) + (after #(dispatch [:set-chat-input-text ""]))] (fn [db [_ to-msg-id command-key]] (-> db (commands/set-response-chat-command to-msg-id command-key) @@ -143,7 +144,7 @@ (let [suggestions (get-in db [:command-suggestions current-chat-id])] (if-not (= 1 (count suggestions)) (update-input-text db text) - db))) + (assoc db :disable-input true)))) (defn update-command [db [_ text]] (if-not (commands/get-chat-command db) @@ -545,3 +546,19 @@ (register-handler :text-edit-mode (after #(dispatch [:set-chat-input-text ""])) (edit-mode-handler :text)) + +(register-handler :set-layout-height + [(after + (fn [{:keys [current-chat-id] :as db}] + (let [suggestions (get-in db [:suggestions current-chat-id]) + mode (get-in db [:edit-mode current-chat-id])] + (when (and (= :command mode) (seq suggestions)) + (dispatch [:fix-response-height]))))) + (after + (fn [{:keys [current-chat-id] :as db}] + (let [suggestions (get-in db [:command-suggestions current-chat-id]) + mode (get-in db [:edit-mode current-chat-id])] + (when (and (= :text mode)) (seq suggestions) + (dispatch [:fix-commands-suggestions-height])))))] + (fn [db [_ h]] + (assoc db :layout-height h))) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index dd5218ac0a..571297542b 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -29,10 +29,10 @@ (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 10) + height (if suggestions? middle-height 30) changed? (if (and suggestions? (not (nil? current)) - (not= 10 current)) + (not= 30 current)) identity inc)] (-> db (update :animations assoc :command-suggestions-height height) @@ -44,7 +44,7 @@ type (get-in db path)] (if (= :response type) minimum-suggestion-height - 10))) + 30))) (register-handler :animate-show-response [(after #(dispatch [:command-edit-mode]))] @@ -64,9 +64,19 @@ under-middle-position? (<= current middle-height) over-middle-position? (not under-middle-position?) suggestions (get-in db [suggestions-key current-chat-id]) + old-fixed (get-in db [:animations height-key]) + new-fixed (cond (not suggestions) (minimum db) + (and (nil? vy) (nil? current) + (> old-fixed middle-height)) + max-height + + (and (nil? vy) (nil? current) + (< old-fixed middle-height)) + (minimum db) + (and under-middle-position? moving-up?) middle-height @@ -82,11 +92,18 @@ (assoc-in [:animations height-key] new-fixed) (update-in [:animations height-signal-key] inc))))) +(defn commands-min-height + [{:keys [current-chat-id] :as db}] + (let [suggestions (get-in db [:command-suggestions current-chat-id])] + (if (seq suggestions) + minimum-command-suggestions-height + 0.1))) + (register-handler :fix-commands-suggestions-height (fix-height :command-suggestions-height :commands-height-changed :command-suggestions - (constantly minimum-command-suggestions-height))) + commands-min-height)) (register-handler :fix-response-height (fix-height :to-response-height diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 0652d5109d..d2b7126cbb 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -262,7 +262,7 @@ :onLayout (fn [event] (let [height (.. event -nativeEvent -layout -height)] (when (not= height layout-height) - (dispatch [:set :layout-height height]))))} + (dispatch [:set-layout-height height]))))} [chat-toolbar] [messages-container [messages-view group-chat]] diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 98f3e9e3e5..c28b8770ec 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -119,7 +119,7 @@ (into [animated-view {:style (st/container h)}] elements))}))) (defn suggestion-container [] - (let [h (anim/create-value 10)] + (let [h (anim/create-value 0.1)] [container h [header h] [suggestions-view] From b746bcef4f1d543ca7dd13ec204fbcdb4fe61a0b Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 17:23:38 +0300 Subject: [PATCH 25/27] attempt to fix performance issues Former-commit-id: 3a93e0890bfea4b167b934c26f2c5096ea73421a --- src/status_im/chat/handlers.cljs | 18 ++++++++++++------ src/status_im/commands/handlers/loading.cljs | 3 +-- src/status_im/commands/utils.cljs | 2 +- src/status_im/constants.cljs | 2 +- src/status_im/contacts/handlers.cljs | 3 ++- src/status_im/discovery/handlers.cljs | 3 ++- src/status_im/group_settings/handlers.cljs | 4 ++-- src/status_im/models/messages.cljs | 2 +- src/status_im/navigation/handlers.cljs | 3 ++- src/status_im/new_group/handlers.cljs | 3 ++- src/status_im/participants/handlers.cljs | 3 ++- src/status_im/protocol/handlers.cljs | 3 ++- src/status_im/qr_scanner/handlers.cljs | 3 ++- 13 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 248520ca44..05ab26564f 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -8,7 +8,8 @@ [status-im.models.messages :as messages] [status-im.constants :refer [text-content-type content-type-command - content-type-command-request]] + content-type-command-request + default-number-of-messages]] [status-im.utils.random :as random] [status-im.chat.sign-up :as sign-up-service] [status-im.models.chats :as chats] @@ -28,12 +29,17 @@ (assoc db :show-actions show-actions))) (register-handler :load-more-messages - debug (fn [{:keys [current-chat-id] :as db} _] - (let [messages-path [:chats current-chat-id :messages] - messages (get-in db messages-path) - new-messages (messages/get-messages current-chat-id (count messages))] - (update-in db messages-path concat new-messages)))) + (let [all-loaded? (get-in db [:chats current-chat-id :all-loaded?])] + (if all-loaded? + db + (let [messages-path [:chats current-chat-id :messages] + messages (get-in db messages-path) + new-messages (messages/get-messages current-chat-id (count messages)) + all-loaded? (> default-number-of-messages (count new-messages))] + (-> db + (update-in messages-path concat new-messages) + (assoc-in [:chats current-chat-id :all-loaded?] all-loaded?))))))) (defn safe-trim [s] (when (string? s) diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index b7b26589fe..ccecdc86e5 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -1,7 +1,6 @@ (ns status-im.commands.handlers.loading (:require-macros [status-im.utils.slurp :refer [slurp]]) - (:require [re-frame.core :refer [register-handler after dispatch subscribe - trim-v debug]] + (:require [re-frame.core :refer [after dispatch subscribe trim-v debug]] [status-im.utils.handlers :as u] [status-im.utils.utils :refer [http-get toast]] [clojure.string :as s] diff --git a/src/status_im/commands/utils.cljs b/src/status_im/commands/utils.cljs index ca03a910cf..af728dabad 100644 --- a/src/status_im/commands/utils.cljs +++ b/src/status_im/commands/utils.cljs @@ -3,7 +3,7 @@ [clojure.walk :as w] [status-im.components.react :refer [text scroll-view view image touchable-highlight]] - [re-frame.core :refer [register-handler dispatch trim-v debug]] + [re-frame.core :refer [dispatch trim-v debug]] [status-im.utils.handlers :refer [register-handler]])) (defn json->clj [json] diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index d01788d834..41460b6cc9 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -16,4 +16,4 @@ (def response-input-hiding-duration 100) (def response-suggesstion-resize-duration 100) -(def default-number-of-messages 20) +(def default-number-of-messages 5) diff --git a/src/status_im/contacts/handlers.cljs b/src/status_im/contacts/handlers.cljs index 2e0cdc73a6..f61bed64d5 100644 --- a/src/status_im/contacts/handlers.cljs +++ b/src/status_im/contacts/handlers.cljs @@ -1,5 +1,6 @@ (ns status-im.contacts.handlers - (:require [re-frame.core :refer [register-handler after dispatch]] + (:require [re-frame.core :refer [after dispatch]] + [status-im.utils.handlers :refer [register-handler]] [status-im.models.contacts :as contacts] [status-im.utils.crypt :refer [encrypt]] [clojure.string :as s] diff --git a/src/status_im/discovery/handlers.cljs b/src/status_im/discovery/handlers.cljs index 2b227acefa..2f062260bc 100644 --- a/src/status_im/discovery/handlers.cljs +++ b/src/status_im/discovery/handlers.cljs @@ -1,5 +1,6 @@ (ns status-im.discovery.handlers - (:require [re-frame.core :refer [register-handler after dispatch enrich]] + (:require [re-frame.core :refer [after dispatch enrich]] + [status-im.utils.handlers :refer [register-handler]] [status-im.protocol.api :as api] [status-im.navigation.handlers :as nav] [status-im.discovery.model :as discoveries] diff --git a/src/status_im/group_settings/handlers.cljs b/src/status_im/group_settings/handlers.cljs index 82eab18d7b..6f5e94d558 100644 --- a/src/status_im/group_settings/handlers.cljs +++ b/src/status_im/group_settings/handlers.cljs @@ -1,6 +1,6 @@ (ns status-im.group-settings.handlers - (:require [re-frame.core :refer [register-handler debug dispatch after - enrich]] + (:require [re-frame.core :refer [debug dispatch after enrich]] + [status-im.utils.handlers :refer [register-handler]] [status-im.persistence.realm :as r] [status-im.chat.handlers :refer [delete-messages!]] [status-im.protocol.api :as api] diff --git a/src/status_im/models/messages.cljs b/src/status_im/models/messages.cljs index c010719ab1..38d7342ae3 100644 --- a/src/status_im/models/messages.cljs +++ b/src/status_im/models/messages.cljs @@ -56,7 +56,7 @@ (r/collection->map)) (into '()) reverse - (map (fn [{:keys [content-type] :as message}] + (keep (fn [{:keys [content-type] :as message}] (if (command-type? content-type) (update message :content str-to-map) message)))))) diff --git a/src/status_im/navigation/handlers.cljs b/src/status_im/navigation/handlers.cljs index cf73ae6434..db33411902 100644 --- a/src/status_im/navigation/handlers.cljs +++ b/src/status_im/navigation/handlers.cljs @@ -1,5 +1,6 @@ (ns status-im.navigation.handlers - (:require [re-frame.core :refer [register-handler dispatch debug enrich after]])) + (:require [re-frame.core :refer [dispatch debug enrich after]] + [status-im.utils.handlers :refer [register-handler]])) (defn push-view [db view-id] (-> db diff --git a/src/status_im/new_group/handlers.cljs b/src/status_im/new_group/handlers.cljs index 0c34111405..3cba0c3db0 100644 --- a/src/status_im/new_group/handlers.cljs +++ b/src/status_im/new_group/handlers.cljs @@ -1,6 +1,7 @@ (ns status-im.new-group.handlers (:require [status-im.protocol.api :as api] - [re-frame.core :refer [register-handler after dispatch debug enrich]] + [re-frame.core :refer [after dispatch debug enrich]] + [status-im.utils.handlers :refer [register-handler]] [status-im.components.styles :refer [default-chat-color]] [status-im.models.chats :as chats] [clojure.string :as s])) diff --git a/src/status_im/participants/handlers.cljs b/src/status_im/participants/handlers.cljs index fe0e5581c0..a6fb532355 100644 --- a/src/status_im/participants/handlers.cljs +++ b/src/status_im/participants/handlers.cljs @@ -1,6 +1,7 @@ (ns status-im.participants.handlers (:require [status-im.navigation.handlers :as nav] - [re-frame.core :refer [register-handler debug]])) + [re-frame.core :refer [debug]] + [status-im.utils.handlers :refer [register-handler]])) (defmethod nav/preload-data! :add-participants [db _] diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index a9b94e5541..e6e8c8699c 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -4,7 +4,8 @@ (:require [status-im.utils.handlers :as u] [status-im.utils.logging :as log] [status-im.protocol.api :as api] - [re-frame.core :refer [register-handler dispatch debug]] + [re-frame.core :refer [dispatch debug]] + [status-im.utils.handlers :refer [register-handler]] [status-im.models.contacts :as contacts] [status-im.protocol.api :refer [init-protocol]] [status-im.protocol.protocol-handler :refer [make-handler]] diff --git a/src/status_im/qr_scanner/handlers.cljs b/src/status_im/qr_scanner/handlers.cljs index be05d7fb65..8827ea847a 100644 --- a/src/status_im/qr_scanner/handlers.cljs +++ b/src/status_im/qr_scanner/handlers.cljs @@ -1,5 +1,6 @@ (ns status-im.qr-scanner.handlers - (:require [re-frame.core :refer [register-handler after dispatch debug enrich]] + (:require [re-frame.core :refer [after dispatch debug enrich]] + [status-im.utils.handlers :refer [register-handler]] [status-im.navigation.handlers :as nav] [status-im.utils.handlers :as u])) From 7e13ef021066cf002889a088b0ed18e3d9dff57c Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 17:24:07 +0300 Subject: [PATCH 26/27] comment debug Former-commit-id: c97fdbe8c5bcf0fb319af0a7ceec984b58c9a347 --- src/status_im/utils/handlers.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/status_im/utils/handlers.cljs b/src/status_im/utils/handlers.cljs index 4d2777e335..083196375e 100644 --- a/src/status_im/utils/handlers.cljs +++ b/src/status_im/utils/handlers.cljs @@ -11,4 +11,4 @@ (defn register-handler ([name handler] (register-handler name nil handler)) ([name middleware handler] - (re-core/register-handler name [debug middleware] handler))) + (re-core/register-handler name [#_debug middleware] handler))) From f833fd12c31f19d54f8b185065e2ee7dbb30bd0c Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 17:47:12 +0300 Subject: [PATCH 27/27] fix suggestions flickering Former-commit-id: 3e7bd39ed3856b95312ef9268bf7d022ae30b03a --- src/status_im/chat/views/suggestions.cljs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index c28b8770ec..457c441083 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -119,8 +119,10 @@ (into [animated-view {:style (st/container h)}] elements))}))) (defn suggestion-container [] - (let [h (anim/create-value 0.1)] - [container h - [header h] - [suggestions-view] - [view {:height c/input-height}]])) + (let [h (anim/create-value 0.1) + command? (subscribe [:command?])] + (when-not @command? + [container h + [header h] + [suggestions-view] + [view {:height c/input-height}]])))