0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-19 11:11:21 -05:00

Minor structure refactor.

Make forms and messages modules independent of
store location (making them plugables).
This commit is contained in:
Andrey Antukh 2017-01-13 22:01:13 +01:00
parent 8c28a8c0a7
commit 08b0a096eb
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
87 changed files with 573 additions and 505 deletions

View file

@ -5,14 +5,13 @@
;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.main
(:require [uxbox.store :as st]
(:require [uxbox.main.store :as st]
[uxbox.main.locales :as lc]
[uxbox.main.ui :as ui]
[uxbox.main.state :refer [initial-state]]))
[uxbox.main.ui :as ui]))
(defn ^:export init
[]
(lc/init)
(st/init initial-state)
(st/init)
(ui/init-routes)
(ui/init))

View file

@ -8,12 +8,12 @@
(:require [cljs.spec :as s]
[beicon.core :as rx]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.repo :as rp]
[uxbox.main.state :refer [initial-state]]
[uxbox.main.data.projects :as udp]
[uxbox.main.data.users :as udu]
[uxbox.main.data.messages :as udm]
[uxbox.util.messages :as uum]
[uxbox.util.router :as rt]
[uxbox.util.spec :as us]
[uxbox.util.i18n :refer (tr)]
@ -58,7 +58,7 @@
(let [params {:username username
:password password
:scope "webapp"}
on-error #(udm/error (tr "errors.auth.unauthorized"))]
on-error #(rx/of (uum/error (tr "errors.auth.unauthorized")))]
(->> (rp/req :fetch/token params)
(rx/map :payload)
(rx/map logged-in)
@ -133,7 +133,7 @@
(->> stream
(rx/filter #(= % ::recovery-requested))
(rx/take 1)
(rx/do #(udm/info! (tr "auth.message.recovery-token-sent"))))))))
(rx/map #(uum/info (tr "auth.message.recovery-token-sent"))))))))
(s/def ::recovery-request-event
(s/keys :req-un [::username]))
@ -151,7 +151,7 @@
(letfn [(on-error [{payload :payload}]
(rx/of
(rt/navigate :auth/login)
(udm/show-error (tr "errors.auth.invalid-recovery-token"))))]
(uum/error (tr "errors.auth.invalid-recovery-token"))))]
(->> (rp/req :auth/validate-recovery-token token)
(rx/ignore)
(rx/catch rp/client-error? on-error)))))
@ -167,11 +167,11 @@
ptk/WatchEvent
(watch [_ state stream]
(letfn [(on-error [{payload :payload}]
(udm/error (tr "errors.auth.invalid-recovery-token")))
(rx/of (uum/error (tr "errors.auth.invalid-recovery-token"))))
(on-success [{payload :payload}]
(rx/of
(rt/navigate :auth/login)
(udm/show-info (tr "auth.message.password-recovered"))))]
(uum/info (tr "auth.message.password-recovered"))))]
(->> (rp/req :auth/recovery {:token token :password password})
(rx/mapcat on-success)
(rx/catch rp/client-error? on-error)))))

View file

@ -12,7 +12,7 @@
[potok.core :as ptk]
[uxbox.util.router :as r]
[uxbox.util.color :as color]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.repo :as rp]))
;; --- Initialize

View file

@ -9,7 +9,7 @@
[uxbox.util.uuid :as uuid]
[potok.core :as ptk]
[uxbox.util.router :as r]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.util.forms :as sc]
[uxbox.main.repo :as rp]
[uxbox.main.data.projects :as dp]

View file

@ -14,7 +14,7 @@
[uxbox.util.i18n :refer (tr)]
[uxbox.util.forms :as sc]
[uxbox.main.data.pages :as udp]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.util.time :as dt]
[uxbox.util.data :refer (without-keys
replace-by-id

View file

@ -13,7 +13,7 @@
[uxbox.util.router :as r]
[uxbox.util.dom :as dom]
[uxbox.util.files :as files]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.repo :as rp]))
;; --- Initialize

View file

@ -12,7 +12,7 @@
[potok.core :as ptk]
[uxbox.util.router :as r]
[uxbox.util.files :as files]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.repo :as rp]))
;; --- Initialize

View file

@ -8,7 +8,7 @@
(:require [beicon.core :as rx]
[lentes.core :as l]
[potok.core :as ptk]
[uxbox.store :as st]))
[uxbox.main.store :as st]))
;; --- Show Lightbox

View file

@ -1,112 +0,0 @@
;; 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) 2016 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.main.data.messages
(:require [cuerdas.core :as str]
[beicon.core :as rx]
[lentes.core :as l]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.util.timers :as ts]))
;; --- Constants
(def +animation-timeout+ 600)
;; --- Message Event
(declare hide-message)
(declare show-message?)
(defrecord ShowMessage [data]
ptk/UpdateEvent
(update [_ state]
(let [message (assoc data :state :visible)]
(assoc state :message message)))
ptk/WatchEvent
(watch [_ state s]
(let [stoper (->> (rx/filter show-message? s)
(rx/take 1))]
(->> (rx/of (hide-message))
(rx/delay (:timeout data))
(rx/take-until stoper)))))
(defn show-message
[message]
(ShowMessage. message))
(defn show-message?
[v]
(instance? ShowMessage v))
(defn show-error
[message & {:keys [timeout] :or {timeout 3000}}]
(show-message {:content message
:type :error
:timeout timeout}))
(defn show-info
[message & {:keys [timeout] :or {timeout 3000}}]
(show-message {:content message
:type :info
:timeout timeout}))
(defn show-dialog
[message & {:keys [on-accept on-cancel]}]
(show-message {:content message
:on-accept on-accept
:on-cancel on-cancel
:timeout js/Number.MAX_SAFE_INTEGER
:type :dialog}))
;; --- Hide Message
(defrecord HideMessage [^:mutable canceled?]
ptk/UpdateEvent
(update [_ state]
(update state :message
(fn [v]
(if (nil? v)
(do (set! canceled? true) nil)
(assoc v :state :hide)))))
ptk/WatchEvent
(watch [_ state s]
(if canceled?
(rx/empty)
(->> (rx/of #(dissoc state :message))
(rx/delay +animation-timeout+)))))
(defn hide-message
[]
(HideMessage. false))
;; --- Direct Call Api
(defn error!
[& args]
(ts/schedule 0 #(st/emit! (apply show-error args))))
(defn info!
[& args]
(ts/schedule 0 #(st/emit! (apply show-info args))))
(defn dialog!
[& args]
(ts/schedule 0 #(st/emit! (apply show-dialog args))))
(defn close!
[]
(st/emit! (hide-message)))
(defn error
[& args]
(rx/of (apply show-error args)))
(defn info
[& args]
(rx/of (apply show-info args)))

View file

@ -10,7 +10,7 @@
[beicon.core :as rx]
[lentes.core :as l]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.repo :as rp]
[uxbox.main.lenses :as ul]
[uxbox.util.rlocks :as rlocks]

View file

@ -9,7 +9,7 @@
[cuerdas.core :as str]
[beicon.core :as rx]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.repo :as rp]
[uxbox.main.data.pages :as udp]
[uxbox.util.spec :as us]

View file

@ -9,7 +9,7 @@
[lentes.core :as l]
[beicon.core :as rx]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.constants :as c]
[uxbox.main.lenses :as ul]
[uxbox.main.geom :as geom]

View file

@ -9,7 +9,7 @@
[beicon.core :as rx]
[potok.core :as ptk]
[uxbox.main.data.pages :as udp]
[uxbox.store :as st]))
[uxbox.main.store :as st]))
;; --- Watch Page Changes

