mirror of
https://github.com/penpot/penpot.git
synced 2025-04-16 00:41:25 -05:00
Redirect to dashboad when logged user enters to login page.
This commit is contained in:
parent
483043202a
commit
468f6a27e1
5 changed files with 51 additions and 38 deletions
|
@ -7,7 +7,8 @@
|
|||
|
||||
(ns uxbox.core
|
||||
(:require-macros [uxbox.util.syntax :refer [define-once]])
|
||||
(:require [uxbox.state :as st]
|
||||
(:require [beicon.core :as rx]
|
||||
[uxbox.state :as st]
|
||||
[uxbox.router :as rt]
|
||||
[uxbox.rstore :as rs]
|
||||
[uxbox.ui :as ui]))
|
||||
|
|
|
@ -21,33 +21,40 @@
|
|||
(as-> (l/in [:route]) $
|
||||
(l/focus-atom $ s/state)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Events
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; --- Update Location (Event)
|
||||
|
||||
(defrecord UpdateLocation [id params]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [route (merge {:id id}
|
||||
(when params
|
||||
{:params params}))]
|
||||
(assoc state :route route))))
|
||||
|
||||
(defn update-location?
|
||||
[v]
|
||||
(instance? UpdateLocation v))
|
||||
|
||||
(defn update-location
|
||||
[{:keys [handler route-params] :as params}]
|
||||
(reify
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
;; (println "update-location" handler route-params)
|
||||
(let [route (merge {:id handler}
|
||||
(when route-params
|
||||
{:params route-params}))]
|
||||
(assoc state :route route)))))
|
||||
(UpdateLocation. handler route-params))
|
||||
|
||||
;; --- Navigate (Event)
|
||||
|
||||
(defrecord Navigate [id params]
|
||||
rs/EffectEvent
|
||||
(-apply-effect [_ state]
|
||||
;; (println "navigate" id params)
|
||||
(let [loc (merge {:handler id}
|
||||
(when params
|
||||
{:route-params params}))]
|
||||
(bidi.router/set-location! @+router+ loc))))
|
||||
|
||||
(defn navigate
|
||||
([id] (navigate id nil))
|
||||
([id params]
|
||||
{:pre [(keyword? id)]}
|
||||
(reify
|
||||
rs/EffectEvent
|
||||
(-apply-effect [_ state]
|
||||
;; (println "navigate" id params)
|
||||
(let [loc (merge {:handler id}
|
||||
(when params
|
||||
{:route-params params}))]
|
||||
(bidi.router/set-location! @+router+ loc))))))
|
||||
(Navigate. id params)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Router declaration
|
||||
|
|
|
@ -13,6 +13,14 @@
|
|||
|
||||
(defonce state (atom {}))
|
||||
|
||||
(def ^:const auth-l
|
||||
(-> (l/key :auth)
|
||||
(l/focus-atom state)))
|
||||
|
||||
(def ^:const loader-l
|
||||
(-> (l/key :loader)
|
||||
(l/focus-atom state)))
|
||||
|
||||
(defn get-initial-state
|
||||
[]
|
||||
{:dashboard {:project-order :name
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
[goog.dom :as gdom]
|
||||
[rum.core :as rum]
|
||||
[lentes.core :as l]
|
||||
[uxbox.state :as s]
|
||||
[uxbox.state :as st]
|
||||
[uxbox.router :as r]
|
||||
[uxbox.rstore :as rs]
|
||||
[uxbox.data.projects :as dp]
|
||||
|
@ -25,16 +25,6 @@
|
|||
[uxbox.ui.mixins :as mx]
|
||||
[uxbox.ui.shapes]))
|
||||
|
||||
;; --- Lentes
|
||||
|
||||
(def ^:const auth-data-l
|
||||
(-> (l/key :auth)
|
||||
(l/focus-atom s/state)))
|
||||
|
||||
(def ^:const loader-l
|
||||
(-> (l/key :loader)
|
||||
(l/focus-atom s/state)))
|
||||
|
||||
;; --- Constants
|
||||
|
||||
(def ^:const +unrestricted+ #{:auth/login})
|
||||
|
@ -45,7 +35,7 @@
|
|||
(defn app-render
|
||||
[own]
|
||||
(let [route (rum/react r/route-l)
|
||||
auth (rum/react auth-data-l)
|
||||
auth (rum/react st/auth-l)
|
||||
location (:id route)
|
||||
params (:params route)]
|
||||
(if (and (restricted? location) (not auth))
|
||||
|
@ -67,7 +57,7 @@
|
|||
|
||||
(defn app-will-mount
|
||||
[own]
|
||||
(when @auth-data-l
|
||||
(when @st/auth-l
|
||||
(rs/emit! (udu/fetch-profile)))
|
||||
own)
|
||||
|
||||
|
@ -82,7 +72,7 @@
|
|||
|
||||
(defn loader-render
|
||||
[own]
|
||||
(when (rum/react loader-l)
|
||||
(when (rum/react st/loader-l)
|
||||
(html
|
||||
[:div.loader-content i/loader])))
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
[lentes.core :as l]
|
||||
[cuerdas.core :as str]
|
||||
[rum.core :as rum]
|
||||
[uxbox.router :as r]
|
||||
[uxbox.state :as s]
|
||||
[uxbox.router :as rt]
|
||||
[uxbox.state :as st]
|
||||
[uxbox.rstore :as rs]
|
||||
[uxbox.data.auth :as da]
|
||||
[uxbox.data.messages :as udm]
|
||||
|
@ -67,11 +67,18 @@
|
|||
:value "Continue"
|
||||
:type "submit"}]
|
||||
[:div.login-links
|
||||
[:a {:on-click #(r/go :auth/recover-password)} "Forgot your password?"]
|
||||
[:a {:on-click #(r/go :auth/register)} "Don't have an account?"]]]]]])))
|
||||
[:a {:on-click #(rt/go :auth/recover-password)} "Forgot your password?"]
|
||||
[:a {:on-click #(rt/go :auth/register)} "Don't have an account?"]]]]]])))
|
||||
|
||||
(defn- login-will-mount
|
||||
[own]
|
||||
(when @st/auth-l
|
||||
(rt/go :dashboard/projects))
|
||||
own)
|
||||
|
||||
(def ^:const login
|
||||
(mx/component
|
||||
{:render #(login-render % (:rum/local %))
|
||||
:will-mount login-will-mount
|
||||
:name "login"
|
||||
:mixins [(mx/local)]}))
|
||||
|
|
Loading…
Add table
Reference in a new issue