0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-15 09:11:21 -05:00
penpot/frontend/src/uxbox/main/ui.cljs

106 lines
3.4 KiB
Text
Raw Normal View History

2016-03-01 20:18:42 +02:00
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2015-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
2019-07-05 09:41:20 +02:00
;; Copyright (c) 2015-2019 Andrey Antukh <niwi@niwi.nz>
2016-03-01 20:18:42 +02:00
2019-07-01 19:40:01 +02:00
(ns uxbox.main.ui
2019-07-05 09:41:20 +02:00
(:require
[beicon.core :as rx]
[cuerdas.core :as str]
[lentes.core :as l]
[potok.core :as ptk]
[rumext.core :as mx :include-macros true]
[uxbox.builtins.icons :as i]
[uxbox.main.data.auth :refer [logout]]
[uxbox.main.data.projects :as dp]
[uxbox.main.store :as st]
[uxbox.main.ui.auth :as auth]
[uxbox.main.ui.dashboard :as dashboard]
[uxbox.main.ui.lightbox :refer [lightbox]]
[uxbox.main.ui.loader :refer [loader]]
[uxbox.main.ui.settings :as settings]
[uxbox.main.ui.shapes]
[uxbox.main.ui.workspace :refer [workspace]]
[uxbox.util.data :refer [parse-int uuid-str?]]
[uxbox.util.dom :as dom]
2019-07-09 13:39:49 +02:00
[uxbox.util.html.history :as html-history]
2019-07-05 09:41:20 +02:00
[uxbox.util.i18n :refer [tr]]
[uxbox.util.messages :as uum]
[uxbox.util.router :as rt]
[uxbox.util.timers :as ts]))
2015-12-17 16:43:58 +02:00
;; --- Routes
(def routes
[["/auth"
["/login" :auth/login]
["/register" :auth/register]
["/recovery/request" :auth/recovery-request]
["/recovery/token/:token" :auth/recovery]]
["/settings"
["/profile" :settings/profile]
["/password" :settings/password]
["/notifications" :settings/notifications]]
["/dashboard"
["/projects" :dashboard/projects]
["/elements" :dashboard/elements]
["/icons" :dashboard/icons]
["/images" :dashboard/images]
["/colors" :dashboard/colors]]
["/workspace/:project/:page" :workspace/page]])
2016-04-16 13:49:39 +03:00
;; --- Main App (Component)
(defn- parse-dashboard-params
[route section]
(let [{:keys [id type]} (get-in route [:params :query])
id (cond
(str/digits? id) (parse-int id)
(uuid-str? id) (uuid id)
:else nil)
type (when (str/alpha? type) (keyword type))]
{:section section
:id id
:type type}))
2019-07-01 19:40:01 +02:00
(mx/def app
:mixins [mx/reactive]
2019-07-01 19:40:01 +02:00
:init
(fn [own props]
(assoc own ::route-ref (l/derive (l/key :route) st/state)))
:render
(fn [own props]
(let [route (mx/react (::route-ref own))]
(case (get-in route [:data :name])
:auth/login (auth/login-page)
:auth/register (auth/register-page)
:auth/recovery-request (auth/recovery-request-page)
:auth/recovery
(let [token (get-in route [:params :path :token])]
(auth/recovery-page token))
:settings/profile (settings/profile-page)
:settings/password (settings/password-page)
:settings/notifications (settings/notifications-page)
:dashboard/projects (dashboard/dashboard {:section :projects})
:dashboard/icons (-> (parse-dashboard-params route :icons)
(dashboard/dashboard))
:dashboard/images (-> (parse-dashboard-params route :images)
(dashboard/dashboard))
:dashboard/colors (-> (parse-dashboard-params route :colors)
(dashboard/dashboard))
:workspace/page
(let [project (uuid (get-in route [:params :path :project]))
page (uuid (get-in route [:params :path :page]))]
(workspace {:project project :page page}))
nil
))))