View file

@ -8,10 +8,10 @@
(:require [cljs.spec :as s]
[beicon.core :as rx]
[potok.core :as ptk]
[uxbox.main.repo :as rp]
[uxbox.util.spec :as us]
[uxbox.util.i18n :refer (tr)]
[uxbox.main.repo :as rp]
[uxbox.main.data.messages :as udm]))
[uxbox.util.messages :as uum]))
(s/def ::fullname string?)
(s/def ::email us/email?)
@ -47,11 +47,8 @@
(defrecord ProfileUpdated [data]
ptk/WatchEvent
(watch [_ state s]
(rx/of (profile-fetched data)))
ptk/EffectEvent
(effect [_ state stream]
(udm/info! (tr "settings.profile-saved"))))
(rx/of (profile-fetched data)
(uum/info (tr "settings.profile-saved")))))
(defn profile-updated
[data]
@ -84,9 +81,9 @@
;; --- Password Updated
(defrecord PasswordUpdated []
ptk/EffectEvent
(effect [_ state stream]
(udm/info! (tr "settings.password-saved"))))
ptk/WatchEvent
(watch [_ state stream]
(rx/of (uum/info (tr "settings.password-saved")))))
(defn password-updated
[]

View file

@ -9,7 +9,7 @@
[beicon.core :as rx]
[potok.core :as ptk]
[lentes.core :as l]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.constants :as c]
[uxbox.main.lenses :as ul]
[uxbox.main.workers :as uwrk]

View file

@ -6,7 +6,7 @@
(ns uxbox.main.exports
"The main logic for SVG export functionality."
(:require [uxbox.store :as st]
(:require [uxbox.main.store :as st]
[uxbox.main.ui.shapes.rect :refer (rect-shape)]
[uxbox.main.ui.shapes.icon :refer (icon-shape)]
[uxbox.main.ui.shapes.text :refer (text-shape)]

View file

@ -9,7 +9,7 @@
[uxbox.util.geom.matrix :as gmt]
[uxbox.util.geom.point :as gpt]
[uxbox.util.math :as mth]
[uxbox.store :as st]))
[uxbox.main.store :as st]))
;; --- Relative Movement

View file

@ -8,7 +8,7 @@
"A collection of derived refs."
(:require [lentes.core :as l]
[beicon.core :as rx]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.lenses :as ul]))
;; --- Helpers

View file

