Sitelet https://github.com/braidchat/braid/pull/85/files
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
:pretty-print false}}

{:id "mobile-dev"
:figwheel true
:figwheel {:on-jsload "braid.client.mobile.core/reload"}
:source-paths ["src/braid/client"
"src/retouch"]
:compiler {:main braid.client.mobile.core
Expand Down
2 changes: 1 addition & 1 deletion resources/public/mobile.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<script>
window.checksum = "{{js}}";
window.api_domain = "{{api_domain}}";
braid.mobile.core.init();
braid.client.mobile.core.init();
</script>
</body>
</html>
Expand Down
25 changes: 18 additions & 7 deletions src/braid/client/core/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[braid.client.schema :as schema]
[braid.common.util :as util]
[braid.client.router :as router]
[braid.client.routes :as routes]
[braid.client.xhr :refer [edn-xhr]]
[braid.client.state.helpers :as helpers :refer [key-by-id]]
[braid.client.quests.helpers :as quest-helpers]))
Expand Down Expand Up @@ -441,7 +442,8 @@
(reg-event-fx
:remove-from-group
(fn [cofx [ _ {:keys [group-id user-id] :as args}]]
{:websocket-send (list [:braid.server/remove-from-group args])}))
{:websocket-send (list [:braid.server/remove-from-group args])
:dispatch [:redirect-to-first-group]}))

(reg-event-fx
:check-auth
Expand Down Expand Up @@ -506,12 +508,21 @@
(dispatch [:set-login-state :login-form])
(dispatch [:clear-session]))}}))

(reg-event-db
(reg-event-fx
:set-group-and-page
(fn [state [_ [group-id page-id]]]
(fn [{state :db :as cofx} [_ [group-id page-id]]]
(if (or (nil? group-id) (some? (get-in state [:groups group-id])))
(assoc state :open-group-id group-id :page page-id)
(assoc state :open-group-id nil :page {:type :index}))))
{:db (assoc state :open-group-id group-id :page page-id)}
{:dispatch [:redirect-to-first-group]})))

(reg-event-fx
:redirect-to-first-group
(fn [{state :db :as cofx} _]
{:redirect-to
(when-let [group-id (-> (helpers/ordered-groups state)
first
:id)]
(routes/inbox-page-path {:group-id group-id}))}))

(reg-event-db
:set-page-loading
Expand Down Expand Up @@ -594,8 +605,8 @@
{:groups-order (into [] (remove (partial = group-id))
sidebar-order)})
state))))
:redirect-to (when (= group-id (state :open-group-id))
"/")}))
:dispatch [(when (= group-id (state :open-group-id))
:redirect-to-first-group)]}))

(reg-event-db
:add-open-thread
Expand Down
3 changes: 1 addition & 2 deletions src/braid/client/group_admin/views/group_settings_page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
(when (js/confirm "Are you sure you want to leave this group?")
(dispatch [:remove-from-group
{:group-id (group :id)
:user-id @user-id}])
(routes/go-to! (routes/index-path))))}
:user-id @user-id}])))}
"Leave this group"])))

(defn intro-message-view
Expand Down
130 changes: 18 additions & 112 deletions src/braid/client/mobile/core.cljs
Original file line number Diff line number Diff line change
@@ -1,119 +1,25 @@
(ns braid.client.mobile.core
(:require [reagent.core :as r]
[re-frame.core :refer [subscribe dispatch]]
[braid.client.mobile.state]
[braid.client.mobile.style :refer [styles]]
[braid.client.ui.views.sidebar]
[retouch.core :refer [drawer-view swipe-view]]))
[braid.client.mobile.views :refer [app-view]]
[braid.client.router :as router]
[braid.client.routes :as routes]
[re-frame.core :as rf :refer [dispatch-sync dispatch]]
[braid.client.state.remote-handlers]
braid.client.uploads.subs
braid.client.uploads.events
braid.client.core.subs
braid.client.core.events))

(enable-console-print!)

(defn message-view [message]
[:div.message
[:a.avatar
[:img]]
[:div.info
[:div.nickname "username"]
[:div.time "4:35 PM"]]
[:div.content (:content message)]])
(defn render []
(r/render [app-view] (. js/document (getElementById "app"))))

(defn new-message-view []
(fn []
[:div.new.message
[:textarea {:value "asd"
:on-change (fn [e])}]]))
(defn ^:export init []
(dispatch-sync [:initialize-db])
(render)
(router/init)
(dispatch [:check-auth]))

(defn tag-view [tag-id]
(let [tag (subscribe [:get-tag tag-id])]
[:div.tag (@tag :name)]))

(defn thread-view [thread]
[:div.thread
[:div.card
[:div.head
[:div.tags
(doall
(for [tag-id (thread :tag-ids)]
^{:key tag-id}
[tag-view tag-id]))
[:a.add "+"]]
[:div.close "×"]]]
[:div.messages
(doall
(for [message (:messages thread)]
^{:key (message :id)}
[message-view message]))]
[new-message-view] ])

(defn inbox-view []
(let [threads (subscribe [:active-group-inbox-threads])]
(fn []
[:div.inbox.page
[:div.threads
[swipe-view @threads thread-view]]])))

(defn main-view []
[:div.main
[drawer-view
[:div.sidebar
[braid.client.ui.views.sidebar/groups-view {:subscribe subscribe}]]]
[inbox-view]])

(defn login-flow-view []
(let [data (r/atom {})]
(fn []
[:div.login-flow
(if-not (@data :method)
[:div.content.welcome
[:img.logo {:src "/images/braid.svg"}]
[:button.login
{:on-click (fn [_]
(swap! data assoc :method :login))}
"Log In"]
[:button.register
{:on-click (fn [_]
(swap! data assoc :method :register))}
"Register"]]
(case (@data :method)
:login
(if-not (@data :email)
[:div.content.login.email
"Email"
[:input.email {:placeholder "you@awesome.com"
:type "email"
:key "email"}]
[:button.next {:on-click (fn [e]
(swap! data assoc :email (.. e -target -value)))}]]
[:div.content.login.password
"Password"
[:input.password {:placeholder "••••••"
:type "password"
:key "password"}]
[:button.next {:on-click (fn [e]
(swap! data assoc :email (.. e -target -value))
(dispatch [:log-in!]))}]])
:register
(if-not (@data :email)
[:div.content.register.email
[:input.email {:placeholder "you@awesome.com"}]
[:button.next {:on-click (fn [e]
(swap! data assoc :email (.. e -target -value))
(dispatch [:log-in!]))}]])))])))

(defn style-view []
[:style {:type "text/css"
:dangerouslySetInnerHTML {:__html styles}}])

(defn app-view []
(let [logged-in? (subscribe [:logged-in?])]
(fn []
[:div.app
[style-view]
(if @logged-in?
[main-view]
[login-flow-view])])))

(defn init []
(r/render [app-view] (.-body js/document)))

(init)
(defn ^:export reload []
(render))
Loading