2016-05-19 18:31:56 +02:00
|
|
|
(ns status-im.ios.core
|
2016-03-23 16:48:26 +02:00
|
|
|
(:require [reagent.core :as r :refer [atom]]
|
2016-07-22 11:53:12 +03:00
|
|
|
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
|
|
|
[status-im.handlers]
|
|
|
|
[status-im.subs]
|
|
|
|
[status-im.components.react :refer [app-registry
|
|
|
|
keyboard
|
2016-09-15 15:33:19 +03:00
|
|
|
orientation]]
|
2016-07-22 11:53:12 +03:00
|
|
|
[status-im.components.main-tabs :refer [main-tabs]]
|
|
|
|
[status-im.contacts.views.contact-list :refer [contact-list]]
|
|
|
|
[status-im.contacts.views.new-contact :refer [new-contact]]
|
|
|
|
[status-im.qr-scanner.screen :refer [qr-scanner]]
|
|
|
|
[status-im.discovery.tag :refer [discovery-tag]]
|
2016-08-19 16:14:59 +03:00
|
|
|
[status-im.discovery.search-results :refer [discovery-search-results]]
|
2016-07-22 11:53:12 +03:00
|
|
|
[status-im.chat.screen :refer [chat]]
|
|
|
|
[status-im.accounts.login.screen :refer [login]]
|
|
|
|
[status-im.accounts.screen :refer [accounts]]
|
|
|
|
[status-im.chats-list.screen :refer [chats-list]]
|
|
|
|
[status-im.new-group.screen :refer [new-group]]
|
|
|
|
[status-im.participants.views.add :refer [new-participants]]
|
|
|
|
[status-im.participants.views.remove :refer [remove-participants]]
|
|
|
|
[status-im.group-settings.screen :refer [group-settings]]
|
|
|
|
[status-im.profile.screen :refer [profile my-profile]]
|
2016-08-01 13:29:10 +03:00
|
|
|
[status-im.profile.photo-capture.screen :refer [profile-photo-capture]]
|
2016-07-22 11:53:12 +03:00
|
|
|
[status-im.utils.utils :refer [toast]]
|
|
|
|
status-im.persistence.realm.core
|
2016-09-17 15:35:01 +03:00
|
|
|
[taoensso.timbre :as log]))
|
2016-03-23 16:48:26 +02:00
|
|
|
|
2016-07-22 11:53:12 +03:00
|
|
|
(defn orientation->keyword [o]
|
|
|
|
(keyword (.toLowerCase o)))
|
2016-03-23 16:48:26 +02:00
|
|
|
|
|
|
|
(defn app-root []
|
2016-09-17 15:35:01 +03:00
|
|
|
(let [signed-up (subscribe [:signed-up?])
|
2016-07-22 11:53:12 +03:00
|
|
|
_ (log/debug "signed up: " @signed-up)
|
|
|
|
view-id (subscribe [:get :view-id])
|
2016-08-01 13:29:10 +03:00
|
|
|
account-id (subscribe [:get :current-account-id])
|
2016-07-22 11:53:12 +03:00
|
|
|
keyboard-height (subscribe [:get :keyboard-height])]
|
2016-08-01 13:29:10 +03:00
|
|
|
(log/debug "Current account: " @account-id)
|
2016-07-22 11:53:12 +03:00
|
|
|
(r/create-class
|
|
|
|
{:component-will-mount
|
|
|
|
(fn []
|
|
|
|
(let [o (orientation->keyword (.getInitialOrientation orientation))]
|
|
|
|
(dispatch [:set :orientation o]))
|
|
|
|
(.addOrientationListener
|
|
|
|
orientation
|
|
|
|
#(dispatch [:set :orientation (orientation->keyword %)]))
|
|
|
|
(.lockToPortrait orientation)
|
|
|
|
(.addListener keyboard
|
|
|
|
"keyboardDidShow"
|
|
|
|
(fn [e]
|
|
|
|
(let [h (.. e -endCoordinates -height)]
|
|
|
|
(when-not (= h @keyboard-height)
|
|
|
|
(dispatch [:set :keyboard-height h])))))
|
|
|
|
(.addListener keyboard
|
|
|
|
"keyboardDidHide"
|
|
|
|
(when-not (= 0 @keyboard-height)
|
|
|
|
#(dispatch [:set :keyboard-height 0]))))
|
|
|
|
:render
|
|
|
|
(fn []
|
2016-08-01 13:29:10 +03:00
|
|
|
(let [startup-view (if @account-id
|
2016-07-22 11:53:12 +03:00
|
|
|
(if @signed-up
|
|
|
|
@view-id
|
|
|
|
:chat)
|
|
|
|
(if (contains? #{:login :chat} @view-id)
|
|
|
|
@view-id
|
|
|
|
:accounts))]
|
|
|
|
(log/debug startup-view)
|
|
|
|
(let [component (case (if true startup-view :chat)
|
|
|
|
:discovery main-tabs
|
|
|
|
:discovery-tag discovery-tag
|
2016-08-19 16:14:59 +03:00
|
|
|
:discovery-search-results discovery-search-results
|
2016-07-22 11:53:12 +03:00
|
|
|
:add-participants new-participants
|
|
|
|
:remove-participants remove-participants
|
|
|
|
:chat-list main-tabs
|
|
|
|
:new-group new-group
|
|
|
|
:group-settings group-settings
|
|
|
|
:contact-list main-tabs
|
|
|
|
:group-contacts contact-list
|
|
|
|
:new-contact new-contact
|
|
|
|
:qr-scanner qr-scanner
|
|
|
|
:chat chat
|
|
|
|
:profile profile
|
2016-08-01 13:29:10 +03:00
|
|
|
:profile-photo-capture profile-photo-capture
|
2016-07-22 11:53:12 +03:00
|
|
|
:accounts accounts
|
|
|
|
:login login
|
|
|
|
:my-profile my-profile)]
|
2016-09-15 15:33:19 +03:00
|
|
|
[component])))})))
|
2016-03-23 16:48:26 +02:00
|
|
|
|
|
|
|
(defn init []
|
2016-07-22 11:53:12 +03:00
|
|
|
(dispatch-sync [:reset-app])
|
|
|
|
(dispatch [:initialize-crypt])
|
|
|
|
(dispatch [:initialize-geth])
|
|
|
|
(dispatch [:load-user-phone-number])
|
|
|
|
(.registerComponent app-registry "StatusIm" #(r/reactify-component app-root)))
|