more navigation handlers
This commit is contained in:
parent
f429a15be8
commit
38161d9e10
|
@ -112,8 +112,7 @@
|
|||
(defn text-message
|
||||
[{:keys [content] :as message}]
|
||||
[message-view message
|
||||
[text {:style (st/text-message message)}
|
||||
content]])
|
||||
[text {:style (st/text-message message)} content]])
|
||||
|
||||
(defmethod message-content text-content-type
|
||||
[wrapper message]
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
(defn chat-list-item [chat-obj navigator]
|
||||
[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 should chat-obj be clj-map?
|
||||
[view {} [chat-list-item-inner-view (merge (js->clj chat-obj :keywordize-keys true)
|
||||
|
|
|
@ -61,8 +61,7 @@
|
|||
:color "white"}}]]
|
||||
[action-button-item {:title "New Group Chat"
|
||||
:buttonColor "#1abc9c"
|
||||
:onPress (fn []
|
||||
(dispatch [:show-group-new navigator]))}
|
||||
:onPress #(dispatch [:show-group-new])}
|
||||
[icon {:name "person-stalker"
|
||||
:style {:fontSize 20
|
||||
:height 22
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
current-chat-id
|
||||
update-new-group-selection
|
||||
update-new-participants-selection
|
||||
clear-new-group
|
||||
clear-new-participants
|
||||
new-group-selection
|
||||
set-chat-input-text
|
||||
|
@ -117,18 +116,6 @@
|
|||
(update-identity identity)
|
||||
(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]
|
||||
{:from "system"
|
||||
:msg-id msg-id
|
||||
|
@ -267,29 +254,11 @@
|
|||
|
||||
;; -- 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
|
||||
(fn [db [action identity add?]]
|
||||
(log/debug action 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
|
||||
(fn [db [action navigator]]
|
||||
(log/debug action)
|
||||
|
@ -302,12 +271,6 @@
|
|||
(removed-participant-msg chat-id ident))
|
||||
(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
|
||||
(fn [db [action navigator]]
|
||||
(log/debug action)
|
||||
|
@ -319,12 +282,6 @@
|
|||
(api/group-add-participant chat-id ident))
|
||||
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
|
||||
(fn [db [action identity add?]]
|
||||
(log/debug action identity add?)
|
||||
|
@ -336,7 +293,7 @@
|
|||
(let [identities (vec (new-group-selection db))
|
||||
group-id (api/start-group-chat identities 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)))
|
||||
|
||||
(register-handler :group-chat-invite-received
|
||||
|
|
|
@ -1,11 +1,30 @@
|
|||
(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
|
||||
(fn [db [_ view-id]]
|
||||
(-> db
|
||||
(assoc :view-id view-id)
|
||||
(update :navigation-stack conj view-id))))
|
||||
(push-view db view-id)))
|
||||
|
||||
(register-handler :navigation-replace
|
||||
(fn [db [_ view-id]]
|
||||
(replace-view db view-id)))
|
||||
|
||||
(register-handler :navigate-back
|
||||
(fn [{:keys [navigation-stack] :as db} _]
|
||||
|
@ -15,3 +34,32 @@
|
|||
(-> db
|
||||
(assoc :view-id view-id)
|
||||
(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)))
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
(:require-macros [reagent.ratom :refer [reaction]])
|
||||
(:require [re-frame.core :refer [register-sub]]))
|
||||
|
||||
(register-sub :view-id
|
||||
(fn [db _]
|
||||
(reaction (@db :view-id))))
|
||||
|
||||
(register-sub :navigation-stack
|
||||
(fn [db _]
|
||||
(reaction (:navigation-stack @db))))
|
||||
|
|
|
@ -78,10 +78,6 @@
|
|||
(map :identity))]
|
||||
(contacts-list-include current-participants)))))))
|
||||
|
||||
(register-sub :view-id
|
||||
(fn [db _]
|
||||
(reaction (@db :view-id))))
|
||||
|
||||
(register-sub :db
|
||||
(fn [db _] (reaction @db)))
|
||||
|
||||
|
|
Loading…
Reference in New Issue