|
1 | 1 | (ns braid.client.mobile.core |
2 | 2 | (:require [reagent.core :as r] |
3 | | - [re-frame.core :refer [subscribe dispatch]] |
4 | | - [braid.client.mobile.state] |
5 | | - [braid.client.mobile.style :refer [styles]] |
6 | | - [braid.client.ui.views.sidebar] |
7 | | - [retouch.core :refer [drawer-view swipe-view]])) |
| 3 | + [braid.client.mobile.views :refer [app-view]] |
| 4 | + [braid.client.router :as router] |
| 5 | + [braid.client.routes :as routes] |
| 6 | + [re-frame.core :as rf :refer [dispatch-sync dispatch]] |
| 7 | + [braid.client.state.remote-handlers] |
| 8 | + braid.client.uploads.subs |
| 9 | + braid.client.uploads.events |
| 10 | + braid.client.core.subs |
| 11 | + braid.client.core.events)) |
8 | 12 |
|
9 | 13 | (enable-console-print!) |
10 | 14 |
|
11 | | -(defn message-view [message] |
12 | | - [:div.message |
13 | | - [:a.avatar |
14 | | - [:img]] |
15 | | - [:div.info |
16 | | - [:div.nickname "username"] |
17 | | - [:div.time "4:35 PM"]] |
18 | | - [:div.content (:content message)]]) |
| 15 | +(defn render [] |
| 16 | + (r/render [app-view] (. js/document (getElementById "app")))) |
19 | 17 |
|
20 | | -(defn new-message-view [] |
21 | | - (fn [] |
22 | | - [:div.new.message |
23 | | - [:textarea {:value "asd" |
24 | | - :on-change (fn [e])}]])) |
| 18 | +(defn ^:export init [] |
| 19 | + (dispatch-sync [:initialize-db]) |
| 20 | + (render) |
| 21 | + (router/init) |
| 22 | + (dispatch [:check-auth])) |
25 | 23 |
|
26 | | -(defn tag-view [tag-id] |
27 | | - (let [tag (subscribe [:get-tag tag-id])] |
28 | | - [:div.tag (@tag :name)])) |
29 | | - |
30 | | -(defn thread-view [thread] |
31 | | - [:div.thread |
32 | | - [:div.card |
33 | | - [:div.head |
34 | | - [:div.tags |
35 | | - (doall |
36 | | - (for [tag-id (thread :tag-ids)] |
37 | | - ^{:key tag-id} |
38 | | - [tag-view tag-id])) |
39 | | - [:a.add "+"]] |
40 | | - [:div.close "×"]]] |
41 | | - [:div.messages |
42 | | - (doall |
43 | | - (for [message (:messages thread)] |
44 | | - ^{:key (message :id)} |
45 | | - [message-view message]))] |
46 | | - [new-message-view] ]) |
47 | | - |
48 | | -(defn inbox-view [] |
49 | | - (let [threads (subscribe [:active-group-inbox-threads])] |
50 | | - (fn [] |
51 | | - [:div.inbox.page |
52 | | - [:div.threads |
53 | | - [swipe-view @threads thread-view]]]))) |
54 | | - |
55 | | -(defn main-view [] |
56 | | - [:div.main |
57 | | - [drawer-view |
58 | | - [:div.sidebar |
59 | | - [braid.client.ui.views.sidebar/groups-view {:subscribe subscribe}]]] |
60 | | - [inbox-view]]) |
61 | | - |
62 | | -(defn login-flow-view [] |
63 | | - (let [data (r/atom {})] |
64 | | - (fn [] |
65 | | - [:div.login-flow |
66 | | - (if-not (@data :method) |
67 | | - [:div.content.welcome |
68 | | - [:img.logo {:src "/images/braid.svg"}] |
69 | | - [:button.login |
70 | | - {:on-click (fn [_] |
71 | | - (swap! data assoc :method :login))} |
72 | | - "Log In"] |
73 | | - [:button.register |
74 | | - {:on-click (fn [_] |
75 | | - (swap! data assoc :method :register))} |
76 | | - "Register"]] |
77 | | - (case (@data :method) |
78 | | - :login |
79 | | - (if-not (@data :email) |
80 | | - [:div.content.login.email |
81 | | - "Email" |
82 | | - [ :input.email { :placeholder "[email protected]" |
83 | | - :type "email" |
84 | | - :key "email"}] |
85 | | - [:button.next {:on-click (fn [e] |
86 | | - (swap! data assoc :email (.. e -target -value)))}]] |
87 | | - [:div.content.login.password |
88 | | - "Password" |
89 | | - [:input.password {:placeholder "••••••" |
90 | | - :type "password" |
91 | | - :key "password"}] |
92 | | - [:button.next {:on-click (fn [e] |
93 | | - (swap! data assoc :email (.. e -target -value)) |
94 | | - (dispatch [:log-in!]))}]]) |
95 | | - :register |
96 | | - (if-not (@data :email) |
97 | | - [:div.content.register.email |
98 | | - [ :input.email { :placeholder "[email protected]"}] |
99 | | - [:button.next {:on-click (fn [e] |
100 | | - (swap! data assoc :email (.. e -target -value)) |
101 | | - (dispatch [:log-in!]))}]])))]))) |
102 | | - |
103 | | -(defn style-view [] |
104 | | - [:style {:type "text/css" |
105 | | - :dangerouslySetInnerHTML {:__html styles}}]) |
106 | | - |
107 | | -(defn app-view [] |
108 | | - (let [logged-in? (subscribe [:logged-in?])] |
109 | | - (fn [] |
110 | | - [:div.app |
111 | | - [style-view] |
112 | | - (if @logged-in? |
113 | | - [main-view] |
114 | | - [login-flow-view])]))) |
115 | | - |
116 | | -(defn init [] |
117 | | - (r/render [app-view] (.-body js/document))) |
118 | | - |
119 | | -(init) |
| 24 | +(defn ^:export reload [] |
| 25 | + (render)) |
0 commit comments