-
-
Save stuartrexking/89e92a917c36ad75cabc1b80be7d8bdc to your computer and use it in GitHub Desktop.
Help!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defsc IndexComponent [this props] | |
{:query [] | |
:ident (fn [] [:component/id ::index]) | |
:initial-state {} | |
:route-segment ["index"]} | |
"Index") | |
;;unauthenticated | |
(defrouter UnauthenticatedRouter [this {:keys [route-factory route-props]}] | |
{:always-render-body? true | |
:router-targets [IndexComponent] | |
(when route-factory | |
(route-factory route-props))}) | |
(def ui-unauthenticated-router (comp/factory UnauthenticatedRouter)) | |
;authenticated | |
(defsc DashboardRoot [this {:ui/keys [value]}] | |
{:query [:ui/value] | |
:ident (fn [] [:component/id ::root]) | |
:initial-state {:ui/value "boop"} | |
:route-segment ["dashboard"]} | |
(div {} | |
(str "Dashboard" value))) | |
(defsc ProfileTab [this {:keys [] :as props}] | |
{:query [] | |
:ident (fn [] [:component/id ::profile]) | |
:route-segment ["profile"] | |
:initial-state {}}) | |
(defsc PreferencesTab [this {:keys [] :as props}] | |
{:query [] | |
:ident (fn [] [:component/id ::preferences]) | |
:route-segment ["preferences"] | |
:initial-state {} | |
:title "Preferences"} | |
(div {} "Preferences")) | |
(defrouter InvestorRouter [this {:keys [route-factory route-props]}] | |
{:always-render-body? true | |
:router-targets [ProfileTab PreferencesTab]} | |
(when route-factory | |
(route-factory route-props))) | |
(def ui-investor-router (comp/factory InvestorRouter)) | |
(defsc InvestorRoot [this {:ui/keys [router] :as props}] | |
{:query [{:ui/router (comp/get-query InvestorRouter)} | |
(uism/asm-ident ::InvestorRouter)] | |
:ident (fn [] [:component/id ::root]) | |
:initial-state (fn [_] {:ui/router {}}) | |
:route-segment ["investors"]}) | |
(defrouter AuthenticatedRouter [this {:keys [route-factory route-props]}] | |
{:always-render-body? true | |
:router-targets [DashboardRoot InvestorRoot]} | |
(when route-factory | |
(do | |
(route-factory route-props)))) | |
(def ui-authenticated-router (comp/factory AuthenticatedRouter)) | |
(defsc AuthenticatedRoot [this {::keys [router]}] | |
{:query [{::router (comp/get-query AuthenticatedRouter)} | |
(uism/asm-ident ::AuthenticatedRouter)] | |
:initial-state (fn [_] {::router {}})} | |
(ui-authenticated-router router)) | |
(def ui-authenticated-root (comp/factory AuthenticatedRoot)) | |
(defsc RootComponent [this {::keys [router auth-root] | |
:as props}] | |
{:query [{::auth-root (comp/get-query AuthenticatedRoot)} | |
{::router (comp/get-query UnauthenticatedRouter)} | |
[::uism/asm-id ::UnauthenticatedRouter] | |
ac/authentication-ident] ;;used in the auth query | |
:initial-state {::router {} | |
::auth-root {}}} | |
(if (is-authenticated? props) ;;this returns true if authenticated | |
(ui-authenticated-root auth-root) | |
(ui-unauthenticated-router router))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment