more navigation handlers

Former-commit-id: 38161d9e10
This commit is contained in:
Roman Volosovskyi 2016-05-10 15:25:36 +03:00
parent 8a99e2a614
commit 39772b41f7
7 changed files with 60 additions and 57 deletions

View File

@ -112,8 +112,7 @@
(defn text-message (defn text-message
[{:keys [content] :as message}] [{:keys [content] :as message}]
[message-view message [message-view message
[text {:style (st/text-message message)} [text {:style (st/text-message message)} content]])
content]])
(defmethod message-content text-content-type (defmethod message-content text-content-type
[wrapper message] [wrapper message]

View File

@ -11,7 +11,7 @@
(defn chat-list-item [chat-obj navigator] (defn chat-list-item [chat-obj navigator]
[touchable-highlight [touchable-highlight
{:on-press #(dispatch [:show-chat (aget chat-obj "chat-id") navigator :push])} {:on-press #(dispatch [:show-chat (aget chat-obj "chat-id") :push])}
;; TODO add [photo-path delivery-status new-messages-count online] values to chat-obj ;; TODO add [photo-path delivery-status new-messages-count online] values to chat-obj
;; TODO should chat-obj be clj-map? ;; TODO should chat-obj be clj-map?
[view {} [chat-list-item-inner-view (merge (js->clj chat-obj :keywordize-keys true) [view {} [chat-list-item-inner-view (merge (js->clj chat-obj :keywordize-keys true)

View File

@ -61,8 +61,7 @@
:color "white"}}]] :color "white"}}]]
[action-button-item {:title "New Group Chat" [action-button-item {:title "New Group Chat"
:buttonColor "#1abc9c" :buttonColor "#1abc9c"
:onPress (fn [] :onPress #(dispatch [:show-group-new])}
(dispatch [:show-group-new navigator]))}
[icon {:name "person-stalker" [icon {:name "person-stalker"
:style {:fontSize 20 :style {:fontSize 20
:height 22 :height 22

View File

@ -33,7 +33,6 @@
current-chat-id current-chat-id
update-new-group-selection update-new-group-selection
update-new-participants-selection update-new-participants-selection
clear-new-group
clear-new-participants clear-new-participants
new-group-selection new-group-selection
set-chat-input-text set-chat-input-text
@ -117,18 +116,6 @@
(update-identity identity) (update-identity identity)
(set-initialized true)))) (set-initialized true))))
(defn gen-messages [n]
(mapv (fn [_]
(let [id (random-uuid)]
{:msg-id id
:content (str id
"ooops sdfg dsfg"
"s dfg\ndsfg dfg\ndsfgdsfgdsfg")
:content-type text-content-type
:outgoing false
:from "console"
:to "me"})) (range n)))
(defn system-message [msg-id content] (defn system-message [msg-id content]
{:from "system" {:from "system"
:msg-id msg-id :msg-id msg-id
@ -267,29 +254,11 @@
;; -- Chats -------------------------------------------------------------- ;; -- Chats --------------------------------------------------------------
(register-handler :show-chat
(fn [db [action chat-id navigator nav-type]]
(log/debug action "chat-id" chat-id)
(let [db (set-current-chat-id db chat-id)]
(dispatch [:navigate-to navigator {:view-id :chat} nav-type])
db)))
(register-handler :show-contacts
(fn [db [_ navigator]]
(nav-push navigator {:view-id :contact-list})
db))
(register-handler :select-new-participant (register-handler :select-new-participant
(fn [db [action identity add?]] (fn [db [action identity add?]]
(log/debug action identity add?) (log/debug action identity add?)
(update-new-participants-selection db identity add?))) (update-new-participants-selection db identity add?)))
(register-handler :show-remove-participants
(fn [db [action navigator]]
(log/debug action)
(nav-push navigator {:view-id :remove-participants})
(clear-new-participants db)))
(register-handler :remove-selected-participants (register-handler :remove-selected-participants
(fn [db [action navigator]] (fn [db [action navigator]]
(log/debug action) (log/debug action)
@ -302,12 +271,6 @@
(removed-participant-msg chat-id ident)) (removed-participant-msg chat-id ident))
(signal-chat-updated db chat-id)))) (signal-chat-updated db chat-id))))
(register-handler :show-add-participants
(fn [db [action navigator]]
(log/debug action)
(nav-push navigator {:view-id :add-participants})
(clear-new-participants db)))
(register-handler :add-new-participants (register-handler :add-new-participants
(fn [db [action navigator]] (fn [db [action navigator]]
(log/debug action) (log/debug action)
@ -319,12 +282,6 @@
(api/group-add-participant chat-id ident)) (api/group-add-participant chat-id ident))
db))) db)))
(register-handler :show-group-new
(fn [db [action navigator]]
(log/debug action)
(nav-push navigator {:view-id :new-group})
(clear-new-group db)))
(register-handler :select-for-new-group (register-handler :select-for-new-group
(fn [db [action identity add?]] (fn [db [action identity add?]]
(log/debug action identity add?) (log/debug action identity add?)
@ -336,7 +293,7 @@
(let [identities (vec (new-group-selection db)) (let [identities (vec (new-group-selection db))
group-id (api/start-group-chat identities group-name) group-id (api/start-group-chat identities group-name)
db (create-chat db group-id identities true group-name)] db (create-chat db group-id identities true group-name)]
(dispatch [:show-chat group-id navigator :replace]) (dispatch [:show-chat group-id :replace])
db))) db)))
(register-handler :group-chat-invite-received (register-handler :group-chat-invite-received

View File

@ -1,11 +1,30 @@
(ns syng-im.navigation.handlers (ns syng-im.navigation.handlers
(:require [re-frame.core :refer [register-handler]])) (:require [re-frame.core :refer [register-handler dispatch]]
[syng-im.models.chat :as chat]))
(defn push-view [db view-id]
(-> db
(update :navigation-stack conj view-id)
(assoc :view-id view-id)))
(defn replace-top-element [stack view-id]
(let [stack' (if (pos? (count stack))
(pop stack)
stack)]
(conj stack' view-id)))
(defn replace-view [db view-id]
(-> db
(update :navigation-stack replace-top-element view-id)
(assoc :view-id view-id)))
(register-handler :navigate-to (register-handler :navigate-to
(fn [db [_ view-id]] (fn [db [_ view-id]]
(-> db (push-view db view-id)))
(assoc :view-id view-id)
(update :navigation-stack conj view-id)))) (register-handler :navigation-replace
(fn [db [_ view-id]]
(replace-view db view-id)))
(register-handler :navigate-back (register-handler :navigate-back
(fn [{:keys [navigation-stack] :as db} _] (fn [{:keys [navigation-stack] :as db} _]
@ -15,3 +34,32 @@
(-> db (-> db
(assoc :view-id view-id) (assoc :view-id view-id)
(assoc :navigation-stack navigation-stack')))))) (assoc :navigation-stack navigation-stack'))))))
(register-handler :show-group-new
(fn [db _]
(-> db
(push-view :new-group)
chat/clear-new-group)))
(register-handler :show-chat
(fn [db [_ chat-id nav-type]]
(let [update-view-id-fn (if (= :replace nav-type) replace-view push-view)]
(-> db
(update-view-id-fn :chat)
(chat/set-current-chat-id chat-id)))))
(register-handler :show-contacts
(fn [db _]
(push-view db :contact-list)))
(register-handler :show-remove-participants
(fn [db _]
(-> db
(push-view :remove-participants)
chat/clear-new-participants)))
(register-handler :show-add-participants
(fn [db _]
(-> db
(push-view :add-participants)
chat/clear-new-participants)))

View File

@ -2,6 +2,10 @@
(:require-macros [reagent.ratom :refer [reaction]]) (:require-macros [reagent.ratom :refer [reaction]])
(:require [re-frame.core :refer [register-sub]])) (:require [re-frame.core :refer [register-sub]]))
(register-sub :view-id
(fn [db _]
(reaction (@db :view-id))))
(register-sub :navigation-stack (register-sub :navigation-stack
(fn [db _] (fn [db _]
(reaction (:navigation-stack @db)))) (reaction (:navigation-stack @db))))

View File

@ -78,10 +78,6 @@
(map :identity))] (map :identity))]
(contacts-list-include current-participants))))))) (contacts-list-include current-participants)))))))
(register-sub :view-id
(fn [db _]
(reaction (@db :view-id))))
(register-sub :db (register-sub :db
(fn [db _] (reaction @db))) (fn [db _] (reaction @db)))