From 496800642cf479cff9e19aeb56c084955687657c Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Thu, 8 Sep 2016 18:12:08 +0300 Subject: [PATCH] fix new chat navigation history --- src/status_im/accounts/login/handlers.cljs | 6 +-- .../chat/handlers/webview_bridge.cljs | 2 +- src/status_im/chats_list/screen.cljs | 4 +- src/status_im/components/drawer/view.cljs | 2 +- src/status_im/contacts/handlers.cljs | 18 ++++++++- src/status_im/contacts/screen.cljs | 10 +++-- src/status_im/navigation/handlers.cljs | 38 +++++++------------ 7 files changed, 43 insertions(+), 37 deletions(-) diff --git a/src/status_im/accounts/login/handlers.cljs b/src/status_im/accounts/login/handlers.cljs index 66f8f0902a..38cf1ae0ff 100644 --- a/src/status_im/accounts/login/handlers.cljs +++ b/src/status_im/accounts/login/handlers.cljs @@ -1,6 +1,6 @@ (ns status-im.accounts.login.handlers - (:require [re-frame.core :refer [register-handler after dispatch]] - [status-im.utils.handlers :as u] + (:require [re-frame.core :refer [after dispatch]] + [status-im.utils.handlers :refer [register-handler] :as u] [status-im.utils.logging :as log] [status-im.utils.types :refer [json->clj]] [status-im.db :refer [default-view]] @@ -56,4 +56,4 @@ (log/debug "Logged in account: ") (if success (logged-in db address) - (dispatch [:set-in [:login :error] error])))))))) \ No newline at end of file + (dispatch [:set-in [:login :error] error])))))))) diff --git a/src/status_im/chat/handlers/webview_bridge.cljs b/src/status_im/chat/handlers/webview_bridge.cljs index 7682d4c042..afeec2c8a4 100644 --- a/src/status_im/chat/handlers/webview_bridge.cljs +++ b/src/status_im/chat/handlers/webview_bridge.cljs @@ -29,7 +29,7 @@ event (keyword (:event message))] (log/debug (str "message from webview: " message)) (case event - :webview-send-transaction (dispatch [:show-contacts contacts-click-handler]) + :webview-send-transaction (dispatch [:navigate-to :contact-list contacts-click-handler]) (log/error (str "Unknown event: " event))))))) (register-handler :send-to-webview-bridge diff --git a/src/status_im/chats_list/screen.cljs b/src/status_im/chats_list/screen.cljs index 8e88570395..b65da803d5 100644 --- a/src/status_im/chats_list/screen.cljs +++ b/src/status_im/chats_list/screen.cljs @@ -60,13 +60,13 @@ [action-button-item {:title (label :t/new-chat) :buttonColor :#9b59b6 - :onPress #(dispatch [:show-group-contacts :people])} + :onPress #(dispatch [:navigate-forget :group-contacts :people])} [ion-icon {:name :md-create :style st/create-icon}]] [action-button-item {:title (label :t/new-group-chat) :buttonColor :#1abc9c - :onPress #(dispatch [:show-group-new])} + :onPress #(dispatch [:navigate-to :new-group])} [ion-icon {:name :md-person :style st/person-stalker-icon}]]]] [bottom-gradient]]) diff --git a/src/status_im/components/drawer/view.cljs b/src/status_im/components/drawer/view.cljs index 43e56a6eb1..d672a6a853 100644 --- a/src/status_im/components/drawer/view.cljs +++ b/src/status_im/components/drawer/view.cljs @@ -63,7 +63,7 @@ :handler #(dispatch [:navigate-to :discovery]) :platform-specific platform-specific}] [menu-item {:name (label :t/contacts) - :handler #(dispatch [:show-contacts]) + :handler #(dispatch [:navigate-to :contact-list]) :platform-specific platform-specific}] [menu-item {:name (label :t/invite-friends) :handler (fn [] diff --git a/src/status_im/contacts/handlers.cljs b/src/status_im/contacts/handlers.cljs index 16e8e3a4dc..c992fa00fe 100644 --- a/src/status_im/contacts/handlers.cljs +++ b/src/status_im/contacts/handlers.cljs @@ -9,7 +9,23 @@ [status-im.utils.phone-number :refer [format-phone-number]] [status-im.utils.handlers :as u] [status-im.utils.utils :refer [require]] - [status-im.utils.logging :as log])) + [status-im.utils.logging :as log] + [status-im.navigation.handlers :as nav])) + + +(defmethod nav/preload-data! :group-contacts + [db [_ _ group]] + (assoc db :contacts-group group)) + +(defmethod nav/preload-data! :new-group + [db _] + (-> db + (assoc :new-group #{}) + (assoc :new-chat-name nil))) + +(defmethod nav/preload-data! :contact-list + [db [_ _ click-handler]] + (assoc db :contacts-click-handler click-handler)) (defn save-contact [_ [_ contact]] diff --git a/src/status_im/contacts/screen.cljs b/src/status_im/contacts/screen.cljs index b35963b2d6..8fb579cdde 100644 --- a/src/status_im/contacts/screen.cljs +++ b/src/status_im/contacts/screen.cljs @@ -2,7 +2,8 @@ (:require-macros [status-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] [reagent.core :as r] - [status-im.components.react :refer [view text + [status-im.components.react :refer [view + text image touchable-highlight linear-gradient @@ -63,10 +64,11 @@ ^{:key contact} [contact-extended-view contact nil (click-handler whisper-identity) nil])) contacts))] - (when (= contacts-limit (count contacts)) + (when (<= contacts-limit (count contacts)) [view st/show-all - [touchable-highlight {:on-press #(dispatch [:show-group-contacts group])} - [text {:style st/show-all-text} (label :show-all)]]])]) + [touchable-highlight {:on-press #(dispatch [:navigate-to :group-contacts group])} + [view + [text {:style st/show-all-text} (label :t/show-all)]]]])]) (defn contact-list [{platform-specific :platform-specific}] (let [contacts (subscribe [:get-added-contacts-with-limit contacts-limit]) diff --git a/src/status_im/navigation/handlers.cljs b/src/status_im/navigation/handlers.cljs index 67b3111b3f..73a9717b75 100644 --- a/src/status_im/navigation/handlers.cljs +++ b/src/status_im/navigation/handlers.cljs @@ -23,6 +23,11 @@ (defmethod preload-data! :default [db _] db) +(register-handler :navigate-forget + (enrich preload-data!) + (fn [db [_ new-view-id]] + (assoc db :view-id new-view-id))) + (register-handler :navigate-to (enrich preload-data!) (fn [{:keys [view-id] :as db} [_ new-view-id]] @@ -37,13 +42,16 @@ (register-handler :navigate-back (enrich preload-data!) - (fn [{:keys [navigation-stack] :as db} _] + (fn [{:keys [navigation-stack view-id] :as db} _] (if (>= 1 (count navigation-stack)) db - (let [[view-id :as navigation-stack'] (pop navigation-stack)] - (-> db - (assoc :view-id view-id) - (assoc :navigation-stack navigation-stack')))))) + (let [[previous-view-id :as navigation-stack'] (pop navigation-stack) + first-in-stack (first navigation-stack)] + (if (= view-id first-in-stack) + (-> db + (assoc :view-id previous-view-id) + (assoc :navigation-stack navigation-stack')) + (assoc db :view-id first-in-stack)))))) (register-handler :navigate-to-tab (enrich preload-data!) @@ -57,30 +65,10 @@ (fn [db [_]] (assoc db :prev-tab-view-id nil))) -(register-handler :show-group-new - (debug - (fn [db _] - (-> db - (push-view :new-group) - (assoc :new-group #{}) - (assoc :new-chat-name nil))))) - -(register-handler :show-contacts - (fn [db [_ click-handler]] - (-> db - (assoc :contacts-click-handler click-handler) - (push-view :contact-list)))) - (register-handler :remove-contacts-click-handler (fn [db] (dissoc db :contacts-click-handler))) -(register-handler :show-group-contacts - (fn [db [_ group]] - (-> db - (assoc :contacts-group group) - (push-view :group-contacts)))) - (defn show-profile [db [_ identity]] (-> db