@ -0,0 +1,58 @@
;; 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 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.main.store
(:require [beicon.core :as rx]
[lentes.core :as l]
[potok.core :as ptk]
[uxbox.builtins.colors :as colors]
[uxbox.util.storage :refer [storage]]))
(enable-console-print!)
(def ^:dynamic *on-error* identity)
(defonce state (atom {}))
(defonce loader (atom false))
(defonce store (ptk/store {:on-error #(*on-error* %)}))
(defonce stream (ptk/input-stream store))
(def auth-ref
(-> (l/key :auth)
(l/derive state)))
(defn emit!
([event]
(ptk/emit! store event))
([event & events]
(apply ptk/emit! store (cons event events))))
(defn- initial-state
[]
{:dashboard {:project-order :name
:project-filter ""
:images-order :name
:images-filter ""}
:route nil
:auth (:auth storage nil)
:clipboard #queue []
:undo {}
:profile nil
:workspace nil
:images-collections nil
:images nil
:icons-collections nil
:icons nil
:colors-collections colors/collections
:shapes nil
:projects nil
:pages nil})
(defn init
"Initialize the state materialization."
[]
(emit! initial-state)
(rx/to-atom store state))

View file

@ -2,19 +2,20 @@
;; 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-2016 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2015-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
(ns uxbox.main.ui
(:require [beicon.core :as rx]
[lentes.core :as l]
[cuerdas.core :as str]
[bide.core :as bc]
[uxbox.store :as st]
[potok.core :as ptk]
[uxbox.main.store :as st]
[uxbox.main.data.projects :as dp]
[uxbox.main.data.users :as udu]
[uxbox.main.data.auth :refer [logout]]
[uxbox.main.data.messages :as dmsg]
[uxbox.util.messages :as uum]
[uxbox.main.ui.loader :refer (loader)]
[uxbox.main.ui.lightbox :refer (lightbox)]
[uxbox.main.ui.icons :as i]
@ -22,14 +23,13 @@
[uxbox.main.ui.dashboard :as dashboard]
[uxbox.main.ui.settings :as settings]
[uxbox.main.ui.workspace :refer (workspace)]
[uxbox.util.timers :as ts]
[uxbox.main.ui.shapes]
[uxbox.util.router :as rt]
[potok.core :as ptk]
[uxbox.util.timers :as ts]
[uxbox.util.i18n :refer (tr)]
[uxbox.util.data :refer (parse-int uuid-str?)]
[uxbox.util.dom :as dom]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.main.ui.shapes]))
[uxbox.util.mixins :as mx :include-macros true]))
;; --- Constants
@ -62,18 +62,18 @@
;; Conflict
(= status 412)
(dmsg/error! (tr "errors.conflict"))
(st/emit! (uum/error (tr "errors.conflict")))
;; Network error
(= (:status error) 0)
(do
(dmsg/error! (tr "errors.network"))
(st/emit! (uum/error (tr "errors.network")))
(js/console.error "Stack:" (.-stack error)))
;; Something else
:else
(do
(dmsg/error! (tr "errors.generic"))
(st/emit! (uum/error (tr "errors.generic")))
(js/console.error "Stack:" (.-stack error)))))
(set! st/*on-error* on-error)
@ -95,7 +95,7 @@
location (:id route)
params (:params route)]
(if (and (restricted? location) (not auth))
(do (ts/schedule 0 #(rt/go :auth/login)) nil)
(do (ts/schedule 0 #(st/emit! (rt/navigate :auth/login))) nil)
(case location
:auth/login (auth/login-page)
:auth/register (auth/register-page)
@ -166,7 +166,7 @@
(defn init-routes
[]
(rt/init routes))
(rt/init st/store routes {:default :auth/login}))
(defn init
[]

View file

@ -9,11 +9,10 @@
(:require [lentes.core :as l]
[cuerdas.core :as str]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.auth :as da]
[uxbox.main.data.messages :as udm]
[uxbox.main.ui.icons :as i]
[uxbox.main.ui.messages :as uum]
[uxbox.main.ui.messages :refer [messages-widget]]
[uxbox.main.ui.navigation :as nav]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.router :as rt]
@ -21,12 +20,12 @@
[uxbox.util.forms :as forms]))
(def form-data (forms/focus-data :login st/state))
(def set-value! (partial forms/set-value! :login))
(def set-value! (partial forms/set-value! st/store :login))
(defn- login-page-will-mount
[own]
(when @st/auth-ref
(rt/go :dashboard/projects))
(st/emit! (rt/navigate :dashboard/projects)))
own)
(def +login-form+
@ -68,8 +67,10 @@
:value "Continue"
:type "submit"}]
[:div.login-links
[:a {:on-click #(rt/go :auth/recovery-request)} "Forgot your password?"]
[:a {:on-click #(rt/go :auth/register)} "Don't have an account?"]]]])))
[:a {:on-click #(st/emit! (rt/navigate :auth/recovery-request))}
"Forgot your password?"]
[:a {:on-click #(st/emit! (rt/navigate :auth/register))}
"Don't have an account?"]]]])))
(mx/defc login-page
{:mixins [mx/static]
@ -77,6 +78,6 @@
[]
[:div.login
[:div.login-body
(uum/messages)
(messages-widget)
[:a i/logo]
(login-form)]])

View file

@ -8,22 +8,22 @@
(ns uxbox.main.ui.auth.recovery
(:require [lentes.core :as l]
[cuerdas.core :as str]
[uxbox.util.router :as rt]
[uxbox.store :as st]
[potok.core :as ptk]
[uxbox.main.store :as st]
[uxbox.main.data.auth :as uda]
[uxbox.main.ui.icons :as i]
[uxbox.main.ui.messages :refer [messages-widget]]
[uxbox.main.ui.navigation :as nav]
[uxbox.util.router :as rt]
[uxbox.util.forms :as forms]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.dom :as dom]
[uxbox.main.data.auth :as uda]
[uxbox.main.data.messages :as udm]
[uxbox.main.ui.icons :as i]
[uxbox.main.ui.messages :as uum]
[uxbox.main.ui.navigation :as nav]))
[uxbox.util.dom :as dom]))
;; --- Recovery Form
(def form-data (forms/focus-data :recovery st/state))
(def set-value! (partial forms/set-value! :recovery))
(def set-value! (partial forms/set-value! st/store :recovery))
(def +recovery-form+
{:password [forms/required forms/string]})
@ -40,7 +40,8 @@
(on-submit [event]
(dom/prevent-default event)
(st/emit! (uda/recovery data)
(forms/clear :recovery)))]
(forms/clear-form :recovery)
(forms/clear-errors :recovery)))]
[:form {:on-submit on-submit}
[:div.login-content
[:input.input-text
@ -56,7 +57,7 @@
:value "Recover password"
:type "submit"}]
[:div.login-links
[:a {:on-click #(rt/go :auth/login)} "Go back!"]]]])))
[:a {:on-click #(st/emit! (rt/navigate :auth/login))} "Go back!"]]]])))
;; --- Recovery Page
@ -67,12 +68,11 @@
own))
(mx/defc recovery-page
{:mixins [mx/static]
:will-mount recovery-page-will-mount
:will-unmount (forms/cleaner-fn :recovery)}
{:mixins [mx/static (forms/clear-mixin st/store :recovery)]
:will-mount recovery-page-will-mount}
[token]
[:div.login
[:div.login-body
(uum/messages)
(messages-widget)
[:a i/logo]
(recovery-form token)]])

View file

@ -2,26 +2,26 @@
;; 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-2016 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2015-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
(ns uxbox.main.ui.auth.recovery-request
(:require [lentes.core :as l]
[cuerdas.core :as str]
[uxbox.util.router :as rt]
[potok.core :as ptk]
[uxbox.main.store :as st]
[uxbox.main.data.auth :as uda]
[uxbox.main.ui.icons :as i]
[uxbox.main.ui.messages :refer [messages-widget]]
[uxbox.main.ui.navigation :as nav]
[uxbox.util.router :as rt]
[uxbox.util.forms :as forms]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.dom :as dom]
[uxbox.store :as st]
[uxbox.main.data.auth :as uda]
[uxbox.main.data.messages :as udm]
[uxbox.main.ui.icons :as i]
[uxbox.main.ui.messages :as uum]
[uxbox.main.ui.navigation :as nav]))
[uxbox.util.dom :as dom]))
(def form-data (forms/focus-data :recovery-request st/state))
(def set-value! (partial forms/set-value! :recovery-request))
(def set-value! (partial forms/set-value! st/store :recovery-request))
(def +recovery-request-form+
{:username [forms/required forms/string]})
@ -37,7 +37,8 @@
(on-submit [event]
(dom/prevent-default event)
(st/emit! (uda/recovery-request data)
(forms/clear :recovery-request)))]
(forms/clear-form :recovery-request)
(forms/clear-errors :recovery-request)))]
[:form {:on-submit on-submit}
[:div.login-content
[:input.input-text
@ -53,16 +54,15 @@
:value "Recover password"
:type "submit"}]
[:div.login-links
[:a {:on-click #(rt/go :auth/login)} "Go back!"]]]])))
[:a {:on-click #(st/emit! (rt/navigate :auth/login))} "Go back!"]]]])))
;; --- Recovery Request Page
(mx/defc recovery-request-page
{:mixins [mx/static]
:will-unmount (forms/cleaner-fn :recovery-request)}
{:mixins [mx/static (forms/clear-mixin st/store :recovery-request)]}
[]
[:div.login
[:div.login-body
(uum/messages)
(messages-widget)
[:a i/logo]
(recovery-request-form)]])

View file

@ -8,24 +8,23 @@
(ns uxbox.main.ui.auth.register
(:require [lentes.core :as l]
[cuerdas.core :as str]
[uxbox.util.router :as rt]
[potok.core :as ptk]
[uxbox.main.store :as st]
[uxbox.main.data.auth :as uda]
[uxbox.main.ui.icons :as i]
[uxbox.main.ui.messages :refer [messages-widget]]
[uxbox.main.ui.navigation :as nav]
[uxbox.util.router :as rt]
[uxbox.util.forms :as forms]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.dom :as dom]
[uxbox.store :as st]
[uxbox.main.data.auth :as uda]
[uxbox.main.data.messages :as udm]
[uxbox.main.ui.icons :as i]
[uxbox.main.ui.messages :as uum]
[uxbox.main.ui.navigation :as nav]))
[uxbox.util.dom :as dom]))
;; --- Register Form
(def form-data (forms/focus-data :register st/state))
(def form-errors (forms/focus-errors :register st/state))
(def set-value! (partial forms/set-value! :register))
(def set-error! (partial forms/set-error! :register))
(def set-value! (partial forms/set-value! st/store :register))
(def set-error! (partial forms/set-error! st/store :register))
(def +register-form+
{:username [forms/required forms/string]
@ -94,8 +93,7 @@
:value "Register"
:type "submit"}]
[:div.login-links
;; [:a {:on-click #(rt/go :auth/recover-password)} "Forgot your password?"]
[:a {:on-click #(rt/go :auth/login)} "Already have an account?"]]]])))
[:a {:on-click #(st/emit! (rt/navigate :auth/login))} "Already have an account?"]]]])))
;; --- Register Page
@ -104,6 +102,6 @@
[own]
[:div.login
[:div.login-body
(uum/messages)
(messages-widget)
[:a i/logo]
(register-form)]])

View file

@ -8,11 +8,12 @@
(ns uxbox.main.ui.dashboard.colors
(:require [cuerdas.core :as str]
[lentes.core :as l]
[potok.core :as ptk]
[uxbox.main.data.colors :as dc]
[uxbox.main.data.dashboard :as dd]
[uxbox.main.data.lightbox :as udl]
[uxbox.store :as st]
[uxbox.main.ui.messages :as uum]
[uxbox.main.store :as st]
[uxbox.main.ui.messages :refer [messages-widget]]
[uxbox.main.ui.colorpicker :refer (colorpicker)]
[uxbox.main.ui.dashboard.header :refer (header)]
[uxbox.main.ui.icons :as i]
@ -22,8 +23,7 @@
[uxbox.util.dom :as dom]
[uxbox.util.i18n :as t :refer (tr)]
[uxbox.util.lens :as ul]
[uxbox.util.mixins :as mx :include-macros true]
[potok.core :as ptk]))
[uxbox.util.mixins :as mx :include-macros true]))
;; --- Refs
@ -332,7 +332,7 @@
colls (mx/react collections-ref)
coll (get colls (:id state))]
[:main.dashboard-main
(uum/messages)
(messages-widget)
(header)
[:section.dashboard-content
(nav state colls)

View file

@ -7,7 +7,7 @@
(ns uxbox.main.ui.dashboard.header
(:require [lentes.core :as l]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.projects :as dp]
[uxbox.main.ui.navigation :as nav]
[uxbox.main.ui.icons :as i]

View file

@ -8,7 +8,7 @@
(ns uxbox.main.ui.dashboard.icons
(:require [lentes.core :as l]
[cuerdas.core :as str]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.lightbox :as udl]
[uxbox.main.data.icons :as di]
[uxbox.main.ui.icons :as i]

View file

@ -9,7 +9,7 @@
(:require [cuerdas.core :as str]
[lentes.core :as l]
[uxbox.util.i18n :as t :refer (tr)]
[uxbox.store :as st]
[uxbox.main.store :as st]
[potok.core :as ptk]
[uxbox.main.data.lightbox :as udl]
[uxbox.main.data.images :as di]

View file

@ -8,21 +8,21 @@
(ns uxbox.main.ui.dashboard.projects
(:require [lentes.core :as l]
[cuerdas.core :as str]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.constants :as c]
[uxbox.main.data.projects :as udp]
[uxbox.main.data.lightbox :as udl]
[uxbox.main.ui.icons :as i]
[uxbox.main.ui.dashboard.header :refer (header)]
[uxbox.main.ui.dashboard.header :refer [header]]
[uxbox.main.ui.dashboard.projects-createlightbox]
[uxbox.main.ui.lightbox :as lbx]
[uxbox.main.ui.messages :as uum]
[uxbox.main.ui.messages :refer [messages-widget]]
[uxbox.main.ui.keyboard :as kbd]
[uxbox.main.exports :as exports]
[uxbox.util.i18n :as t :refer (tr)]
[uxbox.util.router :as r]
[potok.core :as ptk]
[uxbox.util.data :refer (read-string)]
[uxbox.util.data :refer [read-string]]
[uxbox.util.dom :as dom]
[uxbox.util.blob :as blob]
[uxbox.util.mixins :as mx :include-macros true]
@ -241,7 +241,7 @@
(let [state (mx/react dashboard-ref)
projects-map (mx/react projects-map-ref)]
[:main.dashboard-main
(uum/messages)
(messages-widget)
(header)
[:section.dashboard-content
(menu state projects-map)

View file

@ -9,20 +9,19 @@
(:require [lentes.core :as l]
[cuerdas.core :as str]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.constants :as c]
[uxbox.main.exports :as exports]
[uxbox.main.data.projects :as udp]
[uxbox.main.data.lightbox :as udl]
[uxbox.main.ui.icons :as i]
[uxbox.main.ui.dashboard.header :refer (header)]
[uxbox.main.ui.dashboard.header :refer [header]]
[uxbox.main.ui.lightbox :as lbx]
[uxbox.main.ui.messages :as uum]
[uxbox.main.ui.keyboard :as kbd]
[uxbox.util.i18n :as t :refer (tr)]
[uxbox.util.i18n :as t :refer [tr]]
[uxbox.util.router :as r]
[uxbox.util.forms :as forms]
[uxbox.util.data :refer (read-string)]
[uxbox.util.data :refer [read-string]]
[uxbox.util.dom :as dom]
[uxbox.util.blob :as blob]
[uxbox.util.mixins :as mx :include-macros true]
@ -30,9 +29,9 @@
(def form-data (forms/focus-data :create-project st/state))
(def form-errors (forms/focus-errors :create-project st/state))
(def set-value! (partial forms/set-value! :create-project))
(def set-error! (partial forms/set-error! :create-project))
(def clear! (partial forms/clear! :create-project))
(def set-value! (partial forms/set-value! st/store :create-project))
(def set-error! (partial forms/set-error! st/store :create-project))
(def clear! (partial forms/clear! st/store :create-project))
(def ^:private create-project-form
{:name [forms/required forms/string]
@ -74,7 +73,7 @@
(mx/defcs new-project-lightbox
{:mixins [mx/static mx/reactive
(forms/clear-mixin :create-project)]}
(forms/clear-mixin st/store :create-project)]}
[own]
(let [data (merge c/project-defaults (mx/react form-data))
errors (mx/react form-errors)

View file

@ -2,7 +2,7 @@
(:require [sablono.core :as html :refer-macros [html]]
[rum.core :as rum]
[lentes.core :as l]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.lightbox :as udl]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.main.ui.keyboard :as k]

View file

@ -2,27 +2,17 @@
;; 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) 2016 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2016-2017 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.main.ui.loader
(:require [sablono.core :refer-macros [html]]
[rum.core :as rum]
[uxbox.store :as st]
(:require [uxbox.main.store :as st]
[uxbox.main.ui.icons :as i]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.main.ui.shapes]))
[uxbox.util.mixins :as mx :include-macros true]))
;; --- Component
(defn loader-render
[own]
(mx/defc loader
{:mixins [mx/reactive mx/static]}
[]
(when (mx/react st/loader)
(html
[:div.loader-content i/loader])))
(def loader
(mx/component
{:render loader-render
:name "loader"
:mixins [mx/reactive mx/static]}))
[:div.loader-content i/loader]))

View file

@ -1,91 +1,16 @@
(ns uxbox.main.ui.messages
(:require [sablono.core :as html :refer-macros [html]]
[rum.core :as rum]
[lentes.core :as l]
[uxbox.store :as st]
[uxbox.main.data.messages :as udm]
[uxbox.main.ui.icons :as i]
[uxbox.util.timers :as ts]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.data :refer (classnames)]
[uxbox.util.dom :as dom]))
;; --- Lenses
(:require [lentes.core :as l]
[uxbox.main.store :as st]
[uxbox.util.messages :as uum]
[uxbox.util.mixins :as mx :include-macros true]))
(def ^:private message-ref
(-> (l/key :message)
(l/derive st/state)))
;; --- Notification Component
(defn notification-render
[own {:keys [type] :as message}]
(let [classes (classnames :error (= type :error)
:info (= type :info)
:hide-message (= (:state message) :hide)
:quick true)
close #(udm/close!)]
(html
[:div.message {:class classes}
[:div.message-body
[:span.close {:on-click close}
i/close]
[:span (:content message)]]])))
(def ^:private notification-box
(mx/component
{:render notification-render
:name "notification"
:mixins [mx/static]}))
;; --- Dialog Component
(defn dialog-render
[own {:keys [on-accept on-cancel] :as message}]
(let [classes (classnames :info true
:hide-message (= (:state message) :hide))]
(letfn [(accept [event]
(dom/prevent-default event)
(on-accept)
(ts/schedule 0 udm/close!))
(cancel [event]
(dom/prevent-default event)
(when on-cancel
(on-cancel))
(ts/schedule 0 udm/close!))]
(html
[:div.message {:class classes}
[:div.message-body
[:span.close {:on-click cancel} i/close]
[:span (:content message)]
[:div.message-action
[:a.btn-transparent.btn-small
{:on-click accept}
"Accept"]
[:a.btn-transparent.btn-small
{:on-click cancel}
"Cancel"]]]]))))
(def ^:private dialog-box
(mx/component
{:render dialog-render
:name "dialog"
:mixins [mx/static]}))
;; --- Main Component (entry point)
(defn messages-render
[own]
(let [message (mx/react message-ref)]
(case (:type message)
:error (notification-box message)
:info (notification-box message)
:dialog (dialog-box message)
nil)))
(def messages
(mx/component
{:render messages-render
:name "messages"
:mixins [mx/static mx/reactive]}))
(mx/defc messages-widget
{:mixins [mx/static mx/reactive]}
[]
(let [message (mx/react message-ref)
on-close #(st/emit! (uum/hide))]
(uum/messages-widget (assoc message :on-close on-close))))

View file

@ -12,7 +12,7 @@
[uxbox.util.i18n :refer (tr)]
[uxbox.util.router :as r]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.projects :as dp]
[uxbox.main.ui.navigation :as nav]
[uxbox.main.ui.icons :as i]

View file

@ -8,21 +8,21 @@
(ns uxbox.main.ui.settings.password
(:require [lentes.core :as l]
[cuerdas.core :as str]
[uxbox.util.i18n :as t :refer (tr)]
[potok.core :as ptk]
[uxbox.util.forms :as forms]
[uxbox.util.dom :as dom]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.users :as udu]
[uxbox.main.ui.icons :as i]
[uxbox.main.ui.messages :as uum]
[uxbox.main.ui.settings.header :refer (header)]))
[uxbox.main.ui.messages :refer [messages-widget]]
[uxbox.main.ui.settings.header :refer [header]]
[uxbox.util.forms :as forms]
[uxbox.util.dom :as dom]
[uxbox.util.mixins :as mx :include-macros true]))
(def form-data (forms/focus-data :profile-password st/state))
(def form-errors (forms/focus-errors :profile-password st/state))
(def set-value! (partial forms/set-value! :profile-password))
(def set-errors! (partial forms/set-errors! :profile-password))
(def set-value! (partial forms/set-value! st/store :profile-password))
(def set-errors! (partial forms/set-errors! st/store :profile-password))
(def +password-form+
[[:password-1 forms/required forms/string [forms/min-len 6]]
@ -42,7 +42,6 @@
(on-submit [event]
(println "on-submit" data)
#_(st/emit! (udu/update-password form)))]
(println "password-form" data)
[:form.password-form
[:span.user-settings-label "Change password"]
[:input.input-text
@ -79,8 +78,8 @@
{:mixins [mx/static]}
[]
[:main.dashboard-main
(messages-widget)
(header)
(uum/messages)
[:section.dashboard-content.user-settings
[:section.user-settings-content
(password-form)]]])

View file

@ -2,28 +2,30 @@
;; 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) 2016 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
;; Copyright (c) 2016-2017 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2016-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
(ns uxbox.main.ui.settings.profile
(:require [cuerdas.core :as str]
[lentes.core :as l]
[potok.core :as ptk]
[uxbox.main.store :as st]
[uxbox.main.ui.icons :as i]
[uxbox.main.ui.settings.header :refer [header]]
[uxbox.main.ui.messages :refer [messages-widget]]
[uxbox.main.data.users :as udu]
[uxbox.util.forms :as forms]
[uxbox.util.router :as r]
[potok.core :as ptk]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.interop :refer (iterable->seq)]
[uxbox.util.dom :as dom]
[uxbox.store :as st]
[uxbox.main.ui.icons :as i]
[uxbox.main.ui.settings.header :refer (header)]
[uxbox.main.ui.messages :as uum]
[uxbox.main.data.users :as udu]))
[uxbox.util.interop :refer [iterable->seq]]
[uxbox.util.dom :as dom]))
(def form-data (forms/focus-data :profile st/state))
(def form-errors (forms/focus-errors :profile st/state))
(def set-value! (partial forms/set-value! :profile))
(def set-error! (partial forms/set-error! :profile))
(def set-value! (partial forms/set-value! st/store :profile))
(def set-error! (partial forms/set-error! st/store :profile))
(def clear! (partial forms/clear! st/store :profile))
(def profile-ref
(-> (l/key :profile)
@ -37,8 +39,8 @@
;; --- Profile Form
(mx/defc profile-form
{:mixins [mx/static mx/reactive]
:will-unmount (forms/cleaner-fn :profile)}
{:mixins [mx/static mx/reactive
(forms/clear-mixin st/store :profile)]}
[]
;; TODO: properly persist theme
(let [data (merge {:theme "light"}
@ -56,10 +58,8 @@
(set-error! :email "Email already exists")
:uxbox.services.users/username-already-exists
(set-error! :username "Username already exists")))
(on-success []
(forms/clear! :profile))
(on-submit [event]
(st/emit! (udu/update-profile data on-success on-error)))]
(st/emit! (udu/update-profile data clear! on-error)))]
[:form.profile-form
[:span.user-settings-label "Name, username and email"]
[:input.input-text
@ -142,8 +142,8 @@
{:mixins [mx/static]}
[]
[:main.dashboard-main
(messages-widget)
(header)
(uum/messages)
[:section.dashboard-content.user-settings
[:section.user-settings-content
[:span.user-settings-label "Your avatar"]

View file

@ -8,7 +8,7 @@
(:require [lentes.core :as l]
[beicon.core :as rx]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.refs :as refs]
[uxbox.main.streams :as streams]
[uxbox.main.geom :as geom]

View file

@ -6,7 +6,7 @@
(ns uxbox.main.ui.shapes.group
(:require [lentes.core :as l]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.geom :as geom]
[uxbox.main.ui.shapes.common :as common]
[uxbox.main.ui.shapes.attrs :as attrs]

View file

@ -8,7 +8,7 @@
(:require [beicon.core :as rx]
[lentes.core :as l]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.ui.shapes.common :as common]
[uxbox.main.ui.shapes.attrs :as attrs]
[uxbox.main.data.images :as udi]

View file

@ -6,7 +6,7 @@
(ns uxbox.main.ui.shapes.path
(:require [potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.ui.shapes.common :as common]
[uxbox.main.ui.shapes.attrs :as attrs]
[uxbox.main.data.shapes :as uds]

View file

@ -10,7 +10,7 @@
(:require [lentes.core :as l]
[beicon.core :as rx]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.constants :as c]
[uxbox.main.refs :as refs]
[uxbox.main.streams :as streams]

View file

@ -9,7 +9,7 @@
[lentes.core :as l]
[goog.events :as events]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.geom :as geom]
[uxbox.main.data.shapes :as uds]
[uxbox.main.ui.shapes.common :as common]

View file

@ -7,13 +7,13 @@
(ns uxbox.main.ui.users
(:require [cuerdas.core :as str]
[lentes.core :as l]
[uxbox.util.router :as r]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.auth :as da]
[uxbox.main.data.lightbox :as udl]
[uxbox.main.ui.icons :as i]
[uxbox.main.ui.navigation :as nav]
[uxbox.util.router :as rt]
[uxbox.util.mixins :as mx :include-macros true]))
;; --- User Menu
@ -22,13 +22,13 @@
{:mixins [mx/static]}
[open?]
[:ul.dropdown {:class (when-not open? "hide")}
[:li {:on-click #(r/go :settings/profile)}
[:li {:on-click #(st/emit! (rt/navigate :settings/profile))}
i/user
[:span "Profile"]]
[:li {:on-click #(r/go :settings/password)}
[:li {:on-click #(st/emit! (rt/navigate :settings/password))}
i/lock
[:span "Password"]]
[:li {:on-click #(r/go :settings/notifications)}
[:li {:on-click #(st/emit! (rt/navigate :settings/notifications))}
i/mail
[:span "Notifications"]]
[:li {:on-click #(st/emit! (da/logout))}
@ -38,8 +38,8 @@
;; --- User Widget
(def profile-ref
(as-> (l/key :profile) $
(l/derive $ st/state)))
(-> (l/key :profile)
(l/derive st/state)))
(mx/defcs user
{:mixins [mx/static mx/reactive (mx/local {:open false})]}

View file

@ -8,7 +8,7 @@
(ns uxbox.main.ui.workspace
(:require [beicon.core :as rx]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.constants :as c]
[uxbox.main.refs :as refs]
[uxbox.main.streams :as streams]
@ -16,7 +16,7 @@
[uxbox.main.data.pages :as udp]
[uxbox.main.data.history :as udh]
[uxbox.main.data.undo :as udu]
[uxbox.main.ui.messages :as uum]
[uxbox.main.ui.messages :refer [messages-widget]]
[uxbox.main.ui.confirm]
[uxbox.main.ui.workspace.images]
[uxbox.main.ui.keyboard :as kbd]
@ -121,9 +121,9 @@
:no-tool-bar-left (not left-sidebar?)
:scrolling (:viewport-positionig workspace))]
[:div
(messages-widget)
(header)
(colorpalette)
(uum/messages)
[:main.main-content

View file

@ -10,7 +10,7 @@
[lentes.core :as l]
[goog.events :as events]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.constants :as c]
[uxbox.main.refs :as refs]
[uxbox.main.streams :as streams]

View file

@ -7,7 +7,7 @@
(ns uxbox.main.ui.workspace.clipboard
(:require [lentes.core :as l]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.lightbox :as udl]
[uxbox.main.data.workspace :as udw]
[uxbox.main.ui.icons :as i]

View file

@ -9,7 +9,7 @@
(:require [beicon.core :as rx]
[lentes.core :as l]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.refs :as refs]
[uxbox.main.data.workspace :as dw]
[uxbox.main.data.shapes :as uds]

View file

@ -8,7 +8,7 @@
(ns uxbox.main.ui.workspace.colorpicker
(:require [lentes.core :as l]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.refs :as refs]
[uxbox.main.geom :as geom]
[uxbox.main.data.workspace :as udw]

View file

@ -10,7 +10,7 @@
[beicon.core :as rx]
[potok.core :as ptk]
[lentes.core :as l]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.refs :as refs]
[uxbox.main.data.lightbox :as udl]
[uxbox.main.exports :as exports]

View file

@ -10,7 +10,7 @@
[potok.core :as ptk]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.rlocks :as rlocks]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.constants :as c]
[uxbox.main.refs :as refs]
[uxbox.main.streams :as streams]

View file

@ -10,7 +10,7 @@
[uxbox.config :as cfg]
[uxbox.util.router :as r]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.refs :as refs]
[uxbox.main.data.workspace :as dw]
[uxbox.main.data.history :as udh]

View file

@ -12,7 +12,7 @@
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.data :as data :refer (read-string)]
[uxbox.util.dom :as dom]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.lightbox :as udl]
[uxbox.main.data.images :as udi]
[uxbox.main.data.workspace :as udw]

View file

@ -8,7 +8,7 @@
(ns uxbox.main.ui.workspace.recent-colors
(:require [lentes.core :as l]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.refs :as refs]
[uxbox.main.data.workspace :as dw]
[uxbox.main.ui.icons :as i]

View file

@ -10,7 +10,7 @@
[rum.core :as rum]
[cuerdas.core :as str]
[beicon.core :as rx]
[uxbox.store :as s]
[uxbox.main.store :as s]
[uxbox.main.constants :as c]
[uxbox.main.streams :as streams]
[uxbox.util.dom :as dom]

View file

@ -9,7 +9,7 @@
"Mouse selection interaction and component."
(:require [beicon.core :as rx]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.constants :as c]
[uxbox.main.refs :as refs]
[uxbox.main.streams :as streams]

View file

@ -9,7 +9,7 @@
(:require [goog.events :as events]
[beicon.core :as rx]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.lightbox :as udl]
[uxbox.main.data.workspace :as dw]
[uxbox.main.data.shapes :as uds]

View file

@ -8,7 +8,7 @@
(ns uxbox.main.ui.workspace.sidebar
(:require [lentes.core :as l]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.refs :as refs]
[uxbox.main.ui.workspace.sidebar.options :refer (options-toolbox)]
[uxbox.main.ui.workspace.sidebar.layers :refer (layers-toolbox)]

View file

@ -9,7 +9,7 @@
(:require [sablono.core :as html :refer-macros [html]]
[lentes.core :as l]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.refs :as refs]
[uxbox.main.data.workspace :as dw]
[uxbox.main.ui.icons :as i]

View file

@ -10,12 +10,11 @@
[rum.core :as rum]
[lentes.core :as l]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.refs :as refs]
[uxbox.main.data.workspace :as dw]
[uxbox.main.data.pages :as udp]
[uxbox.main.data.history :as udh]
[uxbox.main.data.messages :as udm]
[uxbox.main.ui.icons :as i]
[uxbox.util.i18n :refer (tr)]
[uxbox.util.router :as r]

View file

@ -9,7 +9,7 @@
(:require [lentes.core :as l]
[uxbox.util.router :as r]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.lenses :as ul]
[uxbox.main.data.workspace :as udw]
[uxbox.main.data.icons :as udi]

View file

@ -10,7 +10,7 @@
[cuerdas.core :as str]
[goog.events :as events]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.refs :as refs]
[uxbox.main.data.workspace :as udw]
[uxbox.main.data.shapes :as uds]

View file

@ -11,7 +11,7 @@
[uxbox.util.i18n :refer (tr)]
[uxbox.util.router :as r]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.workspace :as udw]
[uxbox.main.data.shapes :as uds]
[uxbox.main.ui.icons :as i]

View file

@ -12,7 +12,7 @@
[uxbox.util.i18n :refer (tr)]
[uxbox.util.router :as r]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.workspace :as udw]
[uxbox.main.data.shapes :as uds]
[uxbox.main.ui.icons :as i]

View file

@ -10,7 +10,7 @@
[uxbox.util.i18n :refer (tr)]
[uxbox.util.router :as r]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.shapes :as uds]
[uxbox.main.data.lightbox :as udl]
[uxbox.main.ui.icons :as i]

View file

@ -12,7 +12,7 @@
[uxbox.util.i18n :refer (tr)]
[uxbox.util.router :as r]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.workspace :as udw]
[uxbox.main.data.shapes :as uds]
[uxbox.main.ui.icons :as i]

View file

@ -13,7 +13,7 @@
[uxbox.util.router :as r]
[potok.core :as ptk]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.shapes :as uds]
[uxbox.main.data.lightbox :as udl]
[uxbox.main.ui.workspace.sidebar.sitemap :refer (pages-ref)]

View file

@ -10,7 +10,7 @@
(:require [lentes.core :as l]
[potok.core :as ptk]
[cuerdas.core :as str]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.constants :as c]
[uxbox.main.refs :as refs]
[uxbox.main.data.pages :as udp]

View file

@ -10,7 +10,7 @@
[uxbox.util.i18n :refer (tr)]
[uxbox.util.router :as r]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.workspace :as udw]
[uxbox.main.data.shapes :as uds]
[uxbox.main.ui.icons :as i]

View file

@ -10,7 +10,7 @@
[uxbox.util.i18n :refer (tr)]
[uxbox.util.router :as r]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.data.shapes :as uds]
[uxbox.main.data.lightbox :as udl]
[uxbox.main.ui.icons :as i]

View file

@ -8,7 +8,7 @@
(ns uxbox.main.ui.workspace.sidebar.options.text
(:require [lentes.core :as l]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.geom :as geom]
[uxbox.main.data.workspace :as udw]
[uxbox.main.data.shapes :as uds]

View file

@ -9,7 +9,7 @@
(:require [lentes.core :as l]
[cuerdas.core :as str]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.store :as st]
[uxbox.main.refs :as refs]
[uxbox.main.data.projects :as dp]
[uxbox.main.data.pages :as udp]

View file

@ -8,7 +8,8 @@
(ns uxbox.main.ui.workspace.sidebar.sitemap-pageform
(:require [lentes.core :as l]
[cuerdas.core :as str]
[uxbox.store :as st]
[potok.core :as ptk]
[uxbox.main.store :as st]
[uxbox.main.constants :as c]
[uxbox.main.data.pages :as udp]
[uxbox.main.data.workspace :as dw]
@ -17,14 +18,13 @@
[uxbox.main.ui.lightbox :as lbx]
[uxbox.util.i18n :refer (tr)]
[uxbox.util.router :as r]
[potok.core :as ptk]
[uxbox.util.forms :as forms]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.data :refer (deep-merge parse-int)]
[uxbox.util.dom :as dom]))
(def form-data (forms/focus-data :workspace-page-form st/state))
(def set-value! (partial forms/set-value! :workspace-page-form))
(def set-value! (partial forms/set-value! st/store :workspace-page-form))
;; --- Lightbox
@ -118,10 +118,7 @@
:type "button"}])])))
(mx/defc page-form-lightbox
{:mixins [mx/static]
:will-unmount (fn [own]
(forms/clear! :workspace-page-form)
own)}
{:mixins [mx/static (forms/clear-mixin st/store :workspace-page-form)]}
[{:keys [id] :as page}]
(letfn [(on-cancel [event]
(dom/prevent-default event)

View file

@ -11,7 +11,6 @@
[lentes.core :as l]
[beicon.core :as rx]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.i18n :refer (tr)]))
@ -113,8 +112,8 @@
(SetError. type field error)))
(defn set-error!
[& args]
(st/emit! (apply set-error args)))
[store & args]
(ptk/emit! store (apply set-error args)))
;; --- Set Errors
@ -133,8 +132,8 @@
(SetErrors. type errors)))
(defn set-errors!
[& args]
(st/emit! (apply set-errors args)))
[store & args]
(ptk/emit! store (apply set-errors args)))
;; --- Set Value
@ -155,8 +154,8 @@
(SetValue. type field value))
(defn set-value!
[type field value]
(st/emit! (set-value type field value)))
[store type field value]
(ptk/emit! store (set-value type field value)))
;; --- Validate Form
@ -195,8 +194,8 @@
(ClearForm. type))
(defn clear-form!
[type]
(st/emit! (clear-form type)))
[store type]
(ptk/emit! store (clear-form type)))
;; --- Clear Form
@ -211,24 +210,16 @@
(ClearErrors. type))
(defn clear-errors!
[type]
(st/emit! (clear-errors type)))
[store type]
(ptk/emit! store (clear-errors type)))
;; --- Clear
(defrecord Clear [type]
ptk/WatchEvent
(watch [_ state s]
(rx/of (clear-form type)
(clear-errors type))))
(defn clear
[type]
(Clear. type))
(defn clear!
[type]
(st/emit! (clear type)))
[store type]
(ptk/emit! store
(clear-form type)
(clear-errors type)))
;; --- Helpers
@ -257,15 +248,8 @@
(when (get errors field)
"invalid"))
(defn cleaner-fn
[type]
{:pre [(keyword? type)]}
(fn [own]
(clear! type)
own))
(defn clear-mixin
[type]
[store type]
{:will-unmount (fn [own]
(clear! type)
(clear! store type)
own)})

View file

@ -0,0 +1,152 @@
;; 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) 2016-2017 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.util.messages
"Messages notifications."
(:require [lentes.core :as l]
[cuerdas.core :as str]
[beicon.core :as rx]
[potok.core :as ptk]
[uxbox.main.ui.icons :as i]
[uxbox.util.timers :as ts]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.data :refer [classnames]]
[uxbox.util.dom :as dom]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Data Events
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; --- Constants
(def +animation-timeout+ 600)
;; --- Message Event
(declare hide)
(declare show?)
(deftype Show [data]
ptk/UpdateEvent
(update [_ state]
(let [message (assoc data :state :visible)]
(assoc state :message message)))
ptk/WatchEvent
(watch [_ state s]
(let [stoper (->> (rx/filter show? s)
(rx/take 1))]
(->> (rx/of (hide))
(rx/delay (:timeout data))
(rx/take-until stoper)))))
(defn show
[message]
(Show. message))
(defn show?
[v]
(instance? Show v))
(defn error
[message & {:keys [timeout] :or {timeout 3000}}]
(show {:content message
:type :error
:timeout timeout}))
(defn info
[message & {:keys [timeout] :or {timeout 3000}}]
(show {:content message
:type :info
:timeout timeout}))
(defn dialog
[message & {:keys [on-accept on-cancel]}]
(show {:content message
:on-accept on-accept
:on-cancel on-cancel
:timeout js/Number.MAX_SAFE_INTEGER
:type :dialog}))
;; --- Hide Message
(deftype Hide [^:mutable canceled?]
ptk/UpdateEvent
(update [_ state]
(update state :message
(fn [v]
(if (nil? v)
(do (set! canceled? true) nil)
(assoc v :state :hide)))))
ptk/WatchEvent
(watch [_ state stream]
(if canceled?
(rx/empty)
(->> (rx/of #(dissoc state :message))
(rx/delay +animation-timeout+)))))
(defn hide
[]
(Hide. false))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; UI Components
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; --- Notification Component
(mx/defc notification-box
{:mixins [mx/static]}
[{:keys [type on-close] :as message}]
(let [classes (classnames :error (= type :error)
:info (= type :info)
:hide-message (= (:state message) :hide)
:quick true)]
[:div.message {:class classes}
[:div.message-body
[:span.close {:on-click on-close} i/close]
[:span (:content message)]]]))
;; --- Dialog Component
(mx/defc dialog-box
{:mixins [mx/static mx/reactive]}
[{:keys [on-accept on-cancel on-close] :as message}]
(let [classes (classnames :info true
:hide-message (= (:state message) :hide))]
(letfn [(accept [event]
(dom/prevent-default event)
(on-accept)
(ts/schedule 0 on-close))
(cancel [event]
(dom/prevent-default event)
(when on-cancel
(on-cancel))
(ts/schedule 0 on-close))]
[:div.message {:class classes}
[:div.message-body
[:span.close {:on-click cancel} i/close]
[:span (:content message)]
[:div.message-action
[:a.btn-transparent.btn-small
{:on-click accept}
"Accept"]
[:a.btn-transparent.btn-small
{:on-click cancel}
"Cancel"]]]])))
;; --- Main Component (entry point)
(mx/defc messages-widget
{:mixins [mx/static mx/reactive]}
[message]
(case (:type message)
:error (notification-box message)
:info (notification-box message)
:dialog (dialog-box message)
nil))

View file

@ -13,7 +13,7 @@
(:require [beicon.core :as rx]))
(defonce lock (atom ::none))
(defonce stream (rx/bus))
(defonce stream (rx/subject))
(defn acquire!
([type]

View file

@ -2,22 +2,19 @@
;; 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-2016 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.util.router
(:require [bide.core :as r]
[beicon.core :as rx]
[potok.core :as ptk]
[uxbox.store :as st]))
(enable-console-print!)
[uxbox.main.store :as st]))
(defonce +router+ nil)
;; --- Update Location (Event)
(defrecord UpdateLocation [id params]
(deftype UpdateLocation [id params]
ptk/UpdateEvent
(update [_ state]
(let [route (merge {:id id}
@ -35,7 +32,7 @@
;; --- Navigate (Event)
(defrecord Navigate [id params]
(deftype Navigate [id params]
ptk/EffectEvent
(effect [_ state stream]
(r/navigate! +router+ id params)))
@ -49,22 +46,16 @@
;; --- Public Api
(defn init
([routes]
(init routes nil))
([routes {:keys [default] :or {default :auth/login}}]
(let [opts {:on-navigate #(st/emit! (update-location %1 %2))
([store routes]
(init store routes nil))
([store routes {:keys [default] :or {default :auth/login}}]
(let [opts {:on-navigate #(ptk/emit! store (update-location %1 %2))
:default default}
router (-> (r/router routes)
(r/start! opts))]
(set! +router+ router)
router)))
(defn go
"Redirect the user to other url."
([id] (go id nil))
([id params]
(st/emit! (navigate id params))))
(defn route-for
"Given a location handler and optional parameter map, return the URI
for such handler and parameters."

View file

@ -2,24 +2,15 @@
;; 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) 2016 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2016-2017 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.view
(:require [uxbox.config]
[uxbox.store :as st]
[uxbox.view.store :as st]
[uxbox.view.ui :as ui]))
(defn- initial-state
[]
{:route nil
:project nil
:pages nil
:page nil
:flags #{:sitemap}
:shapes {}})
(defn ^:export init
[]
(st/init initial-state)
(st/init)
(ui/init-routes)
(ui/init))

View file

@ -0,0 +1,77 @@
;; 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 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.util.router
(:require [bide.core :as r]
[beicon.core :as rx]
[potok.core :as ptk]
[uxbox.main.store :as st]))
(enable-console-print!)
(defonce +router+ nil)
;; --- Update Location (Event)
(deftype UpdateLocation [id params]
ptk/UpdateEvent
(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
[name params]
(UpdateLocation. name params))
;; --- Navigate (Event)
(deftype Navigate [id params]
ptk/EffectEvent
(effect [_ state stream]
(r/navigate! +router+ id params)))
(defn navigate
([id] (navigate id nil))
([id params]
{:pre [(keyword? id)]}
(Navigate. id params)))
;; --- Public Api
(defn init
([routes]
(init routes nil))
([routes {:keys [default] :or {default :auth/login}}]
(let [opts {:on-navigate #(st/emit! (update-location %1 %2))
:default default}
router (-> (r/router routes)
(r/start! opts))]
(set! +router+ router)
router)))
(defn go
"Redirect the user to other url."
([id] (go id nil))
([id params]
(st/emit! (navigate id params))))
(defn route-for
"Given a location handler and optional parameter map, return the URI
for such handler and parameters."
([id]
(if +router+
(r/resolve +router+ id)
""))
([id params]
(if +router+
(r/resolve +router+ id params)
"")))

View file

@ -4,13 +4,11 @@
;;
;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.store
(ns uxbox.view.store
(:require [beicon.core :as rx]
[lentes.core :as l]
[potok.core :as ptk]))
(enable-console-print!)
(def ^:dynamic *on-error* identity)
(defonce state (atom {}))
@ -28,9 +26,17 @@
([event & events]
(apply ptk/emit! store (cons event events))))
(defn- initial-state
[]
{:route nil
:project nil
:pages nil
:page nil
:flags #{:sitemap}
:shapes {}})
(defn init
"Initialize the state materialization."
[initial-state]
(let [istate (if (fn? initial-state) (initial-state) initial-state)]
(emit! (constantly istate))
(rx/to-atom store state)))
[]
(emit! initial-state)
(rx/to-atom store state))

View file

@ -2,20 +2,19 @@
;; 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) 2016 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2016-2017 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.view.ui
(:require [lentes.core :as l]
[uxbox.util.i18n :refer (tr)]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.data.messages :as dmsg]
[uxbox.main.ui.loader :refer (loader)]
[uxbox.main.ui.lightbox :refer (lightbox)]
[uxbox.main.ui.icons :as i]
[uxbox.view.ui.notfound :refer (notfound-page)]
[uxbox.view.ui.viewer :refer (viewer-page)]
[uxbox.view.store :as st]
[uxbox.view.ui.loader :refer [loader]]
[uxbox.view.ui.notfound :refer [notfound-page]]
[uxbox.view.ui.viewer :refer [viewer-page]]
[uxbox.util.i18n :refer [tr]]
[uxbox.util.router :as rt]
[uxbox.util.messages :as uum]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.dom :as dom]))
@ -31,13 +30,13 @@
;; Network error
(= (:status error) 0)
(do
(dmsg/error! (tr "errors.network"))
(st/emit! (uum/error (tr "errors.network")))
(js/console.error "Stack:" (.-stack error)))
;; Something else
:else
(do
(dmsg/error! (tr "errors.generic"))
(st/emit! (uum/error (tr "errors.generic")))
(js/console.error "Stack:" (.-stack error)))))
(set! st/*on-error* on-error)
@ -64,10 +63,9 @@
(defn init-routes
[]
(rt/init routes {:default :view/notfound}))
(rt/init st/store routes {:default :view/notfound}))
(defn init
[]
(mx/mount (app) (dom/get-element "app"))
(mx/mount (lightbox) (dom/get-element "lightbox"))
(mx/mount (loader) (dom/get-element "loader")))

View file

@ -0,0 +1,19 @@
;; 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) 2016-2017 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.view.ui.loader
(:require [uxbox.main.ui.icons :as i]
[uxbox.view.store :as st]
[uxbox.util.mixins :as mx :include-macros true]))
;; --- Component
(mx/defc loader
{:mixins [mx/reactive mx/static]}
[]
(when (mx/react st/loader)
[:div.loader-content i/loader]))

View file

@ -12,7 +12,7 @@
[uxbox.util.router :as rt]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.main.ui.icons :as i]
[uxbox.store :as st]
[uxbox.view.store :as st]
[uxbox.view.data.viewer :as dv]
[uxbox.view.ui.viewer.nav :refer (nav)]
[uxbox.view.ui.viewer.canvas :refer (canvas)]

View file

@ -11,7 +11,7 @@
[rum.core :as rum]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.data :refer (parse-int)]
[uxbox.store :as st]
[uxbox.view.store :as st]
[uxbox.main.ui.shapes :as uus]
[uxbox.main.ui.icons :as i]
[uxbox.view.ui.viewer.shapes :as shapes]))

View file

@ -11,7 +11,7 @@
[uxbox.util.geom.point :as gpt]
[uxbox.util.timers :as ts]
[uxbox.main.geom :as geom]
[uxbox.store :as st]
[uxbox.view.store :as st]
[uxbox.view.data.viewer :as dv]
[vendor.snapsvg])
;; Documentation about available events:

View file

@ -8,7 +8,7 @@
(ns uxbox.view.ui.viewer.nav
(:require [uxbox.util.mixins :as mx :include-macros true]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.view.store :as st]
[uxbox.main.ui.icons :as i]
[uxbox.view.data.viewer :as dv]))

View file

@ -8,7 +8,7 @@
(:require [goog.events :as events]
[lentes.core :as l]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.store :as st]
[uxbox.view.store :as st]
[uxbox.main.geom :as geom]
[uxbox.main.ui.shapes.rect :refer (rect-shape)]
[uxbox.main.ui.shapes.icon :refer (icon-shape)]

View file

@ -12,7 +12,7 @@
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.data :refer (parse-int)]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.view.store :as st]
[uxbox.main.ui.icons :as i]
[uxbox.view.data.viewer :as dv]))