Merge pull request #1048 from penpot/niwinz-bugfixes-20210617

 Fix linter issues on frontend
This commit is contained in:
Andrés Moya 2021-06-18 11:25:49 +02:00 committed by GitHub
commit b994363972
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
265 changed files with 1992 additions and 3104 deletions

View File

@ -33,11 +33,20 @@ jobs:
# fallback to using the latest cache if no exact match is found # fallback to using the latest cache if no exact match is found
- v1-dependencies- - v1-dependencies-
# run backend lint - run:
name: common lint
working_directory: "./common"
command: "clj-kondo --parallel --lint src/"
- run:
name: frontend lint
working_directory: "./frontend"
command: "clj-kondo --parallel --lint src/"
- run: - run:
name: backend lint name: backend lint
working_directory: "./backend" working_directory: "./backend"
command: "clj-kondo --lint src/" command: "clj-kondo --parallel --lint src/"
# run backend test # run backend test
- run: - run:
@ -62,11 +71,6 @@ jobs:
JAVA_HOME: /usr/lib/jvm/openjdk16 JAVA_HOME: /usr/lib/jvm/openjdk16
PATH: /usr/local/nodejs/bin/:/usr/local/bin:/bin:/usr/bin:/usr/lib/jvm/openjdk16/bin PATH: /usr/local/nodejs/bin/:/usr/local/bin:/bin:/usr/bin:/usr/lib/jvm/openjdk16/bin
# - run:
# name: common lint
# working_directory: "./common"
# command: "clj-kondo --lint src/"
- run: - run:
working_directory: "./common" working_directory: "./common"
name: common tests name: common tests

View File

@ -1,14 +1,30 @@
{:lint-as {potok.core/reify clojure.core/reify {:lint-as
promesa.core/let clojure.core/let {promesa.core/let clojure.core/let
rumext.alpha/defc clojure.core/defn rumext.alpha/defc clojure.core/defn
app.common.data/export clojure.core/def rumext.alpha/fnc clojure.core/fn
app.db/with-atomic clojure.core/with-open} app.common.data/export clojure.core/def
app.db/with-atomic clojure.core/with-open}
:hooks :hooks
{:analyze-call {app.common.data/export hooks.export/export}} {:analyze-call
{app.common.data/export hooks.export/export
potok.core/reify hooks.export/potok-reify
cljs.core/specify! hooks.export/clojure-specify
app.util.services/defmethod hooks.export/service-defmethod
}}
:output :output
{:exclude-files ["data_readers.clj"]} {:exclude-files
["data_readers.clj"
"app/util/perf.cljs"
"app/common/exceptions.cljc"
"app/util/import/.*"
"app/worker/export.cljs"
"app/worker/import.cljs"
"app/libs/.*"
"app/main/data/workspace/path/selection.cljs"
"app/main/data/workspace/transforms.cljs"
]}
:linters :linters
{:unsorted-required-namespaces {:unsorted-required-namespaces
@ -21,12 +37,12 @@
:single-key-in :single-key-in
{:level :warning} {:level :warning}
:redundant-do
{:level :off}
:unused-binding :unused-binding
{:exclude-destructured-as true {:exclude-destructured-as true
:exclude-destructured-keys-in-fn-args false :exclude-destructured-keys-in-fn-args false
} }
}}
:unresolved-symbol
{:exclude ['(app.util.services/defmethod)
]}}}

View File

@ -9,3 +9,41 @@
(api/token-node (symbol (name (:value sname)))) (api/token-node (symbol (name (:value sname))))
sname])] sname])]
{:node result})) {:node result}))
(defn potok-reify
[{:keys [:node]}]
(let [[rnode rtype & other] (:children node)
result (api/list-node
(into [(api/token-node (symbol "deftype"))
(api/token-node (gensym (name (:k rtype))))
(api/vector-node [])]
other))]
{:node result}))
(defn clojure-specify
[{:keys [:node]}]
(let [[rnode rtype & other] (:children node)
result (api/list-node
(into [(api/token-node (symbol "extend-type"))
(api/token-node (gensym (:string-value rtype)))]
other))]
{:node result}))
(defn service-defmethod
[{:keys [:node]}]
(let [[rnode rtype & other] (:children node)
rsym (gensym (name (:k rtype)))
result (api/list-node
[(api/token-node (symbol "do"))
(api/list-node
[(api/token-node (symbol "declare"))
(api/token-node rsym)])
(api/list-node
(into [(api/token-node (symbol "defmethod"))
(api/token-node rsym)
rtype]
other))])]
{:node result}))

View File

@ -169,7 +169,7 @@
(s/keys :req-un [::profile-id ::file-id ::library-id])) (s/keys :req-un [::profile-id ::file-id ::library-id]))
(sv/defmethod ::unlink-file-from-library (sv/defmethod ::unlink-file-from-library
[{:keys [pool] :as cfg} {:keys [profile-id file-id library-id] :as params}] [{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(files/check-edition-permissions! conn profile-id file-id) (files/check-edition-permissions! conn profile-id file-id)
(unlink-file-from-library conn params))) (unlink-file-from-library conn params)))
@ -189,7 +189,7 @@
(s/keys :req-un [::profile-id ::file-id ::library-id])) (s/keys :req-un [::profile-id ::file-id ::library-id]))
(sv/defmethod ::update-sync (sv/defmethod ::update-sync
[{:keys [pool] :as cfg} {:keys [profile-id file-id library-id] :as params}] [{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(files/check-edition-permissions! conn profile-id file-id) (files/check-edition-permissions! conn profile-id file-id)
(update-sync conn params))) (update-sync conn params)))
@ -209,7 +209,7 @@
(s/keys :req-un [::profile-id ::file-id ::date])) (s/keys :req-un [::profile-id ::file-id ::date]))
(sv/defmethod ::ignore-sync (sv/defmethod ::ignore-sync
[{:keys [pool] :as cfg} {:keys [profile-id file-id date] :as params}] [{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(files/check-edition-permissions! conn profile-id file-id) (files/check-edition-permissions! conn profile-id file-id)
(ignore-sync conn params))) (ignore-sync conn params)))

View File

@ -48,7 +48,7 @@
:opt-un [::invitation-token])) :opt-un [::invitation-token]))
(sv/defmethod ::login-with-ldap {:auth false :rlimit :password} (sv/defmethod ::login-with-ldap {:auth false :rlimit :password}
[{:keys [pool session tokens] :as cfg} {:keys [email password invitation-token] :as params}] [{:keys [pool session tokens] :as cfg} params]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(let [info (authenticate params) (let [info (authenticate params)
cfg (assoc cfg :conn conn)] cfg (assoc cfg :conn conn)]

View File

@ -167,7 +167,7 @@
:opt-un [::name])) :opt-un [::name]))
(sv/defmethod ::duplicate-file (sv/defmethod ::duplicate-file
[{:keys [pool] :as cfg} {:keys [profile-id file-id name] :as params}] [{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(let [file (db/get-by-id conn :file file-id) (let [file (db/get-by-id conn :file file-id)
index {file-id (uuid/next)} index {file-id (uuid/next)}
@ -187,7 +187,7 @@
:opt-un [::name])) :opt-un [::name]))
(sv/defmethod ::duplicate-project (sv/defmethod ::duplicate-project
[{:keys [pool] :as cfg} {:keys [profile-id project-id name] :as params}] [{:keys [pool] :as cfg} {:keys [profile-id project-id] :as params}]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(let [project (db/get-by-id conn :project project-id)] (let [project (db/get-by-id conn :project project-id)]
(teams/check-edition-permissions! conn profile-id (:team-id project)) (teams/check-edition-permissions! conn profile-id (:team-id project))

View File

@ -131,8 +131,7 @@
:opt-un [::accept-newsletter-subscription])) :opt-un [::accept-newsletter-subscription]))
(sv/defmethod ::register-profile {:auth false :rlimit :password} (sv/defmethod ::register-profile {:auth false :rlimit :password}
[{:keys [pool tokens session] :as cfg} params] [{:keys [pool] :as cfg} params]
(when-not (:accept-terms-and-privacy params) (when-not (:accept-terms-and-privacy params)
(ex/raise :type :validation (ex/raise :type :validation
:code :invalid-terms-and-privacy)) :code :invalid-terms-and-privacy))
@ -292,7 +291,7 @@
:opt-un [::scope ::invitation-token])) :opt-un [::scope ::invitation-token]))
(sv/defmethod ::login {:auth false :rlimit :password} (sv/defmethod ::login {:auth false :rlimit :password}
[{:keys [pool session tokens] :as cfg} {:keys [email password scope] :as params}] [{:keys [pool session tokens] :as cfg} {:keys [email password] :as params}]
(letfn [(check-password [profile password] (letfn [(check-password [profile password]
(when (= (:password profile) "!") (when (= (:password profile) "!")
(ex/raise :type :validation (ex/raise :type :validation
@ -343,7 +342,7 @@
(s/keys :req-un [::profile-id])) (s/keys :req-un [::profile-id]))
(sv/defmethod ::logout (sv/defmethod ::logout
[{:keys [pool session] :as cfg} {:keys [profile-id] :as params}] [{:keys [session] :as cfg} _]
(with-meta {} (with-meta {}
{:transform-response (:delete session)})) {:transform-response (:delete session)}))
@ -376,7 +375,7 @@
(s/keys :req-un [::profile-id ::password ::old-password])) (s/keys :req-un [::profile-id ::password ::old-password]))
(sv/defmethod ::update-profile-password {:rlimit :password} (sv/defmethod ::update-profile-password {:rlimit :password}
[{:keys [pool] :as cfg} {:keys [password profile-id] :as params}] [{:keys [pool] :as cfg} {:keys [password] :as params}]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(let [profile (validate-password! conn params)] (let [profile (validate-password! conn params)]
(update-profile-password! conn (assoc profile :password password)) (update-profile-password! conn (assoc profile :password password))

View File

@ -232,7 +232,7 @@
(update data :objects update-objects))) (update data :objects update-objects)))
(sv/defmethod ::page (sv/defmethod ::page
[{:keys [pool] :as cfg} {:keys [profile-id file-id id strip-thumbnails]}] [{:keys [pool] :as cfg} {:keys [profile-id file-id strip-thumbnails]}]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(check-edition-permissions! conn profile-id file-id) (check-edition-permissions! conn profile-id file-id)
(let [cfg (assoc cfg :conn conn) (let [cfg (assoc cfg :conn conn)
@ -260,7 +260,7 @@
(s/keys :req-un [::profile-id ::team-id])) (s/keys :req-un [::profile-id ::team-id]))
(sv/defmethod ::shared-files (sv/defmethod ::shared-files
[{:keys [pool] :as cfg} {:keys [profile-id team-id] :as params}] [{:keys [pool] :as cfg} {:keys [team-id] :as params}]
(into [] decode-row-xf (db/exec! pool [sql:shared-files team-id]))) (into [] decode-row-xf (db/exec! pool [sql:shared-files team-id])))
@ -285,7 +285,7 @@
(s/keys :req-un [::profile-id ::team-id])) (s/keys :req-un [::profile-id ::team-id]))
(sv/defmethod ::team-shared-files (sv/defmethod ::team-shared-files
[{:keys [pool] :as cfg} {:keys [profile-id team-id] :as params}] [{:keys [pool] :as cfg} {:keys [team-id] :as params}]
(db/exec! pool [sql:team-shared-files team-id])) (db/exec! pool [sql:team-shared-files team-id]))

View File

@ -11,8 +11,8 @@
(:require-macros [app.common.data])) (:require-macros [app.common.data]))
(:require (:require
[app.common.math :as mth] [app.common.math :as mth]
[cljs.analyzer.api :as aapi]
[clojure.set :as set] [clojure.set :as set]
#?(:clj [cljs.analyzer.api :as aapi])
#?(:cljs [cljs.reader :as r] #?(:cljs [cljs.reader :as r]
:clj [clojure.edn :as r]) :clj [clojure.edn :as r])
#?(:cljs [cljs.core :as core] #?(:cljs [cljs.core :as core]
@ -275,7 +275,7 @@
;; Data Parsing / Conversion ;; Data Parsing / Conversion
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn- nan? (defn nan?
[v] [v]
(not= v v)) (not= v v))
@ -506,7 +506,7 @@
(defn- extract-numeric-suffix (defn- extract-numeric-suffix
[basename] [basename]
(if-let [[match p1 p2] (re-find #"(.*)-([0-9]+)$" basename)] (if-let [[_ p1 p2] (re-find #"(.*)-([0-9]+)$" basename)]
[p1 (+ 1 (parse-integer p2))] [p1 (+ 1 (parse-integer p2))]
[basename 1])) [basename 1]))

View File

@ -31,7 +31,7 @@
(defn str->matrix (defn str->matrix
[matrix-str] [matrix-str]
(let [params (->> (re-seq number-regex matrix-str) (let [params (->> (re-seq number-regex matrix-str)
(filter #(-> % first empty? not)) (filter #(-> % first seq))
(map (comp d/parse-double first)))] (map (comp d/parse-double first)))]
(apply matrix params))) (apply matrix params)))
@ -52,12 +52,11 @@
"Given two TRANSLATE matrixes (only e and f have significative "Given two TRANSLATE matrixes (only e and f have significative
values), combine them. Quicker than multiplying them, for this values), combine them. Quicker than multiplying them, for this
precise case." precise case."
([{m1a :a m1b :b m1c :c m1d :d m1e :e m1f :f} ([{m1e :e m1f :f} {m2e :e m2f :f}]
{m2a :a m2b :b m2c :c m2d :d m2e :e m2f :f}]
(Matrix. (Matrix.
1 1
0 0
0 0
1 1
(+ m1e m2e) (+ m1e m2e)
(+ m1f m2f))) (+ m1f m2f)))

View File

@ -32,13 +32,10 @@
(when verify? (when verify?
(us/assert ::spec/changes items)) (us/assert ::spec/changes items))
(let [pages (into #{} (map :page-id) items) (let [result (reduce #(or (process-change %1 %2) %1) data items)]
result (->> items
(reduce #(or (process-change %1 %2) %1) data))]
;; Validate result shapes (only on the backend) ;; Validate result shapes (only on the backend)
#?(:clj #?(:clj
(doseq [page-id pages] (doseq [page-id (into #{} (map :page-id) items)]
(let [page (get-in result [:pages-index page-id])] (let [page (get-in result [:pages-index page-id])]
(doseq [[id shape] (:objects page)] (doseq [[id shape] (:objects page)]
(when-not (= shape (get-in data [:pages-index page-id :objects id])) (when-not (= shape (get-in data [:pages-index page-id :objects id]))

View File

@ -395,11 +395,11 @@
:internal.media-object/mtype])) :internal.media-object/mtype]))
(s/def ::media-object-update (s/def ::media-object-update
(s/keys :req-un [::id] (s/keys :req-un [::id]
:req-opt [::name :opt-un [::name
:internal.media-object/width :internal.media-object/width
:internal.media-object/height :internal.media-object/height
:internal.media-object/mtype])) :internal.media-object/mtype]))
(s/def :internal.file/colors (s/def :internal.file/colors
(s/map-of ::uuid ::color)) (s/map-of ::uuid ::color))

View File

@ -15,11 +15,11 @@
;; NOTE: don't remove this, causes exception on advanced build ;; NOTE: don't remove this, causes exception on advanced build
;; because of some strange interaction with cljs.spec.alpha and ;; because of some strange interaction with cljs.spec.alpha and
;; modules spliting. ;; modules spliting.
[expound.alpha]
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[cuerdas.core :as str])) [cuerdas.core :as str]
[expound.alpha]))
(s/check-asserts true) (s/check-asserts true)

View File

@ -7,7 +7,7 @@
(ns app.common.uuid (ns app.common.uuid
(:refer-clojure :exclude [next uuid zero?]) (:refer-clojure :exclude [next uuid zero?])
(:require (:require
[app.common.data :as d] #?(:clj [app.common.data :as d])
#?(:clj [clj-uuid :as impl]) #?(:clj [clj-uuid :as impl])
#?(:clj [clojure.core :as c]) #?(:clj [clojure.core :as c])
#?(:cljs [app.common.uuid-impl :as impl]) #?(:cljs [app.common.uuid-impl :as impl])

View File

@ -6,9 +6,8 @@
(ns app.config (ns app.config
(:require (:require
[app.common.data :as d]
[app.common.uri :as u]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uri :as u]
[app.common.version :as v] [app.common.version :as v]
[app.util.avatars :as avatars] [app.util.avatars :as avatars]
[app.util.dom :as dom] [app.util.dom :as dom]

View File

@ -12,7 +12,6 @@
[app.main.data.events :as ev] [app.main.data.events :as ev]
[app.main.data.messages :as dm] [app.main.data.messages :as dm]
[app.main.data.users :as du] [app.main.data.users :as du]
[app.main.repo :as rp]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui :as ui] [app.main.ui :as ui]
[app.main.ui.confirm] [app.main.ui.confirm]
@ -21,11 +20,9 @@
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :as i18n] [app.util.i18n :as i18n]
[app.util.logging :as log] [app.util.logging :as log]
[app.util.object :as obj]
[app.util.router :as rt] [app.util.router :as rt]
[app.util.storage :refer [storage]] [app.util.storage :refer [storage]]
[app.util.theme :as theme] [app.util.theme :as theme]
[app.util.timers :as ts]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[potok.core :as ptk] [potok.core :as ptk]
@ -81,7 +78,7 @@
(defn initialize (defn initialize
[] []
(letfn [(on-profile [profile] (letfn [(on-profile [_profile]
(rx/of (rt/initialize-router ui/routes) (rx/of (rt/initialize-router ui/routes)
(rt/initialize-history on-navigate)))] (rt/initialize-history on-navigate)))]
(ptk/reify ::initialize (ptk/reify ::initialize
@ -90,7 +87,7 @@
(assoc state :session-id (uuid/next))) (assoc state :session-id (uuid/next)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(rx/merge (rx/merge
(rx/of (rx/of
(ptk/event ::ev/initialize) (ptk/event ::ev/initialize)

View File

@ -6,28 +6,11 @@
(ns app.main.data.comments (ns app.main.data.comments
(:require (:require
[cuerdas.core :as str]
[app.common.data :as d] [app.common.data :as d]
[app.common.exceptions :as ex]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as geom]
[app.common.math :as mth]
[app.common.pages :as cp]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid]
[app.config :as cfg]
[app.main.constants :as c]
[app.main.repo :as rp] [app.main.repo :as rp]
[app.main.store :as st]
[app.main.streams :as ms]
[app.main.worker :as uw]
[app.util.router :as rt]
[app.util.timers :as ts]
[app.util.webapi :as wapi]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[clojure.set :as set]
[potok.core :as ptk])) [potok.core :as ptk]))
(s/def ::content ::us/string) (s/def ::content ::us/string)
@ -91,7 +74,7 @@
(ptk/reify ::create-thread (ptk/reify ::create-thread
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation :create-comment-thread params) (->> (rp/mutation :create-comment-thread params)
(rx/mapcat #(rp/query :comment-thread {:file-id (:file-id %) :id (:id %)})) (rx/mapcat #(rp/query :comment-thread {:file-id (:file-id %) :id (:id %)}))
(rx/map #(partial created %))))))) (rx/map #(partial created %)))))))
@ -101,7 +84,7 @@
(us/assert ::comment-thread thread) (us/assert ::comment-thread thread)
(ptk/reify ::update-comment-thread-status (ptk/reify ::update-comment-thread-status
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [done #(d/update-in-when % [:comment-threads id] assoc :count-unread-comments 0)] (let [done #(d/update-in-when % [:comment-threads id] assoc :count-unread-comments 0)]
(->> (rp/mutation :update-comment-thread-status {:id id}) (->> (rp/mutation :update-comment-thread-status {:id id})
(rx/map (constantly done))))))) (rx/map (constantly done)))))))
@ -117,7 +100,7 @@
(d/update-in-when state [:comment-threads id] assoc :is-resolved is-resolved)) (d/update-in-when state [:comment-threads id] assoc :is-resolved is-resolved))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation :update-comment-thread {:id id :is-resolved is-resolved}) (->> (rp/mutation :update-comment-thread {:id id :is-resolved is-resolved})
(rx/ignore))))) (rx/ignore)))))
@ -130,7 +113,7 @@
(update-in state [:comments (:id thread)] assoc (:id comment) comment))] (update-in state [:comments (:id thread)] assoc (:id comment) comment))]
(ptk/reify ::create-comment (ptk/reify ::create-comment
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(rx/concat (rx/concat
(->> (rp/mutation :add-comment {:thread-id (:id thread) :content content}) (->> (rp/mutation :add-comment {:thread-id (:id thread) :content content})
(rx/map #(partial created %))) (rx/map #(partial created %)))
@ -145,7 +128,7 @@
(d/update-in-when state [:comments thread-id id] assoc :content content)) (d/update-in-when state [:comments thread-id id] assoc :content content))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation :update-comment {:id id :content content}) (->> (rp/mutation :update-comment {:id id :content content})
(rx/ignore))))) (rx/ignore)))))
@ -160,7 +143,7 @@
(update :comment-threads dissoc id))) (update :comment-threads dissoc id)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation :delete-comment-thread {:id id}) (->> (rp/mutation :delete-comment-thread {:id id})
(rx/ignore))))) (rx/ignore)))))
@ -173,7 +156,7 @@
(d/update-in-when state [:comments thread-id] dissoc id)) (d/update-in-when state [:comments thread-id] dissoc id))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation :delete-comment {:id id}) (->> (rp/mutation :delete-comment {:id id})
(rx/ignore))))) (rx/ignore)))))
@ -184,7 +167,7 @@
(assoc-in state [:comment-threads id] thread))] (assoc-in state [:comment-threads id] thread))]
(ptk/reify ::refresh-comment-thread (ptk/reify ::refresh-comment-thread
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :comment-thread {:file-id file-id :id id}) (->> (rp/query :comment-thread {:file-id file-id :id id})
(rx/map #(partial fetched %))))))) (rx/map #(partial fetched %)))))))
@ -195,7 +178,7 @@
(assoc state :comment-threads (d/index-by :id data)))] (assoc state :comment-threads (d/index-by :id data)))]
(ptk/reify ::retrieve-comment-threads (ptk/reify ::retrieve-comment-threads
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :comment-threads {:file-id file-id}) (->> (rp/query :comment-threads {:file-id file-id})
(rx/map #(partial fetched %))))))) (rx/map #(partial fetched %)))))))
@ -206,7 +189,7 @@
(update state :comments assoc thread-id (d/index-by :id comments)))] (update state :comments assoc thread-id (d/index-by :id comments)))]
(ptk/reify ::retrieve-comments (ptk/reify ::retrieve-comments
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :comments {:thread-id thread-id}) (->> (rp/query :comments {:thread-id thread-id})
(rx/map #(partial fetched %))))))) (rx/map #(partial fetched %)))))))
@ -216,7 +199,7 @@
(us/assert ::us/uuid team-id) (us/assert ::us/uuid team-id)
(ptk/reify ::retrieve-unread-comment-threads (ptk/reify ::retrieve-unread-comment-threads
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [fetched #(assoc %2 :comment-threads (d/index-by :id %1))] (let [fetched #(assoc %2 :comment-threads (d/index-by :id %1))]
(->> (rp/query :unread-comment-threads {:team-id team-id}) (->> (rp/query :unread-comment-threads {:team-id team-id})
(rx/map #(partial fetched %))))))) (rx/map #(partial fetched %)))))))
@ -320,7 +303,7 @@
(defn apply-filters (defn apply-filters
[cstate profile threads] [cstate profile threads]
(let [{:keys [show mode open]} cstate] (let [{:keys [show mode]} cstate]
(cond->> threads (cond->> threads
(= :pending show) (= :pending show)
(filter (comp not :is-resolved)) (filter (comp not :is-resolved))

View File

@ -7,23 +7,16 @@
(ns app.main.data.dashboard (ns app.main.data.dashboard
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.pages :as cp]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.repo :as rp]
[app.main.data.events :as ev]
[app.main.data.users :as du]
[app.main.data.fonts :as df] [app.main.data.fonts :as df]
[app.main.data.media :as di]
[app.main.data.users :as du]
[app.main.repo :as rp]
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.router :as rt] [app.util.router :as rt]
[app.util.time :as dt]
[app.util.timers :as ts]
[app.util.avatars :as avatars]
[app.main.data.media :as di]
[app.main.data.messages :as dm]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[cuerdas.core :as str]
[potok.core :as ptk])) [potok.core :as ptk]))
;; --- Specs ;; --- Specs
@ -44,13 +37,13 @@
::modified-at])) ::modified-at]))
(s/def ::project (s/def ::project
(s/keys ::req-un [::id (s/keys :req-un [::id
::name ::name
::team-id ::team-id
::profile-id ::profile-id
::created-at ::created-at
::modified-at ::modified-at
::is-pinned])) ::is-pinned]))
(s/def ::file (s/def ::file
(s/keys :req-un [::id (s/keys :req-un [::id
@ -109,7 +102,7 @@
[] []
(ptk/reify ::fetch-team-members (ptk/reify ::fetch-team-members
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(->> (rp/query :team-members {:team-id team-id}) (->> (rp/query :team-members {:team-id team-id})
(rx/map team-members-fetched)))))) (rx/map team-members-fetched))))))
@ -127,7 +120,7 @@
[] []
(ptk/reify ::fetch-team-stats (ptk/reify ::fetch-team-stats
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(->> (rp/query :team-stats {:team-id team-id}) (->> (rp/query :team-stats {:team-id team-id})
(rx/map team-stats-fetched)))))) (rx/map team-stats-fetched))))))
@ -146,7 +139,7 @@
[] []
(ptk/reify ::fetch-projects (ptk/reify ::fetch-projects
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(->> (rp/query :projects {:team-id team-id}) (->> (rp/query :projects {:team-id team-id})
(rx/map projects-fetched)))))) (rx/map projects-fetched))))))
@ -173,7 +166,7 @@
(dissoc state :dashboard-search-result)) (dissoc state :dashboard-search-result))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state) (let [team-id (:current-team-id state)
params (assoc params :team-id team-id)] params (assoc params :team-id team-id)]
(->> (rp/query :search-files params) (->> (rp/query :search-files params)
@ -202,7 +195,7 @@
(us/assert ::us/uuid project-id) (us/assert ::us/uuid project-id)
(ptk/reify ::fetch-files (ptk/reify ::fetch-files
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :project-files {:project-id project-id}) (->> (rp/query :project-files {:project-id project-id})
(rx/map #(files-fetched project-id %)))))) (rx/map #(files-fetched project-id %))))))
@ -219,7 +212,7 @@
[] []
(ptk/reify ::fetch-shared-files (ptk/reify ::fetch-shared-files
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(->> (rp/query :team-shared-files {:team-id team-id}) (->> (rp/query :team-shared-files {:team-id team-id})
(rx/map shared-files-fetched)))))) (rx/map shared-files-fetched))))))
@ -240,7 +233,7 @@
[] []
(ptk/reify ::fetch-recent-files (ptk/reify ::fetch-recent-files
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(->> (rp/query :team-recent-files {:team-id team-id}) (->> (rp/query :team-recent-files {:team-id team-id})
(rx/map recent-files-fetched)))))) (rx/map recent-files-fetched))))))
@ -293,7 +286,7 @@
(us/assert string? name) (us/assert string? name)
(ptk/reify ::create-team (ptk/reify ::create-team
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params)] on-error rx/throw}} (meta params)]
@ -313,7 +306,7 @@
(assoc-in state [:teams id :name] name)) (assoc-in state [:teams id :name] name))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation! :update-team params) (->> (rp/mutation! :update-team params)
(rx/ignore))))) (rx/ignore)))))
@ -322,7 +315,7 @@
(us/assert ::di/file file) (us/assert ::di/file file)
(ptk/reify ::update-team-photo (ptk/reify ::update-team-photo
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [on-success di/notify-finished-loading (let [on-success di/notify-finished-loading
on-error #(do (di/notify-finished-loading) on-error #(do (di/notify-finished-loading)
(di/process-error %)) (di/process-error %))
@ -344,7 +337,7 @@
(us/assert ::us/keyword role) (us/assert ::us/keyword role)
(ptk/reify ::update-team-member-role (ptk/reify ::update-team-member-role
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state) (let [team-id (:current-team-id state)
params (assoc params :team-id team-id)] params (assoc params :team-id team-id)]
(->> (rp/mutation! :update-team-member-role params) (->> (rp/mutation! :update-team-member-role params)
@ -357,7 +350,7 @@
(us/assert ::us/uuid member-id) (us/assert ::us/uuid member-id)
(ptk/reify ::delete-team-member (ptk/reify ::delete-team-member
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state) (let [team-id (:current-team-id state)
params (assoc params :team-id team-id)] params (assoc params :team-id team-id)]
(->> (rp/mutation! :delete-team-member params) (->> (rp/mutation! :delete-team-member params)
@ -370,7 +363,7 @@
(us/assert (s/nilable ::us/uuid) reassign-to) (us/assert (s/nilable ::us/uuid) reassign-to)
(ptk/reify ::leave-team (ptk/reify ::leave-team
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params) on-error rx/throw}} (meta params)
@ -391,7 +384,7 @@
(us/assert ::us/keyword role) (us/assert ::us/keyword role)
(ptk/reify ::invite-team-member (ptk/reify ::invite-team-member
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params) on-error rx/throw}} (meta params)
@ -408,7 +401,7 @@
(us/assert ::team params) (us/assert ::team params)
(ptk/reify ::delete-team (ptk/reify ::delete-team
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params)] on-error rx/throw}} (meta params)]
@ -434,7 +427,7 @@
[] []
(ptk/reify ::create-project (ptk/reify ::create-project
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [name (name (gensym (str (tr "dashboard.new-project-prefix") " "))) (let [name (name (gensym (str (tr "dashboard.new-project-prefix") " ")))
team-id (:current-team-id state) team-id (:current-team-id state)
params {:name name params {:name name
@ -461,7 +454,7 @@
(us/assert ::us/uuid id) (us/assert ::us/uuid id)
(ptk/reify ::duplicate-project (ptk/reify ::duplicate-project
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params) on-error rx/throw}} (meta params)
@ -480,7 +473,7 @@
(us/assert ::us/uuid team-id) (us/assert ::us/uuid team-id)
(ptk/reify ::move-project (ptk/reify ::move-project
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params)] on-error rx/throw}} (meta params)]
@ -491,7 +484,7 @@
(rx/catch on-error)))))) (rx/catch on-error))))))
(defn toggle-project-pin (defn toggle-project-pin
[{:keys [id is-pinned team-id] :as project}] [{:keys [id is-pinned] :as project}]
(us/assert ::project project) (us/assert ::project project)
(ptk/reify ::toggle-project-pin (ptk/reify ::toggle-project-pin
ptk/UpdateEvent ptk/UpdateEvent
@ -499,7 +492,7 @@
(assoc-in state [:dashboard-projects id :is-pinned] (not is-pinned))) (assoc-in state [:dashboard-projects id :is-pinned] (not is-pinned)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [project (get-in state [:dashboard-projects id]) (let [project (get-in state [:dashboard-projects id])
params (select-keys project [:id :is-pinned :team-id])] params (select-keys project [:id :is-pinned :team-id])]
(->> (rp/mutation :update-project-pin params) (->> (rp/mutation :update-project-pin params)
@ -508,7 +501,7 @@
;; --- EVENT: rename-project ;; --- EVENT: rename-project
(defn rename-project (defn rename-project
[{:keys [id name team-id] :as params}] [{:keys [id name] :as params}]
(us/assert ::project params) (us/assert ::project params)
(ptk/reify ::rename-project (ptk/reify ::rename-project
ptk/UpdateEvent ptk/UpdateEvent
@ -518,7 +511,7 @@
(update :dashboard-local dissoc :project-for-edit))) (update :dashboard-local dissoc :project-for-edit)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [params {:id id :name name}] (let [params {:id id :name name}]
(->> (rp/mutation :rename-project params) (->> (rp/mutation :rename-project params)
(rx/ignore)))))) (rx/ignore))))))
@ -526,7 +519,7 @@
;; --- EVENT: delete-project ;; --- EVENT: delete-project
(defn delete-project (defn delete-project
[{:keys [id team-id] :as params}] [{:keys [id] :as params}]
(us/assert ::project params) (us/assert ::project params)
(ptk/reify ::delete-project (ptk/reify ::delete-project
ptk/UpdateEvent ptk/UpdateEvent
@ -534,14 +527,14 @@
(update state :dashboard-projects dissoc id)) (update state :dashboard-projects dissoc id))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state s] (watch [_ _ _]
(->> (rp/mutation :delete-project {:id id}) (->> (rp/mutation :delete-project {:id id})
(rx/ignore))))) (rx/ignore)))))
;; --- EVENT: delete-file ;; --- EVENT: delete-file
(defn file-deleted (defn file-deleted
[team-id project-id] [_team-id project-id]
(ptk/reify ::file-deleted (ptk/reify ::file-deleted
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
@ -558,7 +551,7 @@
(d/update-when :dashboard-recent-files dissoc id))) (d/update-when :dashboard-recent-files dissoc id)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state s] (watch [_ state _]
(let [team-id (uuid/uuid (get-in state [:route :path-params :team-id]))] (let [team-id (uuid/uuid (get-in state [:route :path-params :team-id]))]
(->> (rp/mutation :delete-file {:id id}) (->> (rp/mutation :delete-file {:id id})
(rx/map #(file-deleted team-id project-id))))))) (rx/map #(file-deleted team-id project-id)))))))
@ -576,7 +569,7 @@
(d/update-in-when [:dashboard-recent-files id :name] (constantly name)))) (d/update-in-when [:dashboard-recent-files id :name] (constantly name))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [params (select-keys params [:id :name])] (let [params (select-keys params [:id :name])]
(->> (rp/mutation :rename-file params) (->> (rp/mutation :rename-file params)
(rx/ignore)))))) (rx/ignore))))))
@ -594,7 +587,7 @@
(d/update-in-when [:dashboard-recent-files id :is-shared] (constantly is-shared)))) (d/update-in-when [:dashboard-recent-files id :is-shared] (constantly is-shared))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [params {:id id :is-shared is-shared}] (let [params {:id id :is-shared is-shared}]
(->> (rp/mutation :set-file-shared params) (->> (rp/mutation :set-file-shared params)
(rx/ignore)))))) (rx/ignore))))))
@ -621,7 +614,7 @@
(us/assert ::us/uuid project-id) (us/assert ::us/uuid project-id)
(ptk/reify ::create-file (ptk/reify ::create-file
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params) on-error rx/throw}} (meta params)
@ -642,7 +635,7 @@
(us/assert ::name name) (us/assert ::name name)
(ptk/reify ::duplicate-file (ptk/reify ::duplicate-file
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params) on-error rx/throw}} (meta params)
@ -663,7 +656,7 @@
(us/assert ::us/uuid project-id) (us/assert ::us/uuid project-id)
(ptk/reify ::move-files (ptk/reify ::move-files
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error rx/throw}} (meta params)] on-error rx/throw}} (meta params)]
@ -682,7 +675,7 @@
(us/assert ::file file) (us/assert ::file file)
(ptk/reify ::go-to-workspace (ptk/reify ::go-to-workspace
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [pparams {:project-id project-id :file-id id}] (let [pparams {:project-id project-id :file-id id}]
(rx/of (rt/nav :workspace pparams)))))) (rx/of (rt/nav :workspace pparams))))))
@ -691,14 +684,14 @@
([project-id] ([project-id]
(ptk/reify ::go-to-files (ptk/reify ::go-to-files
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(rx/of (rt/nav :dashboard-files {:team-id team-id (rx/of (rt/nav :dashboard-files {:team-id team-id
:project-id project-id})))))) :project-id project-id}))))))
([team-id project-id] ([team-id project-id]
(ptk/reify ::go-to-files (ptk/reify ::go-to-files
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(rx/of (rt/nav :dashboard-files {:team-id team-id (rx/of (rt/nav :dashboard-files {:team-id team-id
:project-id project-id})))))) :project-id project-id}))))))
@ -707,7 +700,7 @@
([term] ([term]
(ptk/reify ::go-to-search (ptk/reify ::go-to-search
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(if (empty? term) (if (empty? term)
(rx/of (rt/nav :dashboard-search (rx/of (rt/nav :dashboard-search
@ -720,13 +713,13 @@
([] ([]
(ptk/reify ::go-to-projects (ptk/reify ::go-to-projects
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(rx/of (rt/nav :dashboard-projects {:team-id team-id})))))) (rx/of (rt/nav :dashboard-projects {:team-id team-id}))))))
([team-id] ([team-id]
(ptk/reify ::go-to-projects (ptk/reify ::go-to-projects
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(du/set-current-team! team-id) (du/set-current-team! team-id)
(rx/of (rt/nav :dashboard-projects {:team-id team-id})))))) (rx/of (rt/nav :dashboard-projects {:team-id team-id}))))))
@ -734,7 +727,7 @@
[] []
(ptk/reify ::go-to-team-members (ptk/reify ::go-to-team-members
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(rx/of (rt/nav :dashboard-team-members {:team-id team-id})))))) (rx/of (rt/nav :dashboard-team-members {:team-id team-id}))))))
@ -742,6 +735,6 @@
[] []
(ptk/reify ::go-to-team-settings (ptk/reify ::go-to-team-settings
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(rx/of (rt/nav :dashboard-team-settings {:team-id team-id})))))) (rx/of (rt/nav :dashboard-team-settings {:team-id team-id}))))))

View File

@ -8,14 +8,14 @@
(:require (:require
["ua-parser-js" :as UAParser] ["ua-parser-js" :as UAParser]
[app.common.data :as d] [app.common.data :as d]
[app.main.repo :as rp]
[app.config :as cf] [app.config :as cf]
[app.main.repo :as rp]
[app.util.globals :as g] [app.util.globals :as g]
[app.util.http :as http] [app.util.http :as http]
[app.util.i18n :as i18n]
[app.util.object :as obj] [app.util.object :as obj]
[app.util.storage :refer [storage]] [app.util.storage :refer [storage]]
[app.util.time :as dt] [app.util.time :as dt]
[app.util.i18n :as i18n]
[beicon.core :as rx] [beicon.core :as rx]
[lambdaisland.uri :as u] [lambdaisland.uri :as u]
[potok.core :as ptk])) [potok.core :as ptk]))
@ -139,7 +139,7 @@
:project-id (:project-id data)}})) :project-id (:project-id data)}}))
(defn- event->generic-action (defn- event->generic-action
[event name] [_ name]
{:type "action" {:type "action"
:name name :name name
:props {}}) :props {}})
@ -176,7 +176,7 @@
[_ {:keys [buffer] :as params}] [_ {:keys [buffer] :as params}]
(ptk/reify ::persistence (ptk/reify ::persistence
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ state _]
(let [profile-id (:profile-id state) (let [profile-id (:profile-id state)
events (into [] (take max-buffer-size) @buffer)] events (into [] (take max-buffer-size) @buffer)]
(when (seq events) (when (seq events)
@ -191,7 +191,7 @@
(let [buffer (atom #queue [])] (let [buffer (atom #queue [])]
(ptk/reify ::initialize (ptk/reify ::initialize
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(->> (rx/merge (->> (rx/merge
(->> (rx/from-atom buffer) (->> (rx/from-atom buffer)
(rx/filter #(pos? (count %))) (rx/filter #(pos? (count %)))
@ -202,7 +202,7 @@
(rx/map #(ptk/event ::persistence {:buffer buffer})))) (rx/map #(ptk/event ::persistence {:buffer buffer}))))
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ _ stream]
(let [events (methods process-event) (let [events (methods process-event)
session (atom nil) session (atom nil)

View File

@ -8,16 +8,14 @@
(:require (:require
["opentype.js" :as ot] ["opentype.js" :as ot]
[app.common.data :as d] [app.common.data :as d]
[app.common.spec :as us]
[app.common.media :as cm] [app.common.media :as cm]
[app.common.spec :as us]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.fonts :as fonts] [app.main.fonts :as fonts]
[app.main.repo :as rp] [app.main.repo :as rp]
[app.util.i18n :as i18n :refer [tr]]
[app.util.logging :as log] [app.util.logging :as log]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[app.util.webapi :as wa] [app.util.webapi :as wa]
[beicon.core :as rx]
[cuerdas.core :as str] [cuerdas.core :as str]
[potok.core :as ptk])) [potok.core :as ptk]))
@ -62,7 +60,7 @@
(assoc state :dashboard-fonts (d/index-by :id fonts))) (assoc state :dashboard-fonts (d/index-by :id fonts)))
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ _ _]
(let [fonts (->> fonts (let [fonts (->> fonts
(map adapt-font-id) (map adapt-font-id)
(group-by :font-id) (group-by :font-id)
@ -73,7 +71,7 @@
[team-id] [team-id]
(ptk/reify ::load-team-fonts (ptk/reify ::load-team-fonts
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :font-variants {:team-id team-id}) (->> (rp/query :font-variants {:team-id team-id})
(rx/map fonts-fetched))))) (rx/map fonts-fetched)))))
@ -121,7 +119,7 @@
(parse-font [{:keys [data] :as params}] (parse-font [{:keys [data] :as params}]
(try (try
(assoc params :font (ot/parse data)) (assoc params :font (ot/parse data))
(catch :default e (catch :default _e
(log/warn :msg (str/fmt "skiping file %s, unsupported format" (:name params))) (log/warn :msg (str/fmt "skiping file %s, unsupported format" (:name params)))
nil))) nil)))
@ -204,7 +202,7 @@
fonts)))) fonts))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(->> (rp/mutation! :update-font {:id id :name name :team-id team-id}) (->> (rp/mutation! :update-font {:id id :name name :team-id team-id})
(rx/ignore)))))) (rx/ignore))))))
@ -218,10 +216,10 @@
(update [_ state] (update [_ state]
(update state :dashboard-fonts (update state :dashboard-fonts
(fn [variants] (fn [variants]
(d/removem (fn [[id variant]] (d/removem (fn [[_id variant]]
(= (:font-id variant) font-id)) variants)))) (= (:font-id variant) font-id)) variants))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(->> (rp/mutation! :delete-font {:id font-id :team-id team-id}) (->> (rp/mutation! :delete-font {:id font-id :team-id team-id})
(rx/ignore)))))) (rx/ignore))))))
@ -238,7 +236,7 @@
(= (:id variant) id)) (= (:id variant) id))
variants)))) variants))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(->> (rp/mutation! :delete-font-variant {:id id :team-id team-id}) (->> (rp/mutation! :delete-font-variant {:id id :team-id team-id})
(rx/ignore)))))) (rx/ignore))))))

View File

@ -1,270 +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) UXBOX Labs SL
(ns app.main.data.history
(:require
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[potok.core :as ptk]
[app.common.spec :as us]
[app.common.pages :as cp]
[app.main.repo :as rp]
[app.util.data :refer [replace-by-id index-by]]))
;; --- Schema
(s/def ::pinned boolean?)
(s/def ::id uuid?)
(s/def ::label string?)
(s/def ::project uuid?)
(s/def ::created-at inst?)
(s/def ::modified-at inst?)
(s/def ::version number?)
(s/def ::user uuid?)
(s/def ::shapes
(s/every ::cp/minimal-shape :kind vector?))
(s/def ::data
(s/keys :req-un [::shapes]))
(s/def ::history-entry
(s/keys :req-un [::id
::pinned
::label
::project
::created-at
::modified-at
::version
::user
::data]))
(s/def ::history-entries
(s/every ::history-entry))
;; --- Initialize History State
(declare fetch-history)
(declare fetch-pinned-history)
(defn initialize
[id]
(us/verify ::us/uuid id)
(ptk/reify ::initialize
ptk/UpdateEvent
(update [_ state]
(update-in state [:workspace id]
assoc :history {:selected nil
:pinned #{}
:items #{}
:byver {}}))
ptk/WatchEvent
(watch [_ state stream]
(rx/of (fetch-history id)
(fetch-pinned-history id)))))
;; --- Watch Page Changes
(defn watch-page-changes
[id]
(us/verify ::us/uuid id)
(reify
ptk/WatchEvent
(watch [_ state stream]
#_(let [stopper (rx/filter #(= % ::stop-page-watcher) stream)]
(->> stream
(rx/filter dp/page-persisted?)
(rx/debounce 1000)
(rx/flat-map #(rx/of (fetch-history id)
(fetch-pinned-history id)))
(rx/take-until stopper))))))
;; --- Pinned Page History Fetched
(defn pinned-history-fetched
[items]
(us/verify ::history-entries items)
(ptk/reify ::pinned-history-fetched
ptk/UpdateEvent
(update [_ state]
(let [pid (get-in state [:workspace :current])
items-map (index-by :version items)
items-set (into #{} items)]
(update-in state [:workspace pid :history]
(fn [history]
(-> history
(assoc :pinned items-set)
(update :byver merge items-map))))))))
;; --- Fetch Pinned Page History
(defn fetch-pinned-history
[id]
(us/verify ::us/uuid id)
(ptk/reify ::fetch-pinned-history
ptk/WatchEvent
(watch [_ state s]
(let [params {:page id :pinned true}]
#_(->> (rp/req :fetch/page-history params)
(rx/map :payload)
(rx/map pinned-history-fetched))))))
;; --- Page History Fetched
(defn history-fetched
[items]
(us/verify ::history-entries items)
(ptk/reify ::history-fetched
ptk/UpdateEvent
(update [_ state]
(let [pid (get-in state [:workspace :current])
versions (into #{} (map :version) items)
items-map (index-by :version items)
min-version (apply min versions)
max-version (apply max versions)]
(update-in state [:workspace pid :history]
(fn [history]
(-> history
(assoc :min-version min-version)
(assoc :max-version max-version)
(update :byver merge items-map)
(update :items #(reduce conj % items)))))))))
;; --- Fetch Page History
(defn fetch-history
([id]
(fetch-history id nil))
([id {:keys [since max]}]
(us/verify ::us/uuid id)
(ptk/reify ::fetch-history
ptk/WatchEvent
(watch [_ state s]
(let [params (merge {:page id
:max (or max 20)}
(when since
{:since since}))]
#_(->> (rp/req :fetch/page-history params)
(rx/map :payload)
(rx/map history-fetched)))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Context Aware Events
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; --- Select Section
(deftype SelectSection [section]
ptk/UpdateEvent
(update [_ state]
(assoc-in state [:workspace :history :section] section)))
(defn select-section
[section]
{:pre [(keyword? section)]}
(SelectSection. section))
;; --- Load More
(def load-more
(ptk/reify ::load-more
ptk/WatchEvent
(watch [_ state stream]
(let [pid (get-in state [:workspace :current])
since (get-in state [:workspace pid :history :min-version])]
(rx/of (fetch-history pid {:since since}))))))
;; --- Select Page History
(defn select
[version]
(us/verify int? version)
(ptk/reify ::select
ptk/UpdateEvent
(update [_ state]
#_(let [pid (get-in state [:workspace :current])
item (get-in state [:workspace pid :history :byver version])
page (-> (get-in state [:pages pid])
(assoc :history true
:data (:data item)))]
(-> state
(dp/unpack-page page)
(assoc-in [:workspace pid :history :selected] version))))))
;; --- Apply Selected History
(def apply-selected
(ptk/reify ::apply-selected
ptk/UpdateEvent
(update [_ state]
(let [pid (get-in state [:workspace :current])]
(-> state
(update-in [:pages pid] dissoc :history)
(assoc-in [:workspace pid :history :selected] nil))))
ptk/WatchEvent
(watch [_ state s]
#_(let [pid (get-in state [:workspace :current])]
(rx/of (dp/persist-page pid))))))
;; --- Deselect Page History
(def deselect
(ptk/reify ::deselect
ptk/UpdateEvent
(update [_ state]
#_(let [pid (get-in state [:workspace :current])
packed (get-in state [:packed-pages pid])]
(-> (dp/unpack-page state packed)
(assoc-in [:workspace pid :history :selected] nil))))))
;; --- Refresh Page History
(def refres-history
(ptk/reify ::refresh-history
ptk/WatchEvent
(watch [_ state stream]
(let [pid (get-in state [:workspace :current])
history (get-in state [:workspace pid :history])
maxitems (count (:items history))]
(rx/of (fetch-history pid {:max maxitems})
(fetch-pinned-history pid))))))
;; --- History Item Updated
(defn history-updated
[item]
(us/verify ::history-entry item)
(ptk/reify ::history-item-updated
ptk/UpdateEvent
(update [_ state]
(let [pid (get-in state [:workspace :current])]
(update-in state [:workspace pid :history]
(fn [history]
(-> history
(update :items #(into #{} (replace-by-id item) %))
(update :pinned #(into #{} (replace-by-id item) %))
(assoc-in [:byver (:version item)] item))))))))
(defn history-updated?
[v]
(= ::history-item-updated (ptk/type v)))
;; --- Update History Item
(defn update-history-item
[item]
(ptk/reify ::update-history-item
ptk/WatchEvent
(watch [_ state stream]
(rx/concat
#_(->> (rp/req :update/page-history item)
(rx/map :payload)
(rx/map history-updated))
(->> (rx/filter history-updated? stream)
(rx/take 1)
(rx/map (constantly refres-history)))))))

View File

@ -6,22 +6,14 @@
(ns app.main.data.media (ns app.main.data.media
(:require (:require
[app.common.data :as d]
[app.common.media :as cm]
[app.common.spec :as us]
[app.common.uuid :as uuid]
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.media :as cm]
[app.main.data.messages :as dm] [app.main.data.messages :as dm]
[app.main.repo :as rp]
[app.main.store :as st] [app.main.store :as st]
[app.util.i18n :refer [tr]] [app.util.i18n :refer [tr]]
[app.util.router :as r]
[app.util.router :as rt]
[app.util.time :as ts]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[cuerdas.core :as str] [cuerdas.core :as str]))
[potok.core :as ptk]))
;; --- Predicates ;; --- Predicates

View File

@ -7,10 +7,7 @@
(ns app.main.data.messages (ns app.main.data.messages
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.exceptions :as ex]
[app.common.pages :as cp]
[app.common.spec :as us] [app.common.spec :as us]
[app.config :as cfg]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[potok.core :as ptk])) [potok.core :as ptk]))
@ -54,7 +51,7 @@
(assoc state :message message))) (assoc state :message message)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(when (:timeout data) (when (:timeout data)
(let [stoper (rx/filter (ptk/type? ::show) stream)] (let [stoper (rx/filter (ptk/type? ::show) stream)]
(->> (rx/of hide) (->> (rx/of hide)
@ -68,7 +65,7 @@
(d/update-when state :message assoc :status :hide)) (d/update-when state :message assoc :status :hide))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(let [stoper (rx/filter (ptk/type? ::show) stream)] (let [stoper (rx/filter (ptk/type? ::show) stream)]
(->> (rx/of #(dissoc % :message)) (->> (rx/of #(dissoc % :message))
(rx/delay default-animation-timeout) (rx/delay default-animation-timeout)
@ -78,7 +75,7 @@
[tag] [tag]
(ptk/reify ::hide-tag (ptk/reify ::hide-tag
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [message (get state :message)] (let [message (get state :message)]
(when (= (:tag message) tag) (when (= (:tag message) tag)
(rx/of hide)))))) (rx/of hide))))))
@ -127,7 +124,7 @@
:tag tag}))) :tag tag})))
(defn assign-exception (defn assign-exception
[{:keys [type] :as error}] [error]
(ptk/reify ::assign-exception (ptk/reify ::assign-exception
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]

View File

@ -7,10 +7,10 @@
(ns app.main.data.modal (ns app.main.data.modal
(:refer-clojure :exclude [update]) (:refer-clojure :exclude [update])
(:require (:require
[potok.core :as ptk]
[app.main.store :as st]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[cljs.core :as c])) [app.main.store :as st]
[cljs.core :as c]
[potok.core :as ptk]))
(defonce components (atom {})) (defonce components (atom {}))
@ -29,7 +29,7 @@
:allow-click-outside false}))))) :allow-click-outside false})))))
(defn update-props (defn update-props
([type props] ([_type props]
(ptk/reify ::update-modal-props (ptk/reify ::update-modal-props
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]

View File

@ -8,7 +8,6 @@
(:refer-clojure :exclude [meta reset!]) (:refer-clojure :exclude [meta reset!])
(:require (:require
["mousetrap" :as mousetrap] ["mousetrap" :as mousetrap]
[app.common.data :as d]
[app.common.spec :as us] [app.common.spec :as us]
[app.config :as cfg] [app.config :as cfg]
[app.util.logging :as log] [app.util.logging :as log]
@ -164,8 +163,8 @@
(update :shortcuts (fnil conj '()) [key shortcuts]))) (update :shortcuts (fnil conj '()) [key shortcuts])))
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ state _]
(let [[key shortcuts] (peek (:shortcuts state))] (let [[_key shortcuts] (peek (:shortcuts state))]
(reset! shortcuts))))) (reset! shortcuts)))))
(defn pop-shortcuts (defn pop-shortcuts
@ -179,7 +178,7 @@
(pop shortcuts) (pop shortcuts)
shortcuts))))) shortcuts)))))
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ state _]
(let [[key* shortcuts] (peek (:shortcuts state))] (let [[key* shortcuts] (peek (:shortcuts state))]
(when (not= key key*) (when (not= key key*)
(reset! shortcuts)))))) (reset! shortcuts))))))

View File

@ -6,24 +6,20 @@
(ns app.main.data.users (ns app.main.data.users
(:require (:require
[app.config :as cf]
[app.common.data :as d] [app.common.data :as d]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.config :as cf]
[app.main.data.events :as ev] [app.main.data.events :as ev]
[app.main.data.media :as di] [app.main.data.media :as di]
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
[app.main.data.messages :as dm]
[app.main.repo :as rp] [app.main.repo :as rp]
[app.main.store :as st] [app.util.i18n :as i18n]
[app.util.avatars :as avatars]
[app.util.i18n :as i18n :refer [tr]]
[app.util.router :as rt] [app.util.router :as rt]
[app.util.storage :refer [storage]] [app.util.storage :refer [storage]]
[app.util.theme :as theme] [app.util.theme :as theme]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[cuerdas.core :as str]
[potok.core :as ptk])) [potok.core :as ptk]))
;; --- COMMON SPECS ;; --- COMMON SPECS
@ -75,7 +71,7 @@
[] []
(ptk/reify ::fetch-teams (ptk/reify ::fetch-teams
ptk/WatchEvent ptk/WatchEvent
(watch [_ state s] (watch [_ _ _]
(->> (rp/query! :teams) (->> (rp/query! :teams)
(rx/map teams-fetched))))) (rx/map teams-fetched)))))
@ -95,7 +91,7 @@
(assoc :profile profile))) (assoc :profile profile)))
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ state _]
(let [profile (:profile state)] (let [profile (:profile state)]
(when (not= uuid/zero (:id profile)) (when (not= uuid/zero (:id profile))
(swap! storage assoc :profile profile) (swap! storage assoc :profile profile)
@ -107,7 +103,7 @@
[] []
(ptk/reify ::fetch-profile (ptk/reify ::fetch-profile
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query! :profile) (->> (rp/query! :profile)
(rx/map profile-fetched))))) (rx/map profile-fetched)))))
@ -120,7 +116,7 @@
[] []
(ptk/reify ::initialize-profile (ptk/reify ::initialize-profile
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(rx/merge (rx/merge
(rx/of (fetch-profile)) (rx/of (fetch-profile))
(->> stream (->> stream
@ -141,7 +137,7 @@
(-deref [_] profile) (-deref [_] profile)
ptk/WatchEvent ptk/WatchEvent
(watch [this state stream] (watch [_ _ _]
(let [team-id (get-current-team-id profile) (let [team-id (get-current-team-id profile)
profile (with-meta profile profile (with-meta profile
{::ev/source "login"})] {::ev/source "login"})]
@ -166,7 +162,7 @@
(us/verify ::login-params data) (us/verify ::login-params data)
(ptk/reify ::login (ptk/reify ::login
ptk/WatchEvent ptk/WatchEvent
(watch [this state s] (watch [_ _ _]
(let [{:keys [on-error on-success] (let [{:keys [on-error on-success]
:or {on-error rx/throw :or {on-error rx/throw
on-success identity}} (meta data) on-success identity}} (meta data)
@ -186,7 +182,7 @@
[{:keys [profile] :as tdata}] [{:keys [profile] :as tdata}]
(ptk/reify ::login-from-token (ptk/reify ::login-from-token
ptk/WatchEvent ptk/WatchEvent
(watch [this state s] (watch [_ _ _]
(rx/of (logged-in (rx/of (logged-in
(with-meta profile (with-meta profile
{::ev/source "login-with-token"})))))) {::ev/source "login-with-token"}))))))
@ -201,11 +197,11 @@
(select-keys state [:route :router :session-id :history])) (select-keys state [:route :router :session-id :history]))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state s] (watch [_ _ _]
(rx/of (rt/nav :auth-login))) (rx/of (rt/nav :auth-login)))
ptk/EffectEvent ptk/EffectEvent
(effect [_ state s] (effect [_ _ _]
(reset! storage {}) (reset! storage {})
(i18n/reset-locale)))) (i18n/reset-locale))))
@ -213,7 +209,7 @@
[] []
(ptk/reify ::logout (ptk/reify ::logout
ptk/WatchEvent ptk/WatchEvent
(watch [_ state s] (watch [_ _ _]
(->> (rp/mutation :logout) (->> (rp/mutation :logout)
(rx/delay-at-least 300) (rx/delay-at-least 300)
(rx/catch (constantly (rx/of 1))) (rx/catch (constantly (rx/of 1)))
@ -234,7 +230,7 @@
(s/assert ::register data) (s/assert ::register data)
(ptk/reify ::register (ptk/reify ::register
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-error on-success] (let [{:keys [on-error on-success]
:or {on-error identity :or {on-error identity
on-success identity}} (meta data)] on-success identity}} (meta data)]
@ -249,7 +245,7 @@
(us/assert ::profile data) (us/assert ::profile data)
(ptk/reify ::update-profile (ptk/reify ::update-profile
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(let [mdata (meta data) (let [mdata (meta data)
on-success (:on-success mdata identity) on-success (:on-success mdata identity)
on-error (:on-error mdata #(rx/throw %))] on-error (:on-error mdata #(rx/throw %))]
@ -273,7 +269,7 @@
(us/assert ::us/email email) (us/assert ::us/email email)
(ptk/reify ::request-email-change (ptk/reify ::request-email-change
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-error on-success] (let [{:keys [on-error on-success]
:or {on-error identity :or {on-error identity
on-success identity}} (meta data)] on-success identity}} (meta data)]
@ -286,7 +282,7 @@
(def cancel-email-change (def cancel-email-change
(ptk/reify ::cancel-email-change (ptk/reify ::cancel-email-change
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation :cancel-email-change {}) (->> (rp/mutation :cancel-email-change {})
(rx/map (constantly (fetch-profile))))))) (rx/map (constantly (fetch-profile)))))))
@ -302,7 +298,7 @@
(us/verify ::update-password data) (us/verify ::update-password data)
(ptk/reify ::update-password (ptk/reify ::update-password
ptk/WatchEvent ptk/WatchEvent
(watch [_ state s] (watch [_ _ _]
(let [{:keys [on-error on-success] (let [{:keys [on-error on-success]
:or {on-error identity :or {on-error identity
on-success identity}} (meta data) on-success identity}} (meta data)
@ -321,7 +317,7 @@
([{:keys [version]}] ([{:keys [version]}]
(ptk/reify ::mark-oboarding-as-viewed (ptk/reify ::mark-oboarding-as-viewed
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [version (or version (:main @cf/version)) (let [version (or version (:main @cf/version))
props (-> (get-in state [:profile :props]) props (-> (get-in state [:profile :props])
(assoc :onboarding-viewed true) (assoc :onboarding-viewed true)
@ -336,7 +332,7 @@
(us/verify ::di/blob file) (us/verify ::di/blob file)
(ptk/reify ::update-photo (ptk/reify ::update-photo
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [on-success di/notify-finished-loading (let [on-success di/notify-finished-loading
on-error #(do (di/notify-finished-loading) on-error #(do (di/notify-finished-loading)
(di/process-error %)) (di/process-error %))
@ -364,7 +360,7 @@
(assoc state :users)))] (assoc state :users)))]
(ptk/reify ::fetch-team-users (ptk/reify ::fetch-team-users
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :team-users {:team-id team-id}) (->> (rp/query :team-users {:team-id team-id})
(rx/map #(partial fetched %))))))) (rx/map #(partial fetched %)))))))
@ -374,7 +370,7 @@
[params] [params]
(ptk/reify ::request-account-deletion (ptk/reify ::request-account-deletion
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-error on-success] (let [{:keys [on-error on-success]
:or {on-error rx/throw :or {on-error rx/throw
on-success identity}} (meta params)] on-success identity}} (meta params)]
@ -395,7 +391,7 @@
(us/verify ::request-profile-recovery data) (us/verify ::request-profile-recovery data)
(ptk/reify ::request-profile-recovery (ptk/reify ::request-profile-recovery
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-error on-success] (let [{:keys [on-error on-success]
:or {on-error rx/throw :or {on-error rx/throw
on-success identity}} (meta data)] on-success identity}} (meta data)]
@ -411,19 +407,17 @@
(s/keys :req-un [::password ::token])) (s/keys :req-un [::password ::token]))
(defn recover-profile (defn recover-profile
[{:keys [token password] :as data}] [data]
(us/verify ::recover-profile data) (us/verify ::recover-profile data)
(ptk/reify ::recover-profile (ptk/reify ::recover-profile
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [{:keys [on-error on-success] (let [{:keys [on-error on-success]
:or {on-error rx/throw :or {on-error rx/throw
on-success identity}} (meta data)] on-success identity}} (meta data)]
(->> (rp/mutation :recover-profile data) (->> (rp/mutation :recover-profile data)
(rx/tap on-success) (rx/tap on-success)
(rx/catch (fn [err] (rx/catch on-error))))))
(on-error)
(rx/empty))))))))
;; --- EVENT: crete-demo-profile ;; --- EVENT: crete-demo-profile
@ -431,7 +425,7 @@
[] []
(ptk/reify ::create-demo-profile (ptk/reify ::create-demo-profile
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation :create-demo-profile {}) (->> (rp/mutation :create-demo-profile {})
(rx/map login))))) (rx/map login)))))

View File

@ -7,7 +7,6 @@
(ns app.main.data.viewer (ns app.main.data.viewer
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.exceptions :as ex]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
@ -15,8 +14,6 @@
[app.main.data.comments :as dcm] [app.main.data.comments :as dcm]
[app.main.data.fonts :as df] [app.main.data.fonts :as df]
[app.main.repo :as rp] [app.main.repo :as rp]
[app.main.store :as st]
[app.util.avatars :as avatars]
[app.util.router :as rt] [app.util.router :as rt]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
@ -27,7 +24,7 @@
(s/def ::id ::us/uuid) (s/def ::id ::us/uuid)
(s/def ::name ::us/string) (s/def ::name ::us/string)
(s/def ::project (s/keys ::req-un [::id ::name])) (s/def ::project (s/keys :req-un [::id ::name]))
(s/def ::file (s/keys :req-un [::id ::name])) (s/def ::file (s/keys :req-un [::id ::name]))
(s/def ::page ::cp/page) (s/def ::page ::cp/page)
@ -60,10 +57,10 @@
(s/def ::initialize-params (s/def ::initialize-params
(s/keys :req-un [::page-id ::file-id] (s/keys :req-un [::page-id ::file-id]
:opt-in [::token])) :opt-un [::token]))
(defn initialize (defn initialize
[{:keys [page-id file-id token] :as params}] [{:keys [page-id file-id] :as params}]
(us/assert ::initialize-params params) (us/assert ::initialize-params params)
(ptk/reify ::initialize (ptk/reify ::initialize
ptk/UpdateEvent ptk/UpdateEvent
@ -78,7 +75,7 @@
lstate))))) lstate)))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(rx/of (fetch-bundle params) (rx/of (fetch-bundle params)
(fetch-comment-threads params))))) (fetch-comment-threads params)))))
@ -86,14 +83,14 @@
(s/def ::fetch-bundle-params (s/def ::fetch-bundle-params
(s/keys :req-un [::page-id ::file-id] (s/keys :req-un [::page-id ::file-id]
:opt-in [::token])) :opt-un [::token]))
(defn fetch-bundle (defn fetch-bundle
[{:keys [page-id file-id token] :as params}] [{:keys [page-id file-id token] :as params}]
(us/assert ::fetch-bundle-params params) (us/assert ::fetch-bundle-params params)
(ptk/reify ::fetch-file (ptk/reify ::fetch-file
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [params (cond-> {:page-id page-id (let [params (cond-> {:page-id page-id
:file-id file-id} :file-id file-id}
(string? token) (assoc :token token))] (string? token) (assoc :token token))]
@ -145,7 +142,7 @@
(ptk/reify ::fetch-comment-threads (ptk/reify ::fetch-comment-threads
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :comment-threads {:file-id file-id}) (->> (rp/query :comment-threads {:file-id file-id})
(rx/map #(partial fetched %)) (rx/map #(partial fetched %))
(rx/catch on-error)))))) (rx/catch on-error))))))
@ -156,7 +153,7 @@
(assoc-in state [:comment-threads id] thread))] (assoc-in state [:comment-threads id] thread))]
(ptk/reify ::refresh-comment-thread (ptk/reify ::refresh-comment-thread
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :comment-thread {:file-id file-id :id id}) (->> (rp/query :comment-thread {:file-id file-id :id id})
(rx/map #(partial fetched %))))))) (rx/map #(partial fetched %)))))))
@ -167,7 +164,7 @@
(update state :comments assoc thread-id (d/index-by :id comments)))] (update state :comments assoc thread-id (d/index-by :id comments)))]
(ptk/reify ::retrieve-comments (ptk/reify ::retrieve-comments
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/query :comments {:thread-id thread-id}) (->> (rp/query :comments {:thread-id thread-id})
(rx/map #(partial fetched %))))))) (rx/map #(partial fetched %)))))))
@ -175,7 +172,7 @@
[] []
(ptk/reify ::create-share-link (ptk/reify ::create-share-link
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [file-id (:current-file-id state) (let [file-id (:current-file-id state)
page-id (:current-page-id state)] page-id (:current-page-id state)]
(->> (rp/mutation! :create-file-share-token {:file-id file-id (->> (rp/mutation! :create-file-share-token {:file-id file-id
@ -187,7 +184,7 @@
[] []
(ptk/reify ::delete-share-link (ptk/reify ::delete-share-link
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [file-id (:current-file-id state) (let [file-id (:current-file-id state)
page-id (:current-page-id state) page-id (:current-page-id state)
token (get-in state [:viewer-data :token]) token (get-in state [:viewer-data :token])
@ -246,7 +243,7 @@
(def select-prev-frame (def select-prev-frame
(ptk/reify ::select-prev-frame (ptk/reify ::select-prev-frame
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [route (:route state) (let [route (:route state)
screen (-> route :data :name keyword) screen (-> route :data :name keyword)
qparams (:query-params route) qparams (:query-params route)
@ -260,7 +257,7 @@
(def select-next-frame (def select-next-frame
(ptk/reify ::select-prev-frame (ptk/reify ::select-prev-frame
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [route (:route state) (let [route (:route state)
screen (-> route :data :name keyword) screen (-> route :data :name keyword)
qparams (:query-params route) qparams (:query-params route)
@ -296,7 +293,7 @@
(assoc-in state [:viewer-local :interactions-show?] true)) (assoc-in state [:viewer-local :interactions-show?] true))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(let [stopper (rx/filter (ptk/type? ::flash-interactions) stream)] (let [stopper (rx/filter (ptk/type? ::flash-interactions) stream)]
(->> (rx/of flash-done) (->> (rx/of flash-done)
(rx/delay 500) (rx/delay 500)
@ -314,7 +311,7 @@
[index] [index]
(ptk/reify ::go-to-frame (ptk/reify ::go-to-frame
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [route (:route state) (let [route (:route state)
screen (-> route :data :name keyword) screen (-> route :data :name keyword)
qparams (:query-params route) qparams (:query-params route)
@ -326,7 +323,7 @@
(us/verify ::us/uuid frame-id) (us/verify ::us/uuid frame-id)
(ptk/reify ::go-to-frame (ptk/reify ::go-to-frame
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [frames (get-in state [:viewer-data :frames]) (let [frames (get-in state [:viewer-data :frames])
index (d/index-of-pred frames #(= (:id %) frame-id))] index (d/index-of-pred frames #(= (:id %) frame-id))]
(when index (when index
@ -337,13 +334,11 @@
[section] [section]
(ptk/reify ::go-to-section (ptk/reify ::go-to-section
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [route (:route state) (let [route (:route state)
screen (-> route :data :name keyword)
pparams (:path-params route) pparams (:path-params route)
qparams (:query-params route)] qparams (:query-params route)]
(rx/of (rx/of (rt/nav :viewer pparams (assoc qparams :section section)))))))
(rt/nav :viewer pparams (assoc qparams :section section)))))))
(defn set-current-frame [frame-id] (defn set-current-frame [frame-id]
@ -422,6 +417,6 @@
([{:keys [team-id]}] ([{:keys [team-id]}]
(ptk/reify ::go-to-dashboard (ptk/reify ::go-to-dashboard
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [team-id (or team-id (get-in state [:viewer-data :project :team-id]))] (let [team-id (or team-id (get-in state [:viewer-data :project :team-id]))]
(rx/of (rt/nav :dashboard-projects {:team-id team-id}))))))) (rx/of (rt/nav :dashboard-projects {:team-id team-id})))))))

View File

@ -6,15 +6,9 @@
(ns app.main.data.viewer.shortcuts (ns app.main.data.viewer.shortcuts
(:require (:require
[app.config :as cfg]
[app.main.data.workspace.colors :as mdc]
[app.main.data.shortcuts :as ds] [app.main.data.shortcuts :as ds]
[app.main.data.shortcuts :refer [c-mod]]
[app.main.data.viewer :as dv] [app.main.data.viewer :as dv]
[app.main.store :as st] [app.main.store :as st]))
[app.util.dom :as dom]
[beicon.core :as rx]
[potok.core :as ptk]))
(def shortcuts (def shortcuts
{:increase-zoom {:tooltip "+" {:increase-zoom {:tooltip "+"

View File

@ -38,7 +38,6 @@
[app.main.worker :as uw] [app.main.worker :as uw]
[app.util.http :as http] [app.util.http :as http]
[app.util.i18n :as i18n] [app.util.i18n :as i18n]
[app.util.logging :as log]
[app.util.router :as rt] [app.util.router :as rt]
[app.util.webapi :as wapi] [app.util.webapi :as wapi]
[beicon.core :as rx] [beicon.core :as rx]
@ -134,7 +133,7 @@
(or layout default-layout)))) (or layout default-layout))))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(if (and layout-name (contains? layout-names layout-name)) (if (and layout-name (contains? layout-names layout-name))
(rx/of (ensure-layout layout-name)) (rx/of (ensure-layout layout-name))
(rx/of (ensure-layout :layers)))))) (rx/of (ensure-layout :layers))))))
@ -153,7 +152,7 @@
:workspace-presence {})) :workspace-presence {}))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ stream]
(rx/merge (rx/merge
(rx/of (dwp/fetch-bundle project-id file-id)) (rx/of (dwp/fetch-bundle project-id file-id))
@ -162,7 +161,7 @@
(rx/filter (ptk/type? ::dwp/bundle-fetched)) (rx/filter (ptk/type? ::dwp/bundle-fetched))
(rx/take 1) (rx/take 1)
(rx/map deref) (rx/map deref)
(rx/mapcat (fn [{:keys [project] :as bundle}] (rx/mapcat (fn [bundle]
(rx/merge (rx/merge
(rx/of (dwn/initialize file-id) (rx/of (dwn/initialize file-id)
(dwp/initialize-file-persistence file-id) (dwp/initialize-file-persistence file-id)
@ -188,7 +187,7 @@
:workspace-libraries (d/index-by :id libraries))) :workspace-libraries (d/index-by :id libraries)))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(let [file-id (:id file) (let [file-id (:id file)
ignore-until (:ignore-sync-until file) ignore-until (:ignore-sync-until file)
needs-update? (some #(and (> (:modified-at %) (:synced-at %)) needs-update? (some #(and (> (:modified-at %) (:synced-at %))
@ -199,7 +198,7 @@
(rx/of (dwl/notify-sync-file file-id))))))) (rx/of (dwl/notify-sync-file file-id)))))))
(defn finalize-file (defn finalize-file
[project-id file-id] [_project-id file-id]
(ptk/reify ::finalize (ptk/reify ::finalize
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
@ -210,7 +209,7 @@
:workspace-persistence)) :workspace-persistence))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(rx/of (dwn/finalize file-id) (rx/of (dwn/finalize file-id)
::dwp/finalize)))) ::dwp/finalize))))
@ -262,7 +261,7 @@
{:id id :file-id file-id}) {:id id :file-id file-id})
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [pages (get-in state [:workspace-data :pages-index]) (let [pages (get-in state [:workspace-data :pages-index])
unames (dwc/retrieve-used-names pages) unames (dwc/retrieve-used-names pages)
name (dwc/generate-unique-name unames "Page") name (dwc/generate-unique-name unames "Page")
@ -280,7 +279,7 @@
[page-id] [page-id]
(ptk/reify ::duplicate-page (ptk/reify ::duplicate-page
ptk/WatchEvent ptk/WatchEvent
(watch [this state stream] (watch [this state _]
(let [id (uuid/next) (let [id (uuid/next)
pages (get-in state [:workspace-data :pages-index]) pages (get-in state [:workspace-data :pages-index])
unames (dwc/retrieve-used-names pages) unames (dwc/retrieve-used-names pages)
@ -306,7 +305,7 @@
(us/verify string? name) (us/verify string? name)
(ptk/reify ::rename-page (ptk/reify ::rename-page
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page (get-in state [:workspace-data :pages-index id]) (let [page (get-in state [:workspace-data :pages-index id])
rchg {:type :mod-page rchg {:type :mod-page
:id id :id id
@ -327,7 +326,7 @@
[id] [id]
(ptk/reify ::delete-page (ptk/reify ::delete-page
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page (get-in state [:workspace-data :pages-index id]) (let [page (get-in state [:workspace-data :pages-index id])
rchg {:type :del-page rchg {:type :del-page
:id id} :id id}
@ -353,7 +352,7 @@
(assoc-in state [:workspace-file :name] name)) (assoc-in state [:workspace-file :name] name))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(let [params {:id id :name name}] (let [params {:id id :name name}]
(->> (rp/mutation :rename-file params) (->> (rp/mutation :rename-file params)
(rx/ignore)))))) (rx/ignore))))))
@ -368,7 +367,7 @@
(defn initialize-viewport (defn initialize-viewport
[{:keys [width height] :as size}] [{:keys [width height] :as size}]
(letfn [(update* [{:keys [vbox vport] :as local}] (letfn [(update* [{:keys [vport] :as local}]
(let [wprop (/ (:width vport) width) (let [wprop (/ (:width vport) width)
hprop (/ (:height vport) height)] hprop (/ (:height vport) height)]
(-> local (-> local
@ -433,7 +432,7 @@
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(update state :workspace-local (update state :workspace-local
(fn [{:keys [vbox vport left-sidebar? zoom] :as local}] (fn [{:keys [vport left-sidebar? zoom] :as local}]
(if (or (mth/almost-zero? width) (mth/almost-zero? height)) (if (or (mth/almost-zero? width) (mth/almost-zero? height))
;; If we have a resize to zero just keep the old value ;; If we have a resize to zero just keep the old value
local local
@ -452,7 +451,7 @@
(defn start-panning [] (defn start-panning []
(ptk/reify ::start-panning (ptk/reify ::start-panning
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state stream]
(let [stopper (->> stream (rx/filter (ptk/type? ::finish-panning))) (let [stopper (->> stream (rx/filter (ptk/type? ::finish-panning)))
zoom (-> (get-in state [:workspace-local :zoom]) gpt/point)] zoom (-> (get-in state [:workspace-local :zoom]) gpt/point)]
(when-not (get-in state [:workspace-local :panning]) (when-not (get-in state [:workspace-local :panning])
@ -580,7 +579,7 @@
(mth/nan? (:height srect))) (mth/nan? (:height srect)))
state state
(update state :workspace-local (update state :workspace-local
(fn [{:keys [vbox vport] :as local}] (fn [{:keys [vport] :as local}]
(let [srect (gal/adjust-to-viewport vport srect {:padding 40}) (let [srect (gal/adjust-to-viewport vport srect {:padding 40})
zoom (/ (:width vport) (:width srect))] zoom (/ (:width vport) (:width srect))]
(-> local (-> local
@ -600,7 +599,7 @@
(map #(get objects %)) (map #(get objects %))
(gsh/selection-rect))] (gsh/selection-rect))]
(update state :workspace-local (update state :workspace-local
(fn [{:keys [vbox vport] :as local}] (fn [{:keys [vport] :as local}]
(let [srect (gal/adjust-to-viewport vport srect {:padding 40}) (let [srect (gal/adjust-to-viewport vport srect {:padding 40})
zoom (/ (:width vport) (:width srect))] zoom (/ (:width vport) (:width srect))]
(-> local (-> local
@ -615,7 +614,7 @@
(us/verify ::shape-attrs attrs) (us/verify ::shape-attrs attrs)
(ptk/reify ::update-shape (ptk/reify ::update-shape
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(rx/of (dch/update-shapes [id] #(merge % attrs)))))) (rx/of (dch/update-shapes [id] #(merge % attrs))))))
(defn start-rename-shape (defn start-rename-shape
@ -631,7 +630,7 @@
(ptk/reify ::end-rename-shape (ptk/reify ::end-rename-shape
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(update-in state [:workspace-local] dissoc :shape-for-rename)))) (update state :workspace-local dissoc :shape-for-rename))))
;; --- Update Selected Shapes attrs ;; --- Update Selected Shapes attrs
@ -640,45 +639,17 @@
(us/verify ::shape-attrs attrs) (us/verify ::shape-attrs attrs)
(ptk/reify ::update-selected-shapes (ptk/reify ::update-selected-shapes
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [selected (wsh/lookup-selected state)] (let [selected (wsh/lookup-selected state)]
(rx/from (map #(update-shape % attrs) selected)))))) (rx/from (map #(update-shape % attrs) selected))))))
;; --- Shape Movement (using keyboard shorcuts)
(declare initial-selection-align)
(defn- get-displacement-with-grid
"Retrieve the correct displacement delta point for the
provided direction speed and distances thresholds."
[shape direction options]
(let [grid-x (:grid-x options 10)
grid-y (:grid-y options 10)
x-mod (mod (:x shape) grid-x)
y-mod (mod (:y shape) grid-y)]
(case direction
:up (gpt/point 0 (- (if (zero? y-mod) grid-y y-mod)))
:down (gpt/point 0 (- grid-y y-mod))
:left (gpt/point (- (if (zero? x-mod) grid-x x-mod)) 0)
:right (gpt/point (- grid-x x-mod) 0))))
(defn- get-displacement
"Retrieve the correct displacement delta point for the
provided direction speed and distances thresholds."
[shape direction]
(case direction
:up (gpt/point 0 (- 1))
:down (gpt/point 0 1)
:left (gpt/point (- 1) 0)
:right (gpt/point 1 0)))
;; --- Delete Selected ;; --- Delete Selected
(def delete-selected (def delete-selected
"Deselect all and remove all selected shapes." "Deselect all and remove all selected shapes."
(ptk/reify ::delete-selected (ptk/reify ::delete-selected
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [selected (wsh/lookup-selected state)] (let [selected (wsh/lookup-selected state)]
(rx/of (dwc/delete-shapes selected) (rx/of (dwc/delete-shapes selected)
(dws/deselect-all)))))) (dws/deselect-all))))))
@ -692,7 +663,7 @@
(us/verify ::loc loc) (us/verify ::loc loc)
(ptk/reify ::vertical-order-selected (ptk/reify ::vertical-order-selected
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
@ -901,7 +872,7 @@
(ptk/reify ::relocate-shapes (ptk/reify ::relocate-shapes
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
@ -1012,7 +983,7 @@
[parent-id to-index] [parent-id to-index]
(ptk/reify ::relocate-selected-shapes (ptk/reify ::relocate-selected-shapes
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [selected (wsh/lookup-selected state)] (let [selected (wsh/lookup-selected state)]
(rx/of (relocate-shapes selected parent-id to-index)))))) (rx/of (relocate-shapes selected parent-id to-index))))))
@ -1021,7 +992,7 @@
[] []
(ptk/reify ::start-editing-selected (ptk/reify ::start-editing-selected
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [selected (wsh/lookup-selected state)] (let [selected (wsh/lookup-selected state)]
(if-not (= 1 (count selected)) (if-not (= 1 (count selected))
(rx/empty) (rx/empty)
@ -1049,7 +1020,7 @@
[id index] [id index]
(ptk/reify ::relocate-pages (ptk/reify ::relocate-pages
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [cidx (-> (get-in state [:workspace-data :pages]) (let [cidx (-> (get-in state [:workspace-data :pages])
(d/index-of id)) (d/index-of id))
rchg {:type :mov-page rchg {:type :mov-page
@ -1072,7 +1043,7 @@
(us/verify ::gal/align-axis axis) (us/verify ::gal/align-axis axis)
(ptk/reify :align-objects (ptk/reify :align-objects
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
@ -1103,7 +1074,7 @@
(us/verify ::gal/dist-axis axis) (us/verify ::gal/dist-axis axis)
(ptk/reify :align-objects (ptk/reify :align-objects
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
@ -1121,7 +1092,7 @@
[id lock] [id lock]
(ptk/reify ::set-shape-proportion-lock (ptk/reify ::set-shape-proportion-lock
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(letfn [(assign-proportions [shape] (letfn [(assign-proportions [shape]
(if-not lock (if-not lock
(assoc shape :proportion-lock false) (assoc shape :proportion-lock false)
@ -1142,7 +1113,7 @@
(us/verify ::position position) (us/verify ::position position)
(ptk/reify ::update-position (ptk/reify ::update-position
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
shape (get objects id) shape (get objects id)
@ -1164,7 +1135,7 @@
(s/assert ::shape-attrs flags) (s/assert ::shape-attrs flags)
(ptk/reify ::update-shape-flags (ptk/reify ::update-shape-flags
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [update-fn (let [update-fn
(fn [obj] (fn [obj]
(cond-> obj (cond-> obj
@ -1184,7 +1155,7 @@
[project-id] [project-id]
(ptk/reify ::navigate-to-project (ptk/reify ::navigate-to-project
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [page-ids (get-in state [:projects project-id :pages]) (let [page-ids (get-in state [:projects project-id :pages])
params {:project project-id :page (first page-ids)}] params {:project project-id :page (first page-ids)}]
(rx/of (rt/nav :workspace/page params)))))) (rx/of (rt/nav :workspace/page params))))))
@ -1193,7 +1164,7 @@
([] ([]
(ptk/reify ::go-to-page (ptk/reify ::go-to-page
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [project-id (:current-project-id state) (let [project-id (:current-project-id state)
file-id (:current-file-id state) file-id (:current-file-id state)
page-id (get-in state [:workspace-data :pages 0]) page-id (get-in state [:workspace-data :pages 0])
@ -1205,7 +1176,7 @@
(us/verify ::us/uuid page-id) (us/verify ::us/uuid page-id)
(ptk/reify ::go-to-page (ptk/reify ::go-to-page
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [project-id (:current-project-id state) (let [project-id (:current-project-id state)
file-id (:current-file-id state) file-id (:current-file-id state)
pparams {:file-id file-id :project-id project-id} pparams {:file-id file-id :project-id project-id}
@ -1217,10 +1188,10 @@
(us/verify ::layout-flag layout) (us/verify ::layout-flag layout)
(ptk/reify ::go-to-layout (ptk/reify ::go-to-layout
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [project-id (get-in state [:workspace-project :id]) (let [project-id (get-in state [:workspace-project :id])
file-id (get-in state [:workspace-file :id]) file-id (get-in state [:workspace-file :id])
page-id (get-in state [:current-page-id]) page-id (get state :current-page-id)
pparams {:file-id file-id :project-id project-id} pparams {:file-id file-id :project-id project-id}
qparams {:page-id page-id :layout (name layout)}] qparams {:page-id page-id :layout (name layout)}]
(rx/of (rt/nav :workspace pparams qparams)))))) (rx/of (rt/nav :workspace pparams qparams))))))
@ -1228,7 +1199,7 @@
(def go-to-file (def go-to-file
(ptk/reify ::go-to-file (ptk/reify ::go-to-file
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [{:keys [id project-id data] :as file} (:workspace-file state) (let [{:keys [id project-id data] :as file} (:workspace-file state)
page-id (get-in data [:pages 0]) page-id (get-in data [:pages 0])
pparams {:project-id project-id :file-id id} pparams {:project-id project-id :file-id id}
@ -1240,7 +1211,7 @@
([{:keys [file-id page-id]}] ([{:keys [file-id page-id]}]
(ptk/reify ::go-to-viewer (ptk/reify ::go-to-viewer
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [{:keys [current-file-id current-page-id]} state (let [{:keys [current-file-id current-page-id]} state
params {:file-id (or file-id current-file-id) params {:file-id (or file-id current-file-id)
:page-id (or page-id current-page-id)}] :page-id (or page-id current-page-id)}]
@ -1252,7 +1223,7 @@
([{:keys [team-id]}] ([{:keys [team-id]}]
(ptk/reify ::go-to-dashboard (ptk/reify ::go-to-dashboard
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(when-let [team-id (or team-id (:current-team-id state))] (when-let [team-id (or team-id (:current-team-id state))]
(rx/of ::dwp/force-persist (rx/of ::dwp/force-persist
(rt/nav :dashboard-projects {:team-id team-id}))))))) (rt/nav :dashboard-projects {:team-id team-id})))))))
@ -1261,7 +1232,7 @@
[] []
(ptk/reify ::go-to-dashboard (ptk/reify ::go-to-dashboard
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(rx/of ::dwp/force-persist (rx/of ::dwp/force-persist
(rt/nav :dashboard-fonts {:team-id team-id})))))) (rt/nav :dashboard-fonts {:team-id team-id}))))))
@ -1291,7 +1262,7 @@
(us/verify ::cp/minimal-shape shape) (us/verify ::cp/minimal-shape shape)
(ptk/reify ::show-shape-context-menu (ptk/reify ::show-shape-context-menu
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [selected (wsh/lookup-selected state)] (let [selected (wsh/lookup-selected state)]
(rx/concat (rx/concat
(when-not (selected (:id shape)) (when-not (selected (:id shape))
@ -1383,7 +1354,7 @@
(ptk/reify ::copy-selected (ptk/reify ::copy-selected
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
selected (->> (wsh/lookup-selected state) selected (->> (wsh/lookup-selected state)
(cp/clean-loops objects)) (cp/clean-loops objects))
@ -1410,7 +1381,7 @@
(def paste (def paste
(ptk/reify ::paste (ptk/reify ::paste
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(try (try
(let [clipboard-str (wapi/read-from-clipboard) (let [clipboard-str (wapi/read-from-clipboard)
@ -1449,7 +1420,7 @@
[event in-viewport?] [event in-viewport?]
(ptk/reify ::paste-from-event (ptk/reify ::paste-from-event
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(try (try
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
paste-data (wapi/read-from-paste-event event) paste-data (wapi/read-from-paste-event event)
@ -1487,8 +1458,8 @@
(defn selected-frame? [state] (defn selected-frame? [state]
(let [selected (wsh/lookup-selected state) (let [selected (wsh/lookup-selected state)
objects (wsh/lookup-page-objects state)] objects (wsh/lookup-page-objects state)]
(and (and (= 1 (count selected)) (and (= 1 (count selected))
(= :frame (get-in objects [(first selected) :type])))))) (= :frame (get-in objects [(first selected) :type])))))
(defn- paste-shape (defn- paste-shape
[{:keys [selected objects images] :as data} in-viewport?] [{:keys [selected objects images] :as data} in-viewport?]
@ -1569,7 +1540,6 @@
;; Procceed with the standard shape paste procediment. ;; Procceed with the standard shape paste procediment.
(do-paste [it state mouse-pos media] (do-paste [it state mouse-pos media]
(let [media-idx (d/index-by :prev-id media) (let [media-idx (d/index-by :prev-id media)
page-id (:current-page-id state)
;; Calculate position for the pasted elements ;; Calculate position for the pasted elements
[frame-id parent-id delta index] (calculate-paste-position state mouse-pos in-viewport?) [frame-id parent-id delta index] (calculate-paste-position state mouse-pos in-viewport?)
@ -1619,7 +1589,7 @@
(dwc/select-shapes selected))))] (dwc/select-shapes selected))))]
(ptk/reify ::paste-shape (ptk/reify ::paste-shape
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [file-id (:current-file-id state) (let [file-id (:current-file-id state)
mouse-pos (deref ms/mouse-position)] mouse-pos (deref ms/mouse-position)]
(if (= file-id (:file-id data)) (if (= file-id (:file-id data))
@ -1643,7 +1613,7 @@
(s/assert string? text) (s/assert string? text)
(ptk/reify ::paste-text (ptk/reify ::paste-text
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [id (uuid/next) (let [id (uuid/next)
{:keys [x y]} @ms/mouse-position {:keys [x y]} @ms/mouse-position
width (max 8 (min (* 7 (count text)) 700)) width (max 8 (min (* 7 (count text)) 700))
@ -1672,7 +1642,7 @@
(s/assert string? text) (s/assert string? text)
(ptk/reify ::paste-svg (ptk/reify ::paste-svg
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [position (deref ms/mouse-position) (let [position (deref ms/mouse-position)
file-id (:current-file-id state)] file-id (:current-file-id state)]
(->> (dwp/parse-svg ["svg" text]) (->> (dwp/parse-svg ["svg" text])
@ -1682,7 +1652,7 @@
[image] [image]
(ptk/reify ::paste-bin-impl (ptk/reify ::paste-bin-impl
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [file-id (get-in state [:workspace-file :id]) (let [file-id (get-in state [:workspace-file :id])
params {:file-id file-id params {:file-id file-id
:blobs [image] :blobs [image]
@ -1707,7 +1677,7 @@
[] []
(ptk/reify ::start-create-interaction (ptk/reify ::start-create-interaction
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state stream]
(let [initial-pos @ms/mouse-position (let [initial-pos @ms/mouse-position
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
stopper (rx/filter ms/mouse-up? stream)] stopper (rx/filter ms/mouse-up? stream)]
@ -1744,7 +1714,7 @@
(assoc-in [:workspace-local :draw-interaction-to-frame] nil))) (assoc-in [:workspace-local :draw-interaction-to-frame] nil)))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [position @ms/mouse-position (let [position @ms/mouse-position
page-id (:current-page-id state) page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
@ -1772,7 +1742,7 @@
[color] [color]
(ptk/reify ::change-canvas-color (ptk/reify ::change-canvas-color
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page-id (get state :current-page-id) (let [page-id (get state :current-page-id)
options (wsh/lookup-page-options state page-id) options (wsh/lookup-page-options state page-id)
previus-color (:background options)] previus-color (:background options)]
@ -1787,7 +1757,6 @@
:value previus-color}] :value previus-color}]
:origin it})))))) :origin it}))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Exports ;; Exports
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -10,14 +10,13 @@
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.pages.spec :as spec] [app.common.pages.spec :as spec]
[app.common.spec :as us] [app.common.spec :as us]
[app.main.data.workspace.undo :as dwu]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
[app.main.worker :as uw] [app.main.data.workspace.undo :as dwu]
[app.main.store :as st] [app.main.store :as st]
[app.main.worker :as uw]
[app.util.logging :as log] [app.util.logging :as log]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[clojure.set :as set]
[potok.core :as ptk])) [potok.core :as ptk]))
;; Change this to :info :debug or :trace to debug this module ;; Change this to :info :debug or :trace to debug this module
@ -59,29 +58,29 @@
attrs) attrs)
uops (cond-> uops uops (cond-> uops
(not (empty? uops)) (seq uops)
(conj {:type :set-touched :touched (:touched old-obj)})) (conj {:type :set-touched :touched (:touched old-obj)}))
change {:type :mod-obj :page-id page-id :id id}] change {:type :mod-obj :page-id page-id :id id}]
(cond-> changes (cond-> changes
(not (empty? rops)) (seq rops)
(update :redo-changes conj (assoc change :operations rops)) (update :redo-changes conj (assoc change :operations rops))
(not (empty? uops)) (seq uops)
(update :undo-changes conj (assoc change :operations uops))))) (update :undo-changes conj (assoc change :operations uops)))))
(defn update-shapes (defn update-shapes
([ids f] (update-shapes ids f nil)) ([ids f] (update-shapes ids f nil))
([ids f {:keys [reg-objects? save-undo? keys] ([ids f {:keys [reg-objects? save-undo? keys]
:or {reg-objects? false save-undo? true attrs nil}}] :or {reg-objects? false save-undo? true}}]
(us/assert ::coll-of-uuid ids) (us/assert ::coll-of-uuid ids)
(us/assert fn? f) (us/assert fn? f)
(ptk/reify ::update-shapes (ptk/reify ::update-shapes
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state) objects (wsh/lookup-page-objects state)
changes {:redo-changes [] changes {:redo-changes []
@ -107,7 +106,7 @@
[page-id changes] [page-id changes]
(ptk/reify ::update-indices (ptk/reify ::update-indices
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ _ _]
(uw/ask! {:cmd :update-page-indices (uw/ask! {:cmd :update-page-indices
:page-id page-id :page-id page-id
:changes changes})))) :changes changes}))))
@ -147,7 +146,7 @@
state)))) state))))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(when-not @error (when-not @error
(let [;; adds page-id to page changes (that have the `id` field instead) (let [;; adds page-id to page changes (that have the `id` field instead)
add-page-id add-page-id
@ -163,7 +162,7 @@
(group-by :page-id)) (group-by :page-id))
process-page-changes process-page-changes
(fn [[page-id changes]] (fn [[page-id _changes]]
(update-indices page-id redo-changes))] (update-indices page-id redo-changes))]
(rx/concat (rx/concat
(rx/from (map process-page-changes changes-by-pages)) (rx/from (map process-page-changes changes-by-pages))

View File

@ -7,23 +7,13 @@
(ns app.main.data.workspace.colors (ns app.main.data.workspace.colors
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.pages :as cp]
[app.common.spec :as us]
[app.common.uuid :as uuid]
[app.main.data.modal :as md] [app.main.data.modal :as md]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
[app.main.data.workspace.texts :as dwt] [app.main.data.workspace.texts :as dwt]
[app.main.repo :as rp] [app.main.repo :as rp]
[app.main.store :as st]
[app.main.streams :as ms]
[app.util.color :as color]
[app.util.i18n :refer [tr]]
[app.util.router :as rt]
[app.util.time :as dt]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[clojure.set :as set]
[potok.core :as ptk])) [potok.core :as ptk]))
(def clear-color-for-rename (def clear-color-for-rename
@ -38,17 +28,16 @@
[file-id color-id name] [file-id color-id name]
(ptk/reify ::rename-color (ptk/reify ::rename-color
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rp/mutation! :rename-color {:id color-id :name name}) (->> (rp/mutation! :rename-color {:id color-id :name name})
(rx/map (partial rename-color-result file-id)))))) (rx/map (partial rename-color-result file-id))))))
(defn rename-color-result (defn rename-color-result
[file-id color] [_file-id color]
(ptk/reify ::rename-color-result (ptk/reify ::rename-color-result
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(-> state (update-in state [:workspace-file :colors] #(d/replace-by-id % color)))))
(update-in [:workspace-file :colors] #(d/replace-by-id % color))))))
(defn change-palette-size (defn change-palette-size
[size] [size]
@ -125,7 +114,7 @@
[ids color] [ids color]
(ptk/reify ::change-fill (ptk/reify ::change-fill
ptk/WatchEvent ptk/WatchEvent
(watch [_ state s] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
@ -157,32 +146,29 @@
[ids color] [ids color]
(ptk/reify ::change-stroke (ptk/reify ::change-stroke
ptk/WatchEvent ptk/WatchEvent
(watch [_ state s] (watch [_ _ _]
(let [page-id (:current-page-id state) (let [attrs (cond-> {}
objects (wsh/lookup-page-objects state page-id) (contains? color :color)
(assoc :stroke-color (:color color))
attrs (cond-> {} (contains? color :id)
(contains? color :color) (assoc :stroke-color-ref-id (:id color))
(assoc :stroke-color (:color color))
(contains? color :id) (contains? color :file-id)
(assoc :stroke-color-ref-id (:id color)) (assoc :stroke-color-ref-file (:file-id color))
(contains? color :file-id) (contains? color :gradient)
(assoc :stroke-color-ref-file (:file-id color)) (assoc :stroke-color-gradient (:gradient color))
(contains? color :gradient) (contains? color :opacity)
(assoc :stroke-color-gradient (:gradient color)) (assoc :stroke-opacity (:opacity color)))]
(contains? color :opacity) (rx/of (dch/update-shapes ids (fn [shape]
(assoc :stroke-opacity (:opacity color)))] (cond-> (d/merge shape attrs)
(= (:stroke-style shape) :none)
(rx/of (dch/update-shapes ids (fn [shape] (assoc :stroke-style :solid
(cond-> (d/merge shape attrs) :stroke-width 1
(= (:stroke-style shape) :none) :stroke-opacity 1)))))))))
(assoc :stroke-style :solid
:stroke-width 1
:stroke-opacity 1)))))))))
(defn picker-for-selected-shape (defn picker-for-selected-shape

View File

@ -6,19 +6,14 @@
(ns app.main.data.workspace.comments (ns app.main.data.workspace.comments
(:require (:require
[app.common.data :as d]
[app.common.exceptions :as ex]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.spec :as us] [app.common.spec :as us]
[app.main.constants :as c] [app.main.data.comments :as dcm]
[app.main.data.workspace :as dw] [app.main.data.workspace :as dw]
[app.main.data.workspace.common :as dwc] [app.main.data.workspace.common :as dwc]
[app.main.data.comments :as dcm]
[app.main.store :as st]
[app.main.streams :as ms] [app.main.streams :as ms]
[app.util.router :as rt] [app.util.router :as rt]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s]
[potok.core :as ptk])) [potok.core :as ptk]))
(declare handle-interrupt) (declare handle-interrupt)
@ -29,7 +24,7 @@
(us/assert ::us/uuid file-id) (us/assert ::us/uuid file-id)
(ptk/reify ::initialize-comments (ptk/reify ::initialize-comments
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(let [stoper (rx/filter #(= ::finalize %) stream)] (let [stoper (rx/filter #(= ::finalize %) stream)]
(rx/merge (rx/merge
(rx/of (dcm/retrieve-comment-threads file-id)) (rx/of (dcm/retrieve-comment-threads file-id))
@ -47,8 +42,8 @@
[] []
(ptk/reify ::handle-interrupt (ptk/reify ::handle-interrupt
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [local (:comments-local state)] (let [local (:comments-local state)]
(cond (cond
(:draft local) (rx/of (dcm/close-thread)) (:draft local) (rx/of (dcm/close-thread))
(:open local) (rx/of (dcm/close-thread)) (:open local) (rx/of (dcm/close-thread))
@ -62,7 +57,7 @@
[position] [position]
(ptk/reify ::handle-comment-layer-click (ptk/reify ::handle-comment-layer-click
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [local (:comments-local state)] (let [local (:comments-local state)]
(if (some? (:open local)) (if (some? (:open local))
(rx/of (dcm/close-thread)) (rx/of (dcm/close-thread))
@ -74,14 +69,13 @@
(rx/of (dcm/create-draft params)))))))) (rx/of (dcm/create-draft params))))))))
(defn center-to-comment-thread (defn center-to-comment-thread
[{:keys [id position] :as thread}] [{:keys [position] :as thread}]
(us/assert ::dcm/comment-thread thread) (us/assert ::dcm/comment-thread thread)
(ptk/reify :center-to-comment-thread (ptk/reify :center-to-comment-thread
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(update state :workspace-local (update state :workspace-local
(fn [{:keys [vbox vport zoom] :as local}] (fn [{:keys [vbox zoom] :as local}]
(prn "center-to-comment-thread" vbox)
(let [pw (/ 50 zoom) (let [pw (/ 50 zoom)
ph (/ 200 zoom) ph (/ 200 zoom)
nw (mth/round (- (/ (:width vbox) 2) pw)) nw (mth/round (- (/ (:width vbox) 2) pw))
@ -93,11 +87,11 @@
(update local :vbox assoc :x nx :y ny))))))) (update local :vbox assoc :x nx :y ny)))))))
(defn navigate (defn navigate
[{:keys [project-id file-id page-id] :as thread}] [thread]
(us/assert ::dcm/comment-thread thread) (us/assert ::dcm/comment-thread thread)
(ptk/reify ::navigate (ptk/reify ::navigate
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(let [pparams {:project-id (:project-id thread) (let [pparams {:project-id (:project-id thread)
:file-id (:file-id thread)} :file-id (:file-id thread)}
qparams {:page-id (:page-id thread)}] qparams {:page-id (:page-id thread)}]

View File

@ -40,15 +40,13 @@
[{:keys [file] :as bundle}] [{:keys [file] :as bundle}]
(ptk/reify ::setup-selection-index (ptk/reify ::setup-selection-index
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(let [msg {:cmd :initialize-indices (let [msg {:cmd :initialize-indices
:file-id (:id file) :file-id (:id file)
:data (:data file)}] :data (:data file)}]
(->> (uw/ask! msg) (->> (uw/ask! msg)
(rx/map (constantly ::index-initialized))))))) (rx/map (constantly ::index-initialized)))))))
;; --- Common Helpers & Events ;; --- Common Helpers & Events
(defn get-frame-at-point (defn get-frame-at-point
@ -59,7 +57,7 @@
(defn- extract-numeric-suffix (defn- extract-numeric-suffix
[basename] [basename]
(if-let [[match p1 p2] (re-find #"(.*)-([0-9]+)$" basename)] (if-let [[_ p1 p2] (re-find #"(.*)-([0-9]+)$" basename)]
[p1 (+ 1 (d/parse-integer p2))] [p1 (+ 1 (d/parse-integer p2))]
[basename 1])) [basename 1]))
@ -112,7 +110,7 @@
(def undo (def undo
(ptk/reify ::undo (ptk/reify ::undo
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [edition (get-in state [:workspace-local :edition]) (let [edition (get-in state [:workspace-local :edition])
drawing (get state :workspace-drawing)] drawing (get state :workspace-drawing)]
;; Editors handle their own undo's ;; Editors handle their own undo's
@ -131,7 +129,7 @@
(def redo (def redo
(ptk/reify ::redo (ptk/reify ::redo
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [edition (get-in state [:workspace-local :edition]) (let [edition (get-in state [:workspace-local :edition])
drawing (get state :workspace-drawing)] drawing (get state :workspace-drawing)]
(when-not (or (some? edition) (not-empty drawing)) (when-not (or (some? edition) (not-empty drawing))
@ -180,10 +178,10 @@
(assoc-in state [:workspace-local :selected] ids)) (assoc-in state [:workspace-local :selected] ids))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)] objects (wsh/lookup-page-objects state page-id)]
(rx/of (expand-all-parents ids objects)))))) (rx/of (expand-all-parents ids objects))))))
(declare clear-edition-mode) (declare clear-edition-mode)
@ -202,12 +200,11 @@
state))) state)))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ stream]
(let [objects (wsh/lookup-page-objects state)] (->> stream
(->> stream (rx/filter interrupt?)
(rx/filter interrupt?) (rx/take 1)
(rx/take 1) (rx/map (constantly clear-edition-mode))))))
(rx/map (constantly clear-edition-mode)))))))
;; If these event change modules review /src/app/main/data/workspace/path/undo.cljs ;; If these event change modules review /src/app/main/data/workspace/path/undo.cljs
(def clear-edition-mode (def clear-edition-mode
@ -282,7 +279,7 @@
(us/verify ::shape-attrs attrs) (us/verify ::shape-attrs attrs)
(ptk/reify ::add-shape (ptk/reify ::add-shape
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
@ -313,7 +310,7 @@
(defn move-shapes-into-frame [frame-id shapes] (defn move-shapes-into-frame [frame-id shapes]
(ptk/reify ::move-shapes-into-frame (ptk/reify ::move-shapes-into-frame
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
to-move-shapes (->> (cp/select-toplevel-shapes objects {:include-frames? false}) to-move-shapes (->> (cp/select-toplevel-shapes objects {:include-frames? false})
@ -349,7 +346,7 @@
(us/assert ::set-of-uuid ids) (us/assert ::set-of-uuid ids)
(ptk/reify ::delete-shapes (ptk/reify ::delete-shapes
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
@ -504,7 +501,7 @@
[type frame-x frame-y data] [type frame-x frame-y data]
(ptk/reify ::create-and-add-shape (ptk/reify ::create-and-add-shape
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [{:keys [width height]} data (let [{:keys [width height]} data
[vbc-x vbc-y] (viewport-center state) [vbc-x vbc-y] (viewport-center state)
@ -524,7 +521,7 @@
[image {:keys [x y]}] [image {:keys [x y]}]
(ptk/reify ::image-uploaded (ptk/reify ::image-uploaded
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(let [{:keys [name width height id mtype]} image (let [{:keys [name width height id mtype]} image
shape {:name name shape {:name name
:width width :width width

View File

@ -7,17 +7,15 @@
(ns app.main.data.workspace.drawing (ns app.main.data.workspace.drawing
"Drawing interactions." "Drawing interactions."
(:require (:require
[beicon.core :as rx]
[potok.core :as ptk]
[app.common.spec :as us]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.data.workspace.common :as dwc] [app.main.data.workspace.common :as dwc]
[app.main.data.workspace.selection :as dws] [app.main.data.workspace.drawing.box :as box]
[app.main.data.workspace.path :as path]
[app.main.data.workspace.drawing.common :as common] [app.main.data.workspace.drawing.common :as common]
[app.main.data.workspace.drawing.curve :as curve] [app.main.data.workspace.drawing.curve :as curve]
[app.main.data.workspace.drawing.box :as box])) [app.main.data.workspace.path :as path]
[beicon.core :as rx]
[potok.core :as ptk]))
(declare start-drawing) (declare start-drawing)
(declare handle-drawing) (declare handle-drawing)
@ -38,7 +36,7 @@
(update :workspace-layout disj :scale-text))) (update :workspace-layout disj :scale-text)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(let [stoper (rx/filter (ptk/type? ::clear-drawing) stream)] (let [stoper (rx/filter (ptk/type? ::clear-drawing) stream)]
(rx/merge (rx/merge
(when (= tool :path) (when (= tool :path)
@ -88,16 +86,17 @@
(update-in state [:workspace-drawing :object] merge data))) (update-in state [:workspace-drawing :object] merge data)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(rx/of (case type (rx/of
:path (case type
(path/handle-new-shape) :path
(path/handle-new-shape)
:curve :curve
(curve/handle-drawing-curve) (curve/handle-drawing-curve)
;; default ;; default
(box/handle-drawing-box)))))) (box/handle-drawing-box))))))

View File

@ -21,7 +21,7 @@
(defn truncate-zero [num default] (defn truncate-zero [num default]
(if (mth/almost-zero? num) default num)) (if (mth/almost-zero? num) default num))
(defn resize-shape [{:keys [x y width height transform transform-inverse] :as shape} point lock?] (defn resize-shape [{:keys [x y width height] :as shape} point lock?]
(let [;; The new shape behaves like a resize on the bottom-right corner (let [;; The new shape behaves like a resize on the bottom-right corner
initial (gpt/point (+ x width) (+ y height)) initial (gpt/point (+ x width) (+ y height))
shapev (gpt/point width height) shapev (gpt/point width height)
@ -53,9 +53,7 @@
(ptk/reify ::handle-drawing-box (ptk/reify ::handle-drawing-box
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [{:keys [flags]} (:workspace-local state) (let [stoper? #(or (ms/mouse-up? %) (= % :interrupt))
stoper? #(or (ms/mouse-up? %) (= % :interrupt))
stoper (rx/filter stoper? stream) stoper (rx/filter stoper? stream)
initial @ms/mouse-position initial @ms/mouse-position

View File

@ -6,15 +6,13 @@
(ns app.main.data.workspace.drawing.common (ns app.main.data.workspace.drawing.common
(:require (:require
[beicon.core :as rx]
[potok.core :as ptk]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.main.data.workspace.common :as dwc] [app.main.data.workspace.common :as dwc]
[app.main.data.workspace.selection :as dws]
[app.main.data.workspace.undo :as dwu] [app.main.data.workspace.undo :as dwu]
[app.main.streams :as ms] [app.main.worker :as uw]
[app.main.worker :as uw])) [beicon.core :as rx]
[potok.core :as ptk]))
(def clear-drawing (def clear-drawing
(ptk/reify ::clear-drawing (ptk/reify ::clear-drawing
@ -25,7 +23,7 @@
(def handle-finish-drawing (def handle-finish-drawing
(ptk/reify ::handle-finish-drawing (ptk/reify ::handle-finish-drawing
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [shape (get-in state [:workspace-drawing :object])] (let [shape (get-in state [:workspace-drawing :object])]
(rx/concat (rx/concat
(when (:initialized? shape) (when (:initialized? shape)

View File

@ -6,7 +6,6 @@
(ns app.main.data.workspace.drawing.curve (ns app.main.data.workspace.drawing.curve
(:require (:require
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.geom.shapes.path :as gsp] [app.common.geom.shapes.path :as gsp]
[app.common.pages :as cp] [app.common.pages :as cp]
@ -19,7 +18,7 @@
(def simplify-tolerance 0.3) (def simplify-tolerance 0.3)
(defn stoper-event? [{:keys [type shift] :as event}] (defn stoper-event? [{:keys [type] :as event}]
(ms/mouse-event? event) (= type :up)) (ms/mouse-event? event) (= type :up))
(defn initialize-drawing [state] (defn initialize-drawing [state]
@ -73,9 +72,8 @@
(defn handle-drawing-curve [] (defn handle-drawing-curve []
(ptk/reify ::handle-drawing-curve (ptk/reify ::handle-drawing-curve
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(let [{:keys [flags]} (:workspace-local state) (let [stoper (rx/filter stoper-event? stream)
stoper (rx/filter stoper-event? stream)
mouse (rx/sample 10 ms/mouse-position)] mouse (rx/sample 10 ms/mouse-position)]
(rx/concat (rx/concat
(rx/of initialize-drawing) (rx/of initialize-drawing)

View File

@ -6,11 +6,11 @@
(ns app.main.data.workspace.grid (ns app.main.data.workspace.grid
(:require (:require
[beicon.core :as rx]
[potok.core :as ptk]
[app.common.data :as d] [app.common.data :as d]
[app.common.spec :as us] [app.common.spec :as us]
[app.main.data.workspace.changes :as dch])) [app.main.data.workspace.changes :as dch]
[beicon.core :as rx]
[potok.core :as ptk]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Grid ;; Grid
@ -40,7 +40,7 @@
(us/assert ::us/uuid frame-id) (us/assert ::us/uuid frame-id)
(ptk/reify ::add-frame-grid (ptk/reify ::add-frame-grid
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
data (get-in state [:workspace-data :pages-index page-id]) data (get-in state [:workspace-data :pages-index page-id])
params (or (get-in data [:options :saved-grids :square]) params (or (get-in data [:options :saved-grids :square])
@ -56,21 +56,21 @@
[frame-id index] [frame-id index]
(ptk/reify ::set-frame-grid (ptk/reify ::set-frame-grid
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(rx/of (dch/update-shapes [frame-id] (fn [o] (update o :grids (fnil #(d/remove-at-index % index) [])))))))) (rx/of (dch/update-shapes [frame-id] (fn [o] (update o :grids (fnil #(d/remove-at-index % index) []))))))))
(defn set-frame-grid (defn set-frame-grid
[frame-id index data] [frame-id index data]
(ptk/reify ::set-frame-grid (ptk/reify ::set-frame-grid
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(rx/of (dch/update-shapes [frame-id] #(assoc-in % [:grids index] data)))))) (rx/of (dch/update-shapes [frame-id] #(assoc-in % [:grids index] data))))))
(defn set-default-grid (defn set-default-grid
[type params] [type params]
(ptk/reify ::set-default-grid (ptk/reify ::set-default-grid
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [pid (:current-page-id state) (let [pid (:current-page-id state)
prev-value (get-in state [:workspace-data :pages-index pid :options :saved-grids type])] prev-value (get-in state [:workspace-data :pages-index pid :options :saved-grids type])]
(rx/of (dch/commit-changes (rx/of (dch/commit-changes

View File

@ -1,3 +1,9 @@
;; 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) UXBOX Labs SL
(ns app.main.data.workspace.groups (ns app.main.data.workspace.groups
(:require (:require
[app.common.data :as d] [app.common.data :as d]
@ -5,7 +11,6 @@
[app.common.pages :as cp] [app.common.pages :as cp]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.common :as dwc] [app.main.data.workspace.common :as dwc]
[app.main.data.workspace.selection :as dws]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
[beicon.core :as rx] [beicon.core :as rx]
[potok.core :as ptk])) [potok.core :as ptk]))
@ -22,7 +27,6 @@
[shapes prefix keep-name] [shapes prefix keep-name]
(let [selrect (gsh/selection-rect shapes) (let [selrect (gsh/selection-rect shapes)
frame-id (-> shapes first :frame-id) frame-id (-> shapes first :frame-id)
parent-id (-> shapes first :parent-id)
group-name (if (and keep-name group-name (if (and keep-name
(= (count shapes) 1) (= (count shapes) 1)
(= (:type (first shapes)) :group)) (= (:type (first shapes)) :group))
@ -166,7 +170,7 @@
(def group-selected (def group-selected
(ptk/reify ::group-selected (ptk/reify ::group-selected
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
@ -183,7 +187,7 @@
(def ungroup-selected (def ungroup-selected
(ptk/reify ::ungroup-selected (ptk/reify ::ungroup-selected
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
@ -200,7 +204,7 @@
(def mask-group (def mask-group
(ptk/reify ::mask-group (ptk/reify ::mask-group
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
@ -257,7 +261,7 @@
(def unmask-group (def unmask-group
(ptk/reify ::unmask-group (ptk/reify ::unmask-group
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state)] selected (wsh/lookup-selected state)]

View File

@ -46,7 +46,7 @@
(:component-id change) (:component-id change)
:objects :objects
(:id change)]) (:id change)])
:default nil)) :else nil))
prefix (if (:component-id change) "[C] " "[P] ") prefix (if (:component-id change) "[C] " "[P] ")
@ -90,7 +90,7 @@
(us/assert ::cp/color color) (us/assert ::cp/color color)
(ptk/reify ::add-color (ptk/reify ::add-color
ptk/WatchEvent ptk/WatchEvent
(watch [it state s] (watch [it _ _]
(let [rchg {:type :add-color (let [rchg {:type :add-color
:color color} :color color}
uchg {:type :del-color uchg {:type :del-color
@ -104,7 +104,7 @@
(us/assert ::cp/recent-color color) (us/assert ::cp/recent-color color)
(ptk/reify ::add-recent-color (ptk/reify ::add-recent-color
ptk/WatchEvent ptk/WatchEvent
(watch [it state s] (watch [it _ _]
(let [rchg {:type :add-recent-color (let [rchg {:type :add-recent-color
:color color}] :color color}]
(rx/of (dch/commit-changes {:redo-changes [rchg] (rx/of (dch/commit-changes {:redo-changes [rchg]
@ -123,7 +123,7 @@
(us/assert ::us/uuid file-id) (us/assert ::us/uuid file-id)
(ptk/reify ::update-color (ptk/reify ::update-color
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [[path name] (cp/parse-path-name (:name color)) (let [[path name] (cp/parse-path-name (:name color))
color (assoc color :path path :name name) color (assoc color :path path :name name)
prev (get-in state [:workspace-data :colors id]) prev (get-in state [:workspace-data :colors id])
@ -141,7 +141,7 @@
(us/assert ::us/uuid id) (us/assert ::us/uuid id)
(ptk/reify ::delete-color (ptk/reify ::delete-color
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [prev (get-in state [:workspace-data :colors id]) (let [prev (get-in state [:workspace-data :colors id])
rchg {:type :del-color rchg {:type :del-color
:id id} :id id}
@ -156,7 +156,7 @@
(us/assert ::cp/media-object media) (us/assert ::cp/media-object media)
(ptk/reify ::add-media (ptk/reify ::add-media
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it _ _]
(let [obj (select-keys media [:id :name :width :height :mtype]) (let [obj (select-keys media [:id :name :width :height :mtype])
rchg {:type :add-media rchg {:type :add-media
:object obj} :object obj}
@ -172,7 +172,7 @@
(us/assert ::us/string new-name) (us/assert ::us/string new-name)
(ptk/reify ::rename-media (ptk/reify ::rename-media
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [object (get-in state [:workspace-data :media id]) (let [object (get-in state [:workspace-data :media id])
[path name] (cp/parse-path-name new-name) [path name] (cp/parse-path-name new-name)
@ -195,7 +195,7 @@
(us/assert ::us/uuid id) (us/assert ::us/uuid id)
(ptk/reify ::delete-media (ptk/reify ::delete-media
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [prev (get-in state [:workspace-data :media id]) (let [prev (get-in state [:workspace-data :media id])
rchg {:type :del-media rchg {:type :del-media
:id id} :id id}
@ -212,7 +212,7 @@
(us/assert ::cp/typography typography) (us/assert ::cp/typography typography)
(ptk/reify ::add-typography (ptk/reify ::add-typography
ptk/WatchEvent ptk/WatchEvent
(watch [it state s] (watch [it _ _]
(let [rchg {:type :add-typography (let [rchg {:type :add-typography
:typography typography} :typography typography}
uchg {:type :del-typography uchg {:type :del-typography
@ -230,7 +230,7 @@
(us/assert ::us/uuid file-id) (us/assert ::us/uuid file-id)
(ptk/reify ::update-typography (ptk/reify ::update-typography
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [[path name] (cp/parse-path-name (:name typography)) (let [[path name] (cp/parse-path-name (:name typography))
typography (assoc typography :path path :name name) typography (assoc typography :path path :name name)
prev (get-in state [:workspace-data :typographies (:id typography)]) prev (get-in state [:workspace-data :typographies (:id typography)])
@ -248,7 +248,7 @@
(us/assert ::us/uuid id) (us/assert ::us/uuid id)
(ptk/reify ::delete-typography (ptk/reify ::delete-typography
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [prev (get-in state [:workspace-data :typographies id]) (let [prev (get-in state [:workspace-data :typographies id])
rchg {:type :del-typography rchg {:type :del-typography
:id id} :id id}
@ -262,7 +262,7 @@
"Add a new component to current file library, from the currently selected shapes." "Add a new component to current file library, from the currently selected shapes."
(ptk/reify ::add-component (ptk/reify ::add-component
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [file-id (:current-file-id state) (let [file-id (:current-file-id state)
page-id (:current-page-id state) page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
@ -285,7 +285,7 @@
(us/assert ::us/string new-name) (us/assert ::us/string new-name)
(ptk/reify ::rename-component (ptk/reify ::rename-component
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [[path name] (cp/parse-path-name new-name) (let [[path name] (cp/parse-path-name new-name)
component (get-in state [:workspace-data :components id]) component (get-in state [:workspace-data :components id])
objects (get component :objects) objects (get component :objects)
@ -315,7 +315,7 @@
[{:keys [id] :as params}] [{:keys [id] :as params}]
(ptk/reify ::duplicate-component (ptk/reify ::duplicate-component
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [component (cp/get-component id (let [component (cp/get-component id
(:current-file-id state) (:current-file-id state)
(dwlh/get-local-file state) (dwlh/get-local-file state)
@ -324,7 +324,7 @@
unames (set (map :name all-components)) unames (set (map :name all-components))
new-name (dwc/generate-unique-name unames (:name component)) new-name (dwc/generate-unique-name unames (:name component))
[new-shape new-shapes updated-shapes] [new-shape new-shapes _updated-shapes]
(dwlh/duplicate-component component) (dwlh/duplicate-component component)
rchanges [{:type :add-component rchanges [{:type :add-component
@ -346,7 +346,7 @@
(us/assert ::us/uuid id) (us/assert ::us/uuid id)
(ptk/reify ::delete-component (ptk/reify ::delete-component
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [component (get-in state [:workspace-data :components id]) (let [component (get-in state [:workspace-data :components id])
rchanges [{:type :del-component rchanges [{:type :del-component
@ -371,7 +371,7 @@
(us/assert ::us/point position) (us/assert ::us/point position)
(ptk/reify ::instantiate-component (ptk/reify ::instantiate-component
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [local-library (dwlh/get-local-file state) (let [local-library (dwlh/get-local-file state)
libraries (get state :workspace-libraries) libraries (get state :workspace-libraries)
component (cp/get-component component-id file-id local-library libraries) component (cp/get-component component-id file-id local-library libraries)
@ -449,7 +449,7 @@
(us/assert ::us/uuid id) (us/assert ::us/uuid id)
(ptk/reify ::detach-component (ptk/reify ::detach-component
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
shapes (cp/get-object-with-children id objects) shapes (cp/get-object-with-children id objects)
@ -511,13 +511,13 @@
(us/assert ::us/uuid file-id) (us/assert ::us/uuid file-id)
(ptk/reify ::nav-to-component-file (ptk/reify ::nav-to-component-file
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [file (get-in state [:workspace-libraries file-id]) (let [file (get-in state [:workspace-libraries file-id])
pparams {:project-id (:project-id file) pparams {:project-id (:project-id file)
:file-id (:id file)} :file-id (:id file)}
qparams {:page-id (first (get-in file [:data :pages])) qparams {:page-id (first (get-in file [:data :pages]))
:layout :assets}] :layout :assets}]
(st/emit! (rt/nav-new-window :workspace pparams qparams)))))) (rx/of (rt/nav-new-window :workspace pparams qparams))))))
(defn ext-library-changed (defn ext-library-changed
[file-id modified-at revn changes] [file-id modified-at revn changes]
@ -540,7 +540,7 @@
(us/assert ::us/uuid id) (us/assert ::us/uuid id)
(ptk/reify ::reset-component (ptk/reify ::reset-component
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(log/info :msg "RESET-COMPONENT of shape" :id (str id)) (log/info :msg "RESET-COMPONENT of shape" :id (str id))
(let [local-library (dwlh/get-local-file state) (let [local-library (dwlh/get-local-file state)
libraries (dwlh/get-libraries state) libraries (dwlh/get-libraries state)
@ -574,7 +574,7 @@
(us/assert ::us/uuid id) (us/assert ::us/uuid id)
(ptk/reify ::update-component (ptk/reify ::update-component
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(log/info :msg "UPDATE-COMPONENT of shape" :id (str id)) (log/info :msg "UPDATE-COMPONENT of shape" :id (str id))
(let [page-id (get state :current-page-id) (let [page-id (get state :current-page-id)
local-library (dwlh/get-local-file state) local-library (dwlh/get-local-file state)
@ -642,7 +642,7 @@
state)) state))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(log/info :msg "SYNC-FILE" (log/info :msg "SYNC-FILE"
:file (dwlh/pretty-file file-id state) :file (dwlh/pretty-file file-id state)
:library (dwlh/pretty-file library-id state)) :library (dwlh/pretty-file library-id state))
@ -702,7 +702,7 @@
(us/assert ::us/uuid library-id) (us/assert ::us/uuid library-id)
(ptk/reify ::sync-file-2nd-stage (ptk/reify ::sync-file-2nd-stage
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(log/info :msg "SYNC-FILE (2nd stage)" (log/info :msg "SYNC-FILE (2nd stage)"
:file (dwlh/pretty-file file-id state) :file (dwlh/pretty-file file-id state)
:library (dwlh/pretty-file library-id state)) :library (dwlh/pretty-file library-id state))
@ -727,7 +727,7 @@
(assoc-in state [:workspace-file :ignore-sync-until] (dt/now))) (assoc-in state [:workspace-file :ignore-sync-until] (dt/now)))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(rp/mutation :ignore-sync (rp/mutation :ignore-sync
{:file-id (get-in state [:workspace-file :id]) {:file-id (get-in state [:workspace-file :id])
:date (dt/now)})))) :date (dt/now)}))))
@ -737,7 +737,7 @@
(us/assert ::us/uuid file-id) (us/assert ::us/uuid file-id)
(ptk/reify ::notify-sync-file (ptk/reify ::notify-sync-file
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [libraries-need-sync (filter #(> (:modified-at %) (:synced-at %)) (let [libraries-need-sync (filter #(> (:modified-at %) (:synced-at %))
(vals (get state :workspace-libraries))) (vals (get state :workspace-libraries)))
do-update #(do (apply st/emit! (map (fn [library] do-update #(do (apply st/emit! (map (fn [library]

View File

@ -90,7 +90,7 @@
(assert (nil? (:shape-ref shape))) (assert (nil? (:shape-ref shape)))
(let [;; Ensure that the component root is not an instance and (let [;; Ensure that the component root is not an instance and
;; it's no longer tied to a frame. ;; it's no longer tied to a frame.
update-new-shape (fn [new-shape original-shape] update-new-shape (fn [new-shape _original-shape]
(cond-> new-shape (cond-> new-shape
true true
(-> (assoc :frame-id nil) (-> (assoc :frame-id nil)
@ -338,10 +338,10 @@
(defmulti generate-sync-shape (defmulti generate-sync-shape
"Generate changes to synchronize one shape with all assets of the given type "Generate changes to synchronize one shape with all assets of the given type
that is using, in the given library." that is using, in the given library."
(fn [type library-id state container shape] type)) (fn [type _library-id _state _container _shape] type))
(defmethod generate-sync-shape :components (defmethod generate-sync-shape :components
[_ library-id state container shape] [_ _ state container shape]
(generate-sync-shape-direct container (generate-sync-shape-direct container
(:id shape) (:id shape)
(get-local-file state) (get-local-file state)
@ -666,7 +666,7 @@
[(d/concat rchanges child-rchanges) [(d/concat rchanges child-rchanges)
(d/concat uchanges child-uchanges)])) (d/concat uchanges child-uchanges)]))
(defn- generate-sync-shape-inverse (defn generate-sync-shape-inverse
"Generate changes to update the component a shape is linked to, from "Generate changes to update the component a shape is linked to, from
the values in the shape and all its children." the values in the shape and all its children."
[page-id shape-id local-library libraries] [page-id shape-id local-library libraries]
@ -886,10 +886,10 @@
set-remote-synced? set-remote-synced?
(assoc :remote-synced? true)))) (assoc :remote-synced? true))))
update-original-shape (fn [original-shape new-shape] update-original-shape (fn [original-shape _new-shape]
original-shape) original-shape)
[new-shape new-shapes _] [_ new-shapes _]
(cp/clone-object component-shape (cp/clone-object component-shape
(:id parent-shape) (:id parent-shape)
(get component :objects) (get component :objects)
@ -939,7 +939,7 @@
(cp/get-parents (:id component-parent-shape) (cp/get-parents (:id component-parent-shape)
(:objects component)))) (:objects component))))
update-new-shape (fn [new-shape original-shape] update-new-shape (fn [new-shape _original-shape]
(reposition-shape new-shape (reposition-shape new-shape
root-instance root-instance
root-main)) root-main))
@ -950,7 +950,7 @@
:shape-ref (:id new-shape)) :shape-ref (:id new-shape))
original-shape)) original-shape))
[new-shape new-shapes updated-shapes] [_new-shape new-shapes updated-shapes]
(cp/clone-object shape (cp/clone-object shape
(:id component-parent-shape) (:id component-parent-shape)
(get page :objects) (get page :objects)
@ -1141,33 +1141,6 @@
:remote-synced? (:remote-synced? shape)}]})]] :remote-synced? (:remote-synced? shape)}]})]]
[rchanges uchanges])))) [rchanges uchanges]))))
(defn- set-touched-shapes-group
[shape container]
(if-not (:shape-ref shape)
empty-changes
(do
(log/info :msg (str "SET-TOUCHED-SHAPES-GROUP "
(if (cp/page? container) "[P] " "[C] ")
(:name shape)))
(let [rchanges [(make-change
container
{:type :mod-obj
:id (:id shape)
:operations
[{:type :set-touched
:touched (cp/set-touched-group
(:touched shape)
:shapes-group)}]})]
uchanges [(make-change
container
{:type :mod-obj
:id (:id shape)
:operations
[{:type :set-touched
:touched (:touched shape)}]})]]
[rchanges uchanges]))))
(defn- update-attrs (defn- update-attrs
"The main function that implements the attribute sync algorithm. Copy "The main function that implements the attribute sync algorithm. Copy
attributes that have changed in the origin shape to the dest shape. attributes that have changed in the origin shape to the dest shape.

View File

@ -16,11 +16,7 @@
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.libraries :as dwl] [app.main.data.workspace.libraries :as dwl]
[app.main.data.workspace.persistence :as dwp] [app.main.data.workspace.persistence :as dwp]
[app.main.repo :as rp]
[app.main.store :as st]
[app.main.streams :as ms] [app.main.streams :as ms]
[app.util.avatars :as avatars]
[app.util.i18n :as i18n :refer [tr]]
[app.util.time :as dt] [app.util.time :as dt]
[app.util.websockets :as ws] [app.util.websockets :as ws]
[beicon.core :as rx] [beicon.core :as rx]
@ -104,7 +100,7 @@
[file-id] [file-id]
(ptk/reify ::send-keepalive (ptk/reify ::send-keepalive
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ state _]
(when-let [ws (get-in state [:ws file-id])] (when-let [ws (get-in state [:ws file-id])]
(ws/send! ws {:type :keepalive}))))) (ws/send! ws {:type :keepalive})))))
@ -112,9 +108,8 @@
[file-id point] [file-id point]
(ptk/reify ::handle-pointer-update (ptk/reify ::handle-pointer-update
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ state _]
(let [ws (get-in state [:ws file-id]) (let [ws (get-in state [:ws file-id])
sid (:session-id state)
pid (:current-page-id state) pid (:current-page-id state)
msg {:type :pointer-update msg {:type :pointer-update
:page-id pid :page-id pid
@ -128,7 +123,7 @@
[file-id] [file-id]
(ptk/reify ::finalize (ptk/reify ::finalize
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(when-let [ws (get-in state [:ws file-id])] (when-let [ws (get-in state [:ws file-id])]
(ws/-close ws)) (ws/-close ws))
(rx/of ::finalize)))) (rx/of ::finalize))))
@ -187,7 +182,7 @@
(update state :workspace-presence update-presence)))))) (update state :workspace-presence update-presence))))))
(defn handle-pointer-update (defn handle-pointer-update
[{:keys [page-id profile-id session-id x y] :as msg}] [{:keys [page-id session-id x y] :as msg}]
(ptk/reify ::handle-pointer-update (ptk/reify ::handle-pointer-update
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
@ -213,7 +208,7 @@
(us/assert ::file-change-event msg) (us/assert ::file-change-event msg)
(ptk/reify ::handle-file-change (ptk/reify ::handle-file-change
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(let [changes-by-pages (group-by :page-id changes) (let [changes-by-pages (group-by :page-id changes)
process-page-changes process-page-changes
(fn [[page-id changes]] (fn [[page-id changes]]
@ -239,7 +234,7 @@
(us/assert ::library-change-event msg) (us/assert ::library-change-event msg)
(ptk/reify ::handle-library-change (ptk/reify ::handle-library-change
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(when (contains? (:workspace-libraries state) file-id) (when (contains? (:workspace-libraries state) file-id)
(rx/of (dwl/ext-library-changed file-id modified-at revn changes) (rx/of (dwl/ext-library-changed file-id modified-at revn changes)
(dwl/notify-sync-file file-id)))))) (dwl/notify-sync-file file-id))))))

View File

@ -84,7 +84,7 @@
(assoc-in state (st/get-path state :content) content))) (assoc-in state (st/get-path state :content) content)))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
page-id (:current-page-id state) page-id (:current-page-id state)
id (get-in state [:workspace-local :edition]) id (get-in state [:workspace-local :edition])

View File

@ -16,7 +16,8 @@
[state] [state]
(dissoc state :last-point :prev-handler :drag-handler :preview)) (dissoc state :last-point :prev-handler :drag-handler :preview))
(defn finish-path [source] (defn finish-path
[_source]
(ptk/reify ::finish-path (ptk/reify ::finish-path
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]

View File

@ -17,7 +17,6 @@
[app.main.data.workspace.path.spec :as spec] [app.main.data.workspace.path.spec :as spec]
[app.main.data.workspace.path.state :as st] [app.main.data.workspace.path.state :as st]
[app.main.data.workspace.path.streams :as streams] [app.main.data.workspace.path.streams :as streams]
[app.main.data.workspace.path.tools :as tools]
[app.main.data.workspace.path.undo :as undo] [app.main.data.workspace.path.undo :as undo]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
[app.main.streams :as ms] [app.main.streams :as ms]
@ -60,9 +59,8 @@
state))))) state)))))
(defn drag-handler (defn drag-handler
([{:keys [x y alt? shift?] :as position}] ([position]
(drag-handler nil nil :c1 position)) (drag-handler nil nil :c1 position))
([position index prefix {:keys [x y alt? shift?]}] ([position index prefix {:keys [x y alt? shift?]}]
(ptk/reify ::drag-handler (ptk/reify ::drag-handler
ptk/UpdateEvent ptk/UpdateEvent
@ -110,7 +108,7 @@
(update-in (st/get-path state) helpers/update-selrect)))) (update-in (st/get-path state) helpers/update-selrect))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [id (st/get-path-id state) (let [id (st/get-path-id state)
handler (get-in state [:workspace-local :edit-path id :prev-handler])] handler (get-in state [:workspace-local :edit-path id :prev-handler])]
;; Update the preview because can be outdated after the dragging ;; Update the preview because can be outdated after the dragging
@ -124,9 +122,6 @@
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [id (st/get-path-id state) (let [id (st/get-path-id state)
zoom (get-in state [:workspace-local :zoom])
start-position @ms/mouse-position
stop-stream stop-stream
(->> stream (rx/filter #(or (helpers/end-path-event? %) (->> stream (rx/filter #(or (helpers/end-path-event? %)
(ms/mouse-up? %)))) (ms/mouse-up? %))))
@ -166,9 +161,7 @@
(ptk/reify ::start-path-from-point (ptk/reify ::start-path-from-point
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [start-point @ms/mouse-position (let [mouse-up (->> stream (rx/filter #(or (helpers/end-path-event? %)
zoom (get-in state [:workspace-local :zoom])
mouse-up (->> stream (rx/filter #(or (helpers/end-path-event? %)
(ms/mouse-up? %)))) (ms/mouse-up? %))))
content (get-in state (st/get-path state :content)) content (get-in state (st/get-path state :content))
points (upg/content->points content) points (upg/content->points content)
@ -195,7 +188,7 @@
(rx/merge-map #(rx/empty)))) (rx/merge-map #(rx/empty))))
(defn make-drag-stream (defn make-drag-stream
[stream snap-toggled zoom points down-event] [stream snap-toggled _zoom points down-event]
(let [mouse-up (->> stream (rx/filter #(or (helpers/end-path-event? %) (let [mouse-up (->> stream (rx/filter #(or (helpers/end-path-event? %)
(ms/mouse-up? %)))) (ms/mouse-up? %))))
@ -211,7 +204,7 @@
(rx/of (finish-drag))))))) (rx/of (finish-drag)))))))
(defn handle-drawing-path (defn handle-drawing-path
[id] [_id]
(ptk/reify ::handle-drawing-path (ptk/reify ::handle-drawing-path
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
@ -278,11 +271,11 @@
state))) state)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(->> (rx/of (setup-frame-path) (rx/of (setup-frame-path)
dwdc/handle-finish-drawing dwdc/handle-finish-drawing
(dwc/start-edition-mode shape-id) (dwc/start-edition-mode shape-id)
(change-edit-mode :draw)))))) (change-edit-mode :draw)))))
(defn handle-new-shape (defn handle-new-shape
"Creates a new path shape" "Creates a new path shape"
@ -333,7 +326,7 @@
(defn check-changed-content [] (defn check-changed-content []
(ptk/reify ::check-changed-content (ptk/reify ::check-changed-content
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [id (st/get-path-id state) (let [id (st/get-path-id state)
content (get-in state (st/get-path state :content)) content (get-in state (st/get-path state :content))
old-content (get-in state [:workspace-local :edit-path id :old-content]) old-content (get-in state [:workspace-local :edit-path id :old-content])
@ -354,7 +347,7 @@
id (assoc-in [:workspace-local :edit-path id :edit-mode] mode)))) id (assoc-in [:workspace-local :edit-path id :edit-mode] mode))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [id (st/get-path-id state)] (let [id (st/get-path-id state)]
(cond (cond
(and id (= :move mode)) (rx/of (common/finish-path "change-edit-mode")) (and id (= :move mode)) (rx/of (common/finish-path "change-edit-mode"))

View File

@ -8,11 +8,9 @@
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.math :as mth]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.path.changes :as changes] [app.main.data.workspace.path.changes :as changes]
[app.main.data.workspace.path.common :as common]
[app.main.data.workspace.path.drawing :as drawing] [app.main.data.workspace.path.drawing :as drawing]
[app.main.data.workspace.path.helpers :as helpers] [app.main.data.workspace.path.helpers :as helpers]
[app.main.data.workspace.path.selection :as selection] [app.main.data.workspace.path.selection :as selection]
@ -47,7 +45,7 @@
(defn apply-content-modifiers [] (defn apply-content-modifiers []
(ptk/reify ::apply-content-modifiers (ptk/reify ::apply-content-modifiers
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
id (st/get-path-id state) id (st/get-path-id state)
@ -137,7 +135,7 @@
[position shift?] [position shift?]
(ptk/reify ::start-move-path-point (ptk/reify ::start-move-path-point
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [id (get-in state [:workspace-local :edition]) (let [id (get-in state [:workspace-local :edition])
selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{}) selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{})
selected? (contains? selected-points position)] selected? (contains? selected-points position)]
@ -151,7 +149,7 @@
[start-position] [start-position]
(ptk/reify ::drag-selected-points (ptk/reify ::drag-selected-points
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state stream]
(let [stopper (->> stream (rx/filter ms/mouse-up?)) (let [stopper (->> stream (rx/filter ms/mouse-up?))
id (get-in state [:workspace-local :edition]) id (get-in state [:workspace-local :edition])
snap-toggled (get-in state [:workspace-local :edit-path id :snap-toggled]) snap-toggled (get-in state [:workspace-local :edit-path id :snap-toggled])
@ -206,7 +204,7 @@
state))) state)))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state stream]
(let [id (get-in state [:workspace-local :edition]) (let [id (get-in state [:workspace-local :edition])
current-move (get-in state [:workspace-local :edit-path id :current-move])] current-move (get-in state [:workspace-local :edit-path id :current-move])]
(if (= same-event current-move) (if (= same-event current-move)
@ -240,7 +238,7 @@
[index prefix] [index prefix]
(ptk/reify ::start-move-handler (ptk/reify ::start-move-handler
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state stream]
(let [id (get-in state [:workspace-local :edition]) (let [id (get-in state [:workspace-local :edition])
cx (d/prefix-keyword prefix :x) cx (d/prefix-keyword prefix :x)
cy (d/prefix-keyword prefix :y) cy (d/prefix-keyword prefix :y)
@ -297,7 +295,7 @@
(assoc-in [:workspace-local :edit-path id :edit-mode] :draw)))) (assoc-in [:workspace-local :edit-path id :edit-mode] :draw))))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state stream]
(let [mode (get-in state [:workspace-local :edit-path id :edit-mode])] (let [mode (get-in state [:workspace-local :edit-path id :edit-mode])]
(rx/concat (rx/concat
(rx/of (undo/start-path-undo)) (rx/of (undo/start-path-undo))
@ -327,5 +325,5 @@
(update-in (st/get-path state :content) upt/split-segments #{from-p to-p} t)))) (update-in (st/get-path state :content) upt/split-segments #{from-p to-p} t))))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(rx/of (changes/save-path-content {:preserve-move-to true}))))) (rx/of (changes/save-path-content {:preserve-move-to true})))))

View File

@ -6,25 +6,23 @@
(ns app.main.data.workspace.path.helpers (ns app.main.data.workspace.path.helpers
(:require (:require
[app.common.data :as d]
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth] [app.common.math :as mth]
[app.main.data.workspace.path.common :as common] [app.main.data.workspace.path.common :as common]
[app.main.data.workspace.path.state :refer [get-path]]
[app.main.streams :as ms] [app.main.streams :as ms]
[app.util.path.commands :as upc] [app.util.path.commands :as upc]
[app.util.path.subpaths :as ups] [app.util.path.subpaths :as ups]
[potok.core :as ptk])) [potok.core :as ptk]))
(defn end-path-event? [{:keys [type shift] :as event}] (defn end-path-event? [event]
(or (= (ptk/type event) ::common/finish-path) (or (= (ptk/type event) ::common/finish-path)
(= (ptk/type event) :esc-pressed) (= (ptk/type event) :esc-pressed)
(= :app.main.data.workspace.common/clear-edition-mode (ptk/type event)) (= :app.main.data.workspace.common/clear-edition-mode (ptk/type event))
(= :app.main.data.workspace/finalize-page (ptk/type event)) (= :app.main.data.workspace/finalize-page (ptk/type event))
(= event :interrupt) ;; ESC (= event :interrupt) ;; ESC
(and (ms/mouse-double-click? event)))) (ms/mouse-double-click? event)))
(defn content-center (defn content-center
[content] [content]
@ -35,7 +33,6 @@
(defn content->points+selrect (defn content->points+selrect
"Given the content of a shape, calculate its points and selrect" "Given the content of a shape, calculate its points and selrect"
[shape content] [shape content]
(let [{:keys [flip-x flip-y]} shape (let [{:keys [flip-x flip-y]} shape
transform transform
(cond-> (:transform shape (gmt/matrix)) (cond-> (:transform shape (gmt/matrix))

View File

@ -22,7 +22,7 @@
(defn esc-pressed [] (defn esc-pressed []
(ptk/reify :esc-pressed (ptk/reify :esc-pressed
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
;; Not interrupt when we're editing a path ;; Not interrupt when we're editing a path
(let [edition-id (or (get-in state [:workspace-drawing :object :id]) (let [edition-id (or (get-in state [:workspace-drawing :object :id])
(get-in state [:workspace-local :edition])) (get-in state [:workspace-local :edition]))

View File

@ -40,8 +40,8 @@
(s/def ::content-entry (s/def ::content-entry
(s/keys :req-un [::command] (s/keys :req-un [::command]
:req-opt [::params :opt-un [::params
::relative?])) ::relative?]))
(s/def ::content (s/def ::content
(s/coll-of ::content-entry :kind vector?)) (s/coll-of ::content-entry :kind vector?))

View File

@ -6,17 +6,16 @@
(ns app.main.data.workspace.path.streams (ns app.main.data.workspace.path.streams
(:require (:require
[app.main.data.workspace.path.helpers :as helpers]
[app.main.data.workspace.path.state :as state]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.math :as mth]
[app.main.data.workspace.path.state :as state]
[app.main.snap :as snap]
[app.main.store :as st] [app.main.store :as st]
[app.main.streams :as ms] [app.main.streams :as ms]
[app.util.path.geom :as upg]
[beicon.core :as rx] [beicon.core :as rx]
[potok.core :as ptk]
[app.common.math :as mth]
[app.main.snap :as snap]
[okulary.core :as l] [okulary.core :as l]
[app.util.path.geom :as upg])) [potok.core :as ptk]))
(defonce drag-threshold 5) (defonce drag-threshold 5)
@ -50,7 +49,7 @@
(if (= value ::empty) (if (= value ::empty)
not-drag-stream not-drag-stream
(rx/empty))))) (rx/empty)))))
(->> position-stream (->> position-stream
(rx/merge-map (fn [] to-stream))))))) (rx/merge-map (fn [] to-stream)))))))
@ -107,7 +106,7 @@
(<= (- 180 rot-angle) 5))] (<= (- 180 rot-angle) 5))]
(cond (cond
snap-opposite-angle? snap-opposite-angle?
(let [rot-handler (gpt/rotate handler node (- 180 (* rot-sign rot-angle))) (let [rot-handler (gpt/rotate handler node (- 180 (* rot-sign rot-angle)))
snap (gpt/to-vec handler rot-handler)] snap (gpt/to-vec handler rot-handler)]
(merge position (gpt/add position snap))) (merge position (gpt/add position snap)))
@ -122,7 +121,7 @@
(rx/map check-path-snap)))) (rx/map check-path-snap))))
(defn position-stream (defn position-stream
[snap-toggled points] [snap-toggled _points]
(let [zoom (get-in @st/state [:workspace-local :zoom] 1) (let [zoom (get-in @st/state [:workspace-local :zoom] 1)
;; ranges (snap/create-ranges points) ;; ranges (snap/create-ranges points)
d-pos (/ snap/snap-path-accuracy zoom) d-pos (/ snap/snap-path-accuracy zoom)

View File

@ -6,11 +6,9 @@
(ns app.main.data.workspace.path.tools (ns app.main.data.workspace.path.tools
(:require (:require
[app.common.geom.point :as gpt]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.common :as dwc] [app.main.data.workspace.common :as dwc]
[app.main.data.workspace.path.changes :as changes] [app.main.data.workspace.path.changes :as changes]
[app.main.data.workspace.path.common :as common]
[app.main.data.workspace.path.state :as st] [app.main.data.workspace.path.state :as st]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
[app.util.path.subpaths :as ups] [app.util.path.subpaths :as ups]
@ -25,7 +23,7 @@
([points tool-fn] ([points tool-fn]
(ptk/reify ::process-path-tool (ptk/reify ::process-path-tool
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
id (st/get-path-id state) id (st/get-path-id state)
page-id (:current-page-id state) page-id (:current-page-id state)
@ -33,7 +31,7 @@
selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{}) selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{})
points (or points selected-points)] points (or points selected-points)]
(when (and (not (empty? points)) (some? shape)) (when (and (seq points) (some? shape))
(let [new-content (-> (tool-fn (:content shape) points) (let [new-content (-> (tool-fn (:content shape) points)
(ups/close-subpaths)) (ups/close-subpaths))
[rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)] [rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)]

View File

@ -9,8 +9,8 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.data.undo-stack :as u] [app.common.data.undo-stack :as u]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.data.workspace.path.state :as st]
[app.main.data.workspace.path.changes :as changes] [app.main.data.workspace.path.changes :as changes]
[app.main.data.workspace.path.state :as st]
[app.main.store :as store] [app.main.store :as store]
[beicon.core :as rx] [beicon.core :as rx]
[okulary.core :as l] [okulary.core :as l]
@ -64,7 +64,7 @@
undo-stack))))) undo-stack)))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(rx/of (changes/save-path-content {:preserve-move-to true}))))) (rx/of (changes/save-path-content {:preserve-move-to true})))))
(defn redo-path [] (defn redo-path []
@ -82,7 +82,7 @@
undo-stack)))) undo-stack))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
(rx/of (changes/save-path-content))))) (rx/of (changes/save-path-content)))))
(defn merge-head (defn merge-head
@ -92,10 +92,9 @@
(ptk/reify ::add-undo-entry (ptk/reify ::add-undo-entry
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [id (st/get-path-id state) (let [id (st/get-path-id state)
entry (make-entry state)
stack (get-in state [:workspace-local :edit-path id :undo-stack]) stack (get-in state [:workspace-local :edit-path id :undo-stack])
head (u/peek stack) head (u/peek stack)
stack (-> stack (u/undo) (u/fixup head))] stack (-> stack (u/undo) (u/fixup head))]
(-> state (-> state
(d/assoc-in-when (d/assoc-in-when
@ -145,7 +144,7 @@
assoc assoc
:undo-lock lock :undo-lock lock
:undo-stack (u/make-stack))))) :undo-stack (u/make-stack)))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [undo-lock (get-in state [:workspace-local :edit-path (st/get-path-id state) :undo-lock])] (let [undo-lock (get-in state [:workspace-local :edit-path (st/get-path-id state) :undo-lock])]

View File

@ -8,8 +8,6 @@
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.geom.point :as gpt]
[app.common.media :as cm]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
@ -26,11 +24,9 @@
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.repo :as rp] [app.main.repo :as rp]
[app.main.store :as st] [app.main.store :as st]
[app.util.avatars :as avatars]
[app.util.http :as http] [app.util.http :as http]
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.object :as obj] [app.util.object :as obj]
[app.util.router :as rt]
[app.util.time :as dt] [app.util.time :as dt]
[app.util.uri :as uu] [app.util.uri :as uu]
[beicon.core :as rx] [beicon.core :as rx]
@ -52,7 +48,7 @@
[file-id] [file-id]
(ptk/reify ::initialize-persistence (ptk/reify ::initialize-persistence
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ _ stream]
(let [stoper (rx/filter #(= ::finalize %) stream) (let [stoper (rx/filter #(= ::finalize %) stream)
forcer (rx/filter #(= ::force-persist %) stream) forcer (rx/filter #(= ::force-persist %) stream)
notifier (->> stream notifier (->> stream
@ -120,12 +116,11 @@
(ptk/reify ::persist-changes (ptk/reify ::persist-changes
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [conj (fnil conj []) (let [into* (fnil into [])]
into* (fnil into [])]
(update-in state [:workspace-persistence :queue] into* changes))) (update-in state [:workspace-persistence :queue] into* changes)))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [sid (:session-id state) (let [sid (:session-id state)
file (get state :workspace-file) file (get state :workspace-file)
queue (get-in state [:workspace-persistence :queue] []) queue (get-in state [:workspace-persistence :queue] [])
@ -176,7 +171,7 @@
(us/verify ::us/uuid file-id) (us/verify ::us/uuid file-id)
(ptk/reify ::persist-synchronous-changes (ptk/reify ::persist-synchronous-changes
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [sid (:session-id state) (let [sid (:session-id state)
file (get-in state [:workspace-libraries file-id]) file (get-in state [:workspace-libraries file-id])
@ -255,11 +250,11 @@
(declare fetch-libraries-content) (declare fetch-libraries-content)
(declare bundle-fetched) (declare bundle-fetched)
(defn- fetch-bundle (defn fetch-bundle
[project-id file-id] [project-id file-id]
(ptk/reify ::fetch-bundle (ptk/reify ::fetch-bundle
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(->> (rx/zip (rp/query :file {:id file-id}) (->> (rx/zip (rp/query :file {:id file-id})
(rp/query :team-users {:file-id file-id}) (rp/query :team-users {:file-id file-id})
(rp/query :project {:id project-id}) (rp/query :project {:id project-id})
@ -285,7 +280,7 @@
(assoc-in state [:workspace-file :is-shared] is-shared)) (assoc-in state [:workspace-file :is-shared] is-shared))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(let [params {:id id :is-shared is-shared}] (let [params {:id id :is-shared is-shared}]
(->> (rp/mutation :set-file-shared params) (->> (rp/mutation :set-file-shared params)
(rx/ignore)))))) (rx/ignore))))))
@ -300,7 +295,7 @@
(us/assert ::us/uuid team-id) (us/assert ::us/uuid team-id)
(ptk/reify ::fetch-shared-files (ptk/reify ::fetch-shared-files
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(->> (rp/query :team-shared-files {:team-id team-id}) (->> (rp/query :team-shared-files {:team-id team-id})
(rx/map shared-files-fetched))))) (rx/map shared-files-fetched)))))
@ -320,7 +315,7 @@
[file-id library-id] [file-id library-id]
(ptk/reify ::link-file-to-library (ptk/reify ::link-file-to-library
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(let [fetched #(assoc-in %2 [:workspace-libraries (:id %1)] %1) (let [fetched #(assoc-in %2 [:workspace-libraries (:id %1)] %1)
params {:file-id file-id params {:file-id file-id
:library-id library-id}] :library-id library-id}]
@ -332,7 +327,7 @@
[file-id library-id] [file-id library-id]
(ptk/reify ::unlink-file-from-library (ptk/reify ::unlink-file-from-library
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(let [unlinked #(d/dissoc-in % [:workspace-libraries library-id]) (let [unlinked #(d/dissoc-in % [:workspace-libraries library-id])
params {:file-id file-id params {:file-id file-id
:library-id library-id}] :library-id library-id}]
@ -348,7 +343,7 @@
(->> (rx/of (-> (tubax/xml->clj text) (->> (rx/of (-> (tubax/xml->clj text)
(assoc :name name)))) (assoc :name name))))
(catch :default err (catch :default _err
(rx/throw {:type :svg-parser})))) (rx/throw {:type :svg-parser}))))
(defn fetch-svg [name uri] (defn fetch-svg [name uri]
@ -458,7 +453,7 @@
(s/def ::process-media-objects (s/def ::process-media-objects
(s/and (s/and
(s/keys :req-un [::file-id ::local?] (s/keys :req-un [::file-id ::local?]
:opt-in [::name ::data ::uris ::mtype]) :opt-un [::name ::data ::uris ::mtype])
(fn [props] (fn [props]
(or (contains? props :blobs) (or (contains? props :blobs)
(contains? props :uris))))) (contains? props :uris)))))
@ -468,7 +463,7 @@
(us/assert ::process-media-objects params) (us/assert ::process-media-objects params)
(ptk/reify ::process-media-objects (ptk/reify ::process-media-objects
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(rx/concat (rx/concat
(rx/of (dm/show {:content (tr "media.loading") (rx/of (dm/show {:content (tr "media.loading")
:type :info :type :info
@ -515,7 +510,7 @@
(us/assert ::clone-media-objects-params params) (us/assert ::clone-media-objects-params params)
(ptk/reify ::clone-media-objects (ptk/reify ::clone-media-objects
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
(let [{:keys [on-success on-error] (let [{:keys [on-success on-error]
:or {on-success identity :or {on-success identity
on-error identity}} (meta params) on-error identity}} (meta params)
@ -548,7 +543,7 @@
[ids] [ids]
(ptk/reify ::remove-thumbnails (ptk/reify ::remove-thumbnails
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ _]
;; Removes the thumbnail while it's regenerated ;; Removes the thumbnail while it's regenerated
(rx/of (dch/update-shapes (rx/of (dch/update-shapes
ids ids

View File

@ -61,7 +61,7 @@
:height (mth/abs (- end-y start-y))}))] :height (mth/abs (- end-y start-y))}))]
(ptk/reify ::handle-selection (ptk/reify ::handle-selection
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(let [stop? (fn [event] (or (dwc/interrupt? event) (ms/mouse-up? event))) (let [stop? (fn [event] (or (dwc/interrupt? event) (ms/mouse-up? event)))
stoper (->> stream (rx/filter stop?))] stoper (->> stream (rx/filter stop?))]
(rx/concat (rx/concat
@ -100,7 +100,7 @@
(conj selected id)))))) (conj selected id))))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)] objects (wsh/lookup-page-objects state page-id)]
(rx/of (dwc/expand-all-parents [id] objects))))))) (rx/of (dwc/expand-all-parents [id] objects)))))))
@ -136,7 +136,7 @@
(assoc-in state [:workspace-local :selected] ids)) (assoc-in state [:workspace-local :selected] ids))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [objects (wsh/lookup-page-objects state)] (let [objects (wsh/lookup-page-objects state)]
(rx/of (dwc/expand-all-parents ids objects)))))) (rx/of (dwc/expand-all-parents ids objects))))))
@ -144,7 +144,7 @@
[] []
(ptk/reify ::select-all (ptk/reify ::select-all
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
new-selected (let [selected-objs new-selected (let [selected-objs
@ -204,7 +204,7 @@
[preserve?] [preserve?]
(ptk/reify ::select-shapes-by-current-selrect (ptk/reify ::select-shapes-by-current-selrect
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state) objects (wsh/lookup-page-objects state)
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
@ -224,25 +224,23 @@
(rx/map select-shapes)))))))) (rx/map select-shapes))))))))
(defn select-inside-group (defn select-inside-group
([group-id position] (select-inside-group group-id position false)) [group-id position]
([group-id position deep-children] (ptk/reify ::select-inside-group
(ptk/reify ::select-inside-group ptk/WatchEvent
ptk/WatchEvent (watch [_ state _]
(watch [_ state stream] (let [page-id (:current-page-id state)
(let [page-id (:current-page-id state) objects (wsh/lookup-page-objects state page-id)
objects (wsh/lookup-page-objects state page-id) group (get objects group-id)
group (get objects group-id) children (map #(get objects %) (:shapes group))
children (map #(get objects %) (:shapes group))
;; We need to reverse the children because if two children ;; We need to reverse the children because if two children
;; overlap we want to select the one that's over (and it's ;; overlap we want to select the one that's over (and it's
;; in the later vector position ;; in the later vector position
selected (->> children selected (->> children
reverse reverse
(d/seek #(geom/has-point? % position)))] (d/seek #(geom/has-point? % position)))]
(when selected (when selected
(rx/of (select-shape (:id selected))))))))) (rx/of (select-shape (:id selected))))))))
;; --- Duplicate Shapes ;; --- Duplicate Shapes
(declare prepare-duplicate-change) (declare prepare-duplicate-change)
@ -321,7 +319,6 @@
name (dwc/generate-unique-name names (:name obj)) name (dwc/generate-unique-name names (:name obj))
renamed-obj (assoc obj :id id :name name) renamed-obj (assoc obj :id id :name name)
moved-obj (geom/move renamed-obj delta) moved-obj (geom/move renamed-obj delta)
frames (cp/select-frames objects)
parent-id (or parent-id frame-id) parent-id (or parent-id frame-id)
children-changes children-changes
@ -378,7 +375,7 @@
(def duplicate-selected (def duplicate-selected
(ptk/reify ::duplicate-selected (ptk/reify ::duplicate-selected
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)

View File

@ -10,14 +10,13 @@
[app.main.data.workspace :as dw] [app.main.data.workspace :as dw]
[app.main.data.workspace.colors :as mdc] [app.main.data.workspace.colors :as mdc]
[app.main.data.workspace.common :as dwc] [app.main.data.workspace.common :as dwc]
[app.main.data.workspace.undo :as dwu]
[app.main.data.workspace.drawing :as dwd] [app.main.data.workspace.drawing :as dwd]
[app.main.data.workspace.libraries :as dwl] [app.main.data.workspace.libraries :as dwl]
[app.main.data.workspace.texts :as dwtxt] [app.main.data.workspace.texts :as dwtxt]
[app.main.data.workspace.transforms :as dwt] [app.main.data.workspace.transforms :as dwt]
[app.main.data.workspace.undo :as dwu]
[app.main.store :as st] [app.main.store :as st]
[app.util.dom :as dom] [app.util.dom :as dom]))
[potok.core :as ptk]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Shortcuts ;; Shortcuts

View File

@ -9,7 +9,6 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.proportions :as gpr]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
@ -18,14 +17,12 @@
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
[app.main.repo :as rp] [app.main.repo :as rp]
[app.util.color :as uc] [app.util.color :as uc]
[app.util.object :as obj]
[app.util.path.parser :as upp] [app.util.path.parser :as upp]
[app.util.svg :as usvg] [app.util.svg :as usvg]
[app.util.uri :as uu] [app.util.uri :as uu]
[beicon.core :as rx] [beicon.core :as rx]
[cuerdas.core :as str] [cuerdas.core :as str]
[potok.core :as ptk] [potok.core :as ptk]))
[promesa.core :as p]))
(defonce default-rect {:x 0 :y 0 :width 1 :height 1 :rx 0 :ry 0}) (defonce default-rect {:x 0 :y 0 :width 1 :height 1 :rx 0 :ry 0})
(defonce default-circle {:r 0 :cx 0 :cy 0}) (defonce default-circle {:r 0 :cx 0 :cy 0})
@ -163,7 +160,7 @@
(gsh/setup-selrect)))) (gsh/setup-selrect))))
(defn create-path-shape [name frame-id svg-data {:keys [attrs] :as data}] (defn create-path-shape [name frame-id svg-data {:keys [attrs] :as data}]
(when (and (contains? attrs :d) (not (empty? (:d attrs)) )) (when (and (contains? attrs :d) (seq (:d attrs)))
(let [svg-transform (usvg/parse-transform (:transform attrs)) (let [svg-transform (usvg/parse-transform (:transform attrs))
path-content (upp/parse-path (:d attrs)) path-content (upp/parse-path (:d attrs))
content (cond-> path-content content (cond-> path-content
@ -387,7 +384,7 @@
[svg-data file-id position] [svg-data file-id position]
(ptk/reify ::svg-uploaded (ptk/reify ::svg-uploaded
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ _]
;; Once the SVG is uploaded, we need to extract all the bitmap ;; Once the SVG is uploaded, we need to extract all the bitmap
;; images and upload them separatelly, then proceed to create ;; images and upload them separatelly, then proceed to create
;; all shapes. ;; all shapes.
@ -414,7 +411,7 @@
[svg-data {:keys [x y] :as position}] [svg-data {:keys [x y] :as position}]
(ptk/reify ::create-svg-shapes (ptk/reify ::create-svg-shapes
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(try (try
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)

View File

@ -16,17 +16,11 @@
[app.main.data.workspace.common :as dwc] [app.main.data.workspace.common :as dwc]
[app.main.data.workspace.selection :as dws] [app.main.data.workspace.selection :as dws]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
[app.main.data.workspace.transforms :as dwt]
[app.main.data.workspace.undo :as dwu] [app.main.data.workspace.undo :as dwu]
[app.main.fonts :as fonts] [app.util.router :as rt]
[app.util.object :as obj]
[app.util.text-editor :as ted] [app.util.text-editor :as ted]
[app.util.timers :as ts] [app.util.timers :as ts]
[app.util.router :as rt]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s]
[cuerdas.core :as str]
[goog.object :as gobj]
[potok.core :as ptk])) [potok.core :as ptk]))
(defn update-editor (defn update-editor
@ -42,7 +36,7 @@
[] []
(ptk/reify ::focus-editor (ptk/reify ::focus-editor
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ state _]
(when-let [editor (:workspace-editor state)] (when-let [editor (:workspace-editor state)]
(ts/schedule #(.focus ^js editor)))))) (ts/schedule #(.focus ^js editor))))))
@ -59,7 +53,7 @@
[{:keys [id] :as shape}] [{:keys [id] :as shape}]
(ptk/reify ::finalize-editor-state (ptk/reify ::finalize-editor-state
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [content (-> (get-in state [:workspace-editor-state id]) (let [content (-> (get-in state [:workspace-editor-state id])
(ted/get-editor-current-content))] (ted/get-editor-current-content))]
@ -88,7 +82,7 @@
decorator)))) decorator))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
;; We need to finalize editor on two main events: (1) when user ;; We need to finalize editor on two main events: (1) when user
;; explicitly navigates to other section or page; (2) when user ;; explicitly navigates to other section or page; (2) when user
;; leaves the editor. ;; leaves the editor.
@ -149,7 +143,7 @@
[{:keys [id attrs]}] [{:keys [id attrs]}]
(ptk/reify ::update-root-attrs (ptk/reify ::update-root-attrs
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
shape (get objects id) shape (get objects id)
@ -168,7 +162,7 @@
(d/update-in-when state [:workspace-editor-state id] ted/update-editor-current-block-data attrs)) (d/update-in-when state [:workspace-editor-state id] ted/update-editor-current-block-data attrs))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(when-not (some? (get-in state [:workspace-editor-state id])) (when-not (some? (get-in state [:workspace-editor-state id]))
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
shape (get objects id) shape (get objects id)
@ -195,7 +189,7 @@
(d/update-in-when state [:workspace-editor-state id] ted/update-editor-current-inline-styles attrs)) (d/update-in-when state [:workspace-editor-state id] ted/update-editor-current-inline-styles attrs))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(when-not (some? (get-in state [:workspace-editor-state id])) (when-not (some? (get-in state [:workspace-editor-state id]))
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
shape (get objects id) shape (get objects id)
@ -232,7 +226,7 @@
(defn resize-text-batch [changes] (defn resize-text-batch [changes]
(ptk/reify ::resize-text-batch (ptk/reify ::resize-text-batch
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (get-in state [:workspace-data :pages-index page-id :objects])] objects (get-in state [:workspace-data :pages-index page-id :objects])]
(if-not (every? #(contains? objects(first %)) changes) (if-not (every? #(contains? objects(first %)) changes)

View File

@ -11,7 +11,6 @@
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.spec :as us] [app.common.spec :as us]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
@ -19,13 +18,10 @@
[app.main.data.workspace.selection :as dws] [app.main.data.workspace.selection :as dws]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
[app.main.data.workspace.undo :as dwu] [app.main.data.workspace.undo :as dwu]
[app.main.refs :as refs]
[app.main.snap :as snap] [app.main.snap :as snap]
[app.main.store :as st]
[app.main.streams :as ms] [app.main.streams :as ms]
[app.util.path.shapes-to-path :as ups] [app.util.path.shapes-to-path :as ups]
[beicon.core :as rx] [beicon.core :as rx]
[beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[potok.core :as ptk])) [potok.core :as ptk]))

View File

@ -6,21 +6,10 @@
(ns app.main.data.workspace.undo (ns app.main.data.workspace.undo
(:require (:require
[app.common.data :as d]
[app.common.geom.proportions :as gpr]
[app.common.geom.shapes :as gsh]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.pages.spec :as spec] [app.common.pages.spec :as spec]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid]
[app.main.worker :as uw]
[app.main.streams :as ms]
[app.util.logging :as log]
[app.util.timers :as ts]
[beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[clojure.set :as set]
[cuerdas.core :as str]
[potok.core :as ptk])) [potok.core :as ptk]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -42,7 +31,7 @@
(subvec undo (- cnt MAX-UNDO-SIZE)) (subvec undo (- cnt MAX-UNDO-SIZE))
undo))) undo)))
(defn- materialize-undo (defn materialize-undo
[changes index] [changes index]
(ptk/reify ::materialize-undo (ptk/reify ::materialize-undo
ptk/UpdateEvent ptk/UpdateEvent
@ -51,15 +40,6 @@
(update :workspace-data cp/process-changes changes) (update :workspace-data cp/process-changes changes)
(assoc-in [:workspace-undo :index] index))))) (assoc-in [:workspace-undo :index] index)))))
(defn- reset-undo
[index]
(ptk/reify ::reset-undo
ptk/UpdateEvent
(update [_ state]
(-> state
(update :workspace-undo dissoc :undo-index)
(update-in [:workspace-undo :items] (fn [queue] (into [] (take (inc index) queue))))))))
(defn- add-undo-entry (defn- add-undo-entry
[state entry] [state entry]
(if (and entry (if (and entry
@ -81,7 +61,7 @@
(update-in [:workspace-undo :transaction :undo-changes] #(into undo-changes %)) (update-in [:workspace-undo :transaction :undo-changes] #(into undo-changes %))
(update-in [:workspace-undo :transaction :redo-changes] #(into % redo-changes)))) (update-in [:workspace-undo :transaction :redo-changes] #(into % redo-changes))))
(defn- append-undo (defn append-undo
[entry] [entry]
(us/assert ::undo-entry entry) (us/assert ::undo-entry entry)
(ptk/reify ::append-undo (ptk/reify ::append-undo

View File

@ -17,7 +17,6 @@
[app.main.ui.shapes.circle :as circle] [app.main.ui.shapes.circle :as circle]
[app.main.ui.shapes.embed :as embed] [app.main.ui.shapes.embed :as embed]
[app.main.ui.shapes.export :as use] [app.main.ui.shapes.export :as use]
[app.main.ui.shapes.filters :as filters]
[app.main.ui.shapes.frame :as frame] [app.main.ui.shapes.frame :as frame]
[app.main.ui.shapes.group :as group] [app.main.ui.shapes.group :as group]
[app.main.ui.shapes.image :as image] [app.main.ui.shapes.image :as image]

View File

@ -7,9 +7,9 @@
(ns app.main.fonts (ns app.main.fonts
"A fonts loading macros." "A fonts loading macros."
(:require (:require
[cuerdas.core :as str] [clojure.data.json :as json]
[clojure.java.io :as io] [clojure.java.io :as io]
[clojure.data.json :as json])) [cuerdas.core :as str]))
(defn- parse-gfont-variant (defn- parse-gfont-variant
[variant] [variant]

View File

@ -15,7 +15,6 @@
[app.util.http :as http] [app.util.http :as http]
[app.util.logging :as log] [app.util.logging :as log]
[app.util.object :as obj] [app.util.object :as obj]
[app.util.timers :as ts]
[beicon.core :as rx] [beicon.core :as rx]
[clojure.set :as set] [clojure.set :as set]
[cuerdas.core :as str] [cuerdas.core :as str]
@ -104,7 +103,7 @@
[url on-loaded] [url on-loaded]
(let [node (create-link-element url) (let [node (create-link-element url)
head (.-head ^js js/document)] head (.-head ^js js/document)]
(gev/listenOnce node "load" (fn [event] (gev/listenOnce node "load" (fn [_]
(when (fn? on-loaded) (when (fn? on-loaded)
(on-loaded)))) (on-loaded))))
(dom/append-child! head node))) (dom/append-child! head node)))
@ -140,7 +139,7 @@
(str base ":" variants "&display=block"))) (str base ":" variants "&display=block")))
(defmethod load-font :google (defmethod load-font :google
[{:keys [id family variants ::on-loaded] :as font}] [{:keys [id ::on-loaded] :as font}]
(when (exists? js/window) (when (exists? js/window)
(log/debug :action "load-font" :font-id id :backend "google") (log/debug :action "load-font" :font-id id :backend "google")
(let [url (generate-gfonts-url font)] (let [url (generate-gfonts-url font)]
@ -183,11 +182,13 @@
(str/join "\n"))) (str/join "\n")))
(defmethod load-font :custom (defmethod load-font :custom
[{:keys [id family variants ::on-loaded] :as font}] [{:keys [id ::on-loaded] :as font}]
(when (exists? js/window) (when (exists? js/window)
(js/console.log "[debug:fonts]: loading custom font" id) (js/console.log "[debug:fonts]: loading custom font" id)
(let [css (generate-custom-font-css font)] (let [css (generate-custom-font-css font)]
(add-font-css! css)))) (add-font-css! css)
(when (fn? on-loaded)
(on-loaded)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; LOAD API ;; LOAD API

View File

@ -10,11 +10,8 @@
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.uuid :as uuid]
[app.main.constants :as c]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
[app.main.store :as st] [app.main.store :as st]
[beicon.core :as rx]
[okulary.core :as l])) [okulary.core :as l]))
;; ---- Global refs ;; ---- Global refs

View File

@ -9,7 +9,6 @@
["react-dom/server" :as rds] ["react-dom/server" :as rds]
[app.config :as cfg] [app.config :as cfg]
[app.main.exports :as exports] [app.main.exports :as exports]
[app.main.exports :as svg]
[app.main.fonts :as fonts] [app.main.fonts :as fonts]
[app.util.http :as http] [app.util.http :as http]
[beicon.core :as rx] [beicon.core :as rx]
@ -31,16 +30,13 @@
[])) []))
(defn populate-images-cache (defn populate-images-cache
([data] [data]
(populate-images-cache data nil)) (let [images (->> (:objects data)
(vals)
([data {:keys [resolve-media?] :or {resolve-media? false}}] (mapcat get-image-data))]
(let [images (->> (:objects data) (->> (rx/from images)
(vals) (rx/map #(cfg/resolve-file-media %))
(mapcat get-image-data))] (rx/flat-map http/fetch-data-uri))))
(->> (rx/from images)
(rx/map #(cfg/resolve-file-media %))
(rx/flat-map http/fetch-data-uri)))))
(defn populate-fonts-cache [data] (defn populate-fonts-cache [data]
(let [texts (->> (:objects data) (let [texts (->> (:objects data)

View File

@ -10,9 +10,7 @@
[app.common.uri :as u] [app.common.uri :as u]
[app.config :as cfg] [app.config :as cfg]
[app.util.http :as http] [app.util.http :as http]
[app.util.time :as dt] [beicon.core :as rx]))
[beicon.core :as rx]
[cuerdas.core :as str]))
(defn handle-response (defn handle-response
[{:keys [status body] :as response}] [{:keys [status body] :as response}]
@ -86,7 +84,7 @@
([id params] (mutation id params))) ([id params] (mutation id params)))
(defmethod mutation :login-with-oauth (defmethod mutation :login-with-oauth
[id {:keys [provider] :as params}] [_ {:keys [provider] :as params}]
(let [uri (u/join base-uri "api/auth/oauth/" (d/name provider)) (let [uri (u/join base-uri "api/auth/oauth/" (d/name provider))
params (dissoc params :provider)] params (dissoc params :provider)]
(->> (http/send! {:method :post :uri uri :query params}) (->> (http/send! {:method :post :uri uri :query params})
@ -94,7 +92,7 @@
(rx/mapcat handle-response)))) (rx/mapcat handle-response))))
(defmethod mutation :send-feedback (defmethod mutation :send-feedback
[id params] [_ params]
(->> (http/send! {:method :post (->> (http/send! {:method :post
:uri (u/join base-uri "api/feedback") :uri (u/join base-uri "api/feedback")
:body (http/transit-data params)}) :body (http/transit-data params)})
@ -102,7 +100,7 @@
(rx/mapcat handle-response))) (rx/mapcat handle-response)))
(defmethod query :export (defmethod query :export
[id params] [_ params]
(->> (http/send! {:method :post (->> (http/send! {:method :post
:uri (u/join base-uri "export") :uri (u/join base-uri "export")
:body (http/transit-data params) :body (http/transit-data params)

View File

@ -19,24 +19,24 @@
[beicon.core :as rx] [beicon.core :as rx]
[clojure.set :as set])) [clojure.set :as set]))
(defonce ^:private snap-accuracy 5) (def ^:const snap-accuracy 5)
(defonce ^:private snap-path-accuracy 10) (def ^:const snap-path-accuracy 10)
(defonce ^:private snap-distance-accuracy 10) (def ^:const snap-distance-accuracy 10)
(defn- remove-from-snap-points (defn- remove-from-snap-points
[remove-id?] [remove-id?]
(fn [query-result] (fn [query-result]
(->> query-result (->> query-result
(map (fn [[value data]] [value (remove (comp remove-id? second) data)])) (map (fn [[value data]] [value (remove (comp remove-id? second) data)]))
(filter (fn [[_ data]] (not (empty? data))))))) (filter (fn [[_ data]] (seq data))))))
(defn- flatten-to-points (defn- flatten-to-points
[query-result] [query-result]
(mapcat (fn [[v data]] (map (fn [[point _]] point) data)) query-result)) (mapcat (fn [[_ data]] (map (fn [[point _]] point) data)) query-result))
(defn- calculate-distance [query-result point coord] (defn- calculate-distance [query-result point coord]
(->> query-result (->> query-result
(map (fn [[value data]] [(mth/abs (- value (coord point))) [(coord point) value]])))) (map (fn [[value _]] [(mth/abs (- value (coord point))) [(coord point) value]]))))
(defn- get-min-distance-snap [points coord] (defn- get-min-distance-snap [points coord]
(fn [query-result] (fn [query-result]
@ -45,7 +45,7 @@
(apply min-key first) (apply min-key first)
second))) second)))
(defn- snap-frame-id [shapes] (defn snap-frame-id [shapes]
(let [frames (into #{} (map :frame-id shapes))] (let [frames (into #{} (map :frame-id shapes))]
(cond (cond
;; Only shapes from one frame. The common is the only one ;; Only shapes from one frame. The common is the only one
@ -286,8 +286,9 @@
(fn [matches other] (fn [matches other]
(let [matches (into {} matches) (let [matches (into {} matches)
other (into {} other) other (into {} other)
keys (set/union (keys matches) (keys other))] keys (set/union (set (keys matches))
(set (keys other)))]
(into {} (into {}
(map (fn [key] (map (fn [key]
[key [key
@ -308,7 +309,7 @@
min-match-coord min-match-coord
(fn [matches] (fn [matches]
(if (and (seq matches) (not (empty? matches))) (if (seq matches)
(->> matches (reduce get-min)) (->> matches (reduce get-min))
default))] default))]

View File

@ -75,12 +75,12 @@
(logjs "state" (get-in @state [:workspace-data :pages-index page-id :objects])))) (logjs "state" (get-in @state [:workspace-data :pages-index page-id :objects]))))
(defn ^:export dump-object [name] (defn ^:export dump-object [name]
(let [page-id (get @state :current-page-id)] (let [page-id (get @state :current-page-id)
(let [objects (get-in @state [:workspace-data :pages-index page-id :objects]) objects (get-in @state [:workspace-data :pages-index page-id :objects])
target (or (d/seek (fn [[id shape]] (= name (:name shape))) objects) target (or (d/seek (fn [[_ shape]] (= name (:name shape))) objects)
(get objects (uuid name)))] (get objects (uuid name)))]
(->> target (->> target
(logjs "state"))))) (logjs "state"))))
(defn ^:export dump-tree (defn ^:export dump-tree
([] (dump-tree false false)) ([] (dump-tree false false))
@ -89,7 +89,7 @@
(let [page-id (get @state :current-page-id) (let [page-id (get @state :current-page-id)
objects (get-in @state [:workspace-data :pages-index page-id :objects]) objects (get-in @state [:workspace-data :pages-index page-id :objects])
components (get-in @state [:workspace-data :components]) components (get-in @state [:workspace-data :components])
libraries (get-in @state [:workspace-libraries]) libraries (get @state :workspace-libraries)
root (d/seek #(nil? (:parent-id %)) (vals objects))] root (d/seek #(nil? (:parent-id %)) (vals objects))]
(letfn [(show-shape [shape-id level objects] (letfn [(show-shape [shape-id level objects]

View File

@ -7,12 +7,10 @@
(ns app.main.streams (ns app.main.streams
"User interaction events and streams." "User interaction events and streams."
(:require (:require
[beicon.core :as rx]
[app.main.store :as st] [app.main.store :as st]
[app.main.refs :as refs]
[app.common.geom.point :as gpt]
[app.util.globals :as globals] [app.util.globals :as globals]
[app.util.keyboard :as kbd])) [app.util.keyboard :as kbd]
[beicon.core :as rx]))
;; --- User Events ;; --- User Events

View File

@ -6,15 +6,12 @@
(ns app.main.ui (ns app.main.ui
(:require (:require
[app.config :as cf]
[app.common.data :as d]
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid] [app.config :as cf]
[app.config :as cfg]
[app.main.data.users :as du]
[app.main.data.messages :as dm]
[app.main.data.events :as ev] [app.main.data.events :as ev]
[app.main.data.messages :as dm]
[app.main.data.users :as du]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.auth :refer [auth]] [app.main.ui.auth :refer [auth]]
@ -32,8 +29,6 @@
[app.main.ui.static :as static] [app.main.ui.static :as static]
[app.main.ui.viewer :refer [viewer-page]] [app.main.ui.viewer :refer [viewer-page]]
[app.main.ui.workspace :as workspace] [app.main.ui.workspace :as workspace]
[app.util.i18n :as i18n :refer [tr t]]
[app.util.router :as rt]
[app.util.timers :as ts] [app.util.timers :as ts]
[cljs.pprint :refer [pprint]] [cljs.pprint :refer [pprint]]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
@ -60,11 +55,11 @@
(def routes (def routes
[["/auth" [["/auth"
["/login" :auth-login] ["/login" :auth-login]
(when cfg/registration-enabled (when cf/registration-enabled
["/register" :auth-register]) ["/register" :auth-register])
(when cfg/registration-enabled (when cf/registration-enabled
["/register/validate" :auth-register-validate]) ["/register/validate" :auth-register-validate])
(when cfg/registration-enabled (when cf/registration-enabled
["/register/success" :auth-register-success]) ["/register/success" :auth-register-success])
["/recovery/request" :auth-recovery-request] ["/recovery/request" :auth-recovery-request]
["/recovery" :auth-recovery] ["/recovery" :auth-recovery]
@ -102,9 +97,8 @@
(mf/defc on-main-error (mf/defc on-main-error
[{:keys [error] :as props}] [{:keys [error] :as props}]
(let [data (ex-data error)] (mf/use-effect #(ptk/handle-error error))
(mf/use-effect #(ptk/handle-error error)) [:span "Internal application errror"])
[:span "Internal application errror"]))
(mf/defc main-page (mf/defc main-page
{::mf/wrap [#(mf/catch % {:fallback on-main-error})]} {::mf/wrap [#(mf/catch % {:fallback on-main-error})]}
@ -211,14 +205,14 @@
(derive :service-unavailable ::exceptional-state) (derive :service-unavailable ::exceptional-state)
(defmethod ptk/handle-error ::exceptional-state (defmethod ptk/handle-error ::exceptional-state
[{:keys [status] :as error}] [error]
(ts/schedule (ts/schedule
(st/emitf (dm/assign-exception error)))) (st/emitf (dm/assign-exception error))))
;; We receive a explicit authentication error; this explicitly clears ;; We receive a explicit authentication error; this explicitly clears
;; all profile data and redirect the user to the login page. ;; all profile data and redirect the user to the login page.
(defmethod ptk/handle-error :authentication (defmethod ptk/handle-error :authentication
[error] [_]
(ts/schedule (st/emitf (du/logout)))) (ts/schedule (st/emitf (du/logout))))
;; Error that happens on an active bussines model validation does not ;; Error that happens on an active bussines model validation does not
@ -245,7 +239,7 @@
;; Error on parsing an SVG ;; Error on parsing an SVG
(defmethod ptk/handle-error :svg-parser (defmethod ptk/handle-error :svg-parser
[error] [_]
(ts/schedule (ts/schedule
(st/emitf (st/emitf
(dm/show {:content "SVG is invalid or malformed" (dm/show {:content "SVG is invalid or malformed"
@ -261,7 +255,7 @@
context (str/fmt "ns: '%s'\nname: '%s'\nfile: '%s:%s'" context (str/fmt "ns: '%s'\nname: '%s'\nfile: '%s:%s'"
(:ns context) (:ns context)
(:name context) (:name context)
(str cfg/public-uri "js/cljs-runtime/" (:file context)) (str cf/public-uri "js/cljs-runtime/" (:file context))
(:line context))] (:line context))]
(ts/schedule (ts/schedule
(st/emitf (st/emitf

View File

@ -6,38 +6,27 @@
(ns app.main.ui.auth (ns app.main.ui.auth
(:require (:require
[app.common.uuid :as uuid]
[app.main.data.messages :as dm]
[app.main.data.users :as du]
[app.main.repo :as rp]
[app.main.store :as st]
[app.main.ui.auth.login :refer [login-page]] [app.main.ui.auth.login :refer [login-page]]
[app.main.ui.auth.recovery :refer [recovery-page]] [app.main.ui.auth.recovery :refer [recovery-page]]
[app.main.ui.auth.recovery-request :refer [recovery-request-page]] [app.main.ui.auth.recovery-request :refer [recovery-request-page]]
[app.main.ui.auth.register :refer [register-page register-success-page register-validate-page]] [app.main.ui.auth.register :refer [register-page register-success-page register-validate-page]]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.forms :as fm] [app.util.i18n :as i18n :refer [tr]]
[app.util.i18n :as i18n :refer [t]]
[app.util.router :as rt]
[app.util.timers :as ts]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(mf/defc auth (mf/defc auth
[{:keys [route] :as props}] [{:keys [route] :as props}]
(let [section (get-in route [:data :name]) (let [section (get-in route [:data :name])
locale (mf/deref i18n/locale)
params (:query-params route)] params (:query-params route)]
(mf/use-effect (mf/use-effect
#(dom/set-html-title (t locale "title.default"))) #(dom/set-html-title (tr "title.default")))
[:div.auth [:div.auth
[:section.auth-sidebar [:section.auth-sidebar
[:a.logo {:href "#/"} i/logo] [:a.logo {:href "https://penpot.app"} i/logo]
[:span.tagline (t locale "auth.sidebar-tagline")]] [:span.tagline (tr "auth.sidebar-tagline")]]
[:section.auth-content [:section.auth-content
(case section (case section
@ -54,10 +43,10 @@
[:& login-page {:params params}] [:& login-page {:params params}]
:auth-recovery-request :auth-recovery-request
[:& recovery-request-page {:locale locale}] [:& recovery-request-page]
:auth-recovery :auth-recovery
[:& recovery-page {:locale locale :params params}]) [:& recovery-page {:params params}])
[:div.terms-login [:div.terms-login
[:a {:href "https://penpot.app/terms.html" :target "_blank"} "Terms of service"] [:a {:href "https://penpot.app/terms.html" :target "_blank"} "Terms of service"]

View File

@ -16,8 +16,7 @@
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.main.ui.messages :as msgs] [app.main.ui.messages :as msgs]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :refer [tr t]] [app.util.i18n :refer [tr]]
[app.util.object :as obj]
[app.util.router :as rt] [app.util.router :as rt]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
@ -74,7 +73,7 @@
on-submit on-submit
(mf/use-callback (mf/use-callback
(mf/deps form) (mf/deps form)
(fn [event] (fn [_]
(reset! error nil) (reset! error nil)
(let [params (with-meta (:clean-data @form) (let [params (with-meta (:clean-data @form)
{:on-error on-error})] {:on-error on-error})]

View File

@ -11,12 +11,9 @@
[app.main.data.users :as du] [app.main.data.users :as du]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.components.forms :as fm] [app.main.ui.components.forms :as fm]
[app.main.ui.icons :as i] [app.util.i18n :as i18n :refer [tr]]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [t tr]]
[app.util.router :as rt] [app.util.router :as rt]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[cuerdas.core :as str]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(s/def ::password-1 ::us/not-empty-string) (s/def ::password-1 ::us/not-empty-string)
@ -40,7 +37,7 @@
(assoc :password-1 {:message "errors.password-too-short"})))) (assoc :password-1 {:message "errors.password-too-short"}))))
(defn- on-error (defn- on-error
[form error] [_form _error]
(st/emit! (dm/error (tr "auth.notifications.invalid-token-error")))) (st/emit! (dm/error (tr "auth.notifications.invalid-token-error"))))
(defn- on-success (defn- on-success
@ -49,7 +46,7 @@
(rt/nav :auth-login))) (rt/nav :auth-login)))
(defn- on-submit (defn- on-submit
[form event] [form _event]
(let [mdata {:on-error on-error (let [mdata {:on-error on-error
:on-success on-success} :on-success on-success}
params {:token (get-in @form [:clean-data :token]) params {:token (get-in @form [:clean-data :token])
@ -57,7 +54,7 @@
(st/emit! (du/recover-profile (with-meta params mdata))))) (st/emit! (du/recover-profile (with-meta params mdata)))))
(mf/defc recovery-form (mf/defc recovery-form
[{:keys [locale params] :as props}] [{:keys [params] :as props}]
(let [form (fm/use-form :spec ::recovery-form (let [form (fm/use-form :spec ::recovery-form
:validators [password-equality] :validators [password-equality]
:initial params)] :initial params)]
@ -66,28 +63,28 @@
[:div.fields-row [:div.fields-row
[:& fm/input {:type "password" [:& fm/input {:type "password"
:name :password-1 :name :password-1
:label (t locale "auth.new-password")}]] :label (tr "auth.new-password")}]]
[:div.fields-row [:div.fields-row
[:& fm/input {:type "password" [:& fm/input {:type "password"
:name :password-2 :name :password-2
:label (t locale "auth.confirm-password")}]] :label (tr "auth.confirm-password")}]]
[:& fm/submit-button [:& fm/submit-button
{:label (t locale "auth.recovery-submit")}]])) {:label (tr "auth.recovery-submit")}]]))
;; --- Recovery Request Page ;; --- Recovery Request Page
(mf/defc recovery-page (mf/defc recovery-page
[{:keys [locale params] :as props}] [{:keys [params] :as props}]
[:section.generic-form [:section.generic-form
[:div.form-container [:div.form-container
[:h1 "Forgot your password?"] [:h1 "Forgot your password?"]
[:div.subtitle "Please enter your new password"] [:div.subtitle "Please enter your new password"]
[:& recovery-form {:locale locale :params params}] [:& recovery-form {:params params}]
[:div.links [:div.links
[:div.link-entry [:div.link-entry
[:a {:on-click #(st/emit! (rt/nav :auth-login))} [:a {:on-click #(st/emit! (rt/nav :auth-login))}
(t locale "profile.recovery.go-to-login")]]]]]) (tr "profile.recovery.go-to-login")]]]]])

View File

@ -12,12 +12,10 @@
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.components.forms :as fm] [app.main.ui.components.forms :as fm]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.util.dom :as dom] [app.util.i18n :as i18n :refer [tr]]
[app.util.i18n :as i18n :refer [tr t]]
[app.util.router :as rt] [app.util.router :as rt]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[cuerdas.core :as str]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(s/def ::email ::us/email) (s/def ::email ::us/email)
@ -30,7 +28,7 @@
on-success on-success
(mf/use-callback (mf/use-callback
(fn [data] (fn [_ _]
(reset! submitted false) (reset! submitted false)
(st/emit! (dm/info (tr "auth.notifications.recovery-token-sent")) (st/emit! (dm/info (tr "auth.notifications.recovery-token-sent"))
(rt/nav :auth-login)))) (rt/nav :auth-login))))

View File

@ -8,21 +8,18 @@
(:require (:require
[app.common.spec :as us] [app.common.spec :as us]
[app.config :as cf] [app.config :as cf]
[app.main.data.users :as du]
[app.main.data.messages :as dm] [app.main.data.messages :as dm]
[app.main.store :as st] [app.main.data.users :as du]
[app.main.repo :as rp] [app.main.repo :as rp]
[app.main.store :as st]
[app.main.ui.auth.login :as login]
[app.main.ui.components.forms :as fm] [app.main.ui.components.forms :as fm]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.main.ui.messages :as msgs] [app.main.ui.messages :as msgs]
[app.main.ui.auth.login :as login] [app.util.i18n :refer [tr]]
[app.util.dom :as dom]
[app.util.i18n :refer [tr t]]
[app.util.router :as rt] [app.util.router :as rt]
[app.util.timers :as tm]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[cuerdas.core :as str]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(mf/defc demo-warning (mf/defc demo-warning
@ -71,7 +68,7 @@
(st/emit! (dm/error (tr "errors.generic"))))) (st/emit! (dm/error (tr "errors.generic")))))
(defn- handle-prepare-register-success (defn- handle-prepare-register-success
[form {:keys [token] :as result}] [_form {:keys [token] :as result}]
(st/emit! (rt/nav :auth-register-validate {} {:token token}))) (st/emit! (rt/nav :auth-register-validate {} {:token token})))
(mf/defc register-form (mf/defc register-form
@ -84,7 +81,7 @@
on-submit on-submit
(mf/use-callback (mf/use-callback
(fn [form event] (fn [form _event]
(reset! submitted? true) (reset! submitted? true)
(let [params (:clean-data @form)] (let [params (:clean-data @form)]
(->> (rp/mutation :prepare-register-profile params) (->> (rp/mutation :prepare-register-profile params)
@ -166,7 +163,7 @@
(st/emit! (dm/error (tr "errors.generic")))))) (st/emit! (dm/error (tr "errors.generic"))))))
(defn- handle-register-success (defn- handle-register-success
[form data] [_form data]
(cond (cond
(some? (:invitation-token data)) (some? (:invitation-token data))
(let [token (:invitation-token data)] (let [token (:invitation-token data)]
@ -200,7 +197,7 @@
on-submit on-submit
(mf/use-callback (mf/use-callback
(fn [form event] (fn [form _event]
(reset! submitted? true) (reset! submitted? true)
(let [params (:clean-data @form)] (let [params (:clean-data @form)]
(->> (rp/mutation :register-profile params) (->> (rp/mutation :register-profile params)

View File

@ -6,23 +6,16 @@
(ns app.main.ui.auth.verify-token (ns app.main.ui.auth.verify-token
(:require (:require
[app.common.uuid :as uuid]
[app.main.data.messages :as dm] [app.main.data.messages :as dm]
[app.main.data.users :as du] [app.main.data.users :as du]
[app.main.repo :as rp] [app.main.repo :as rp]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.auth.login :refer [login-page]]
[app.main.ui.auth.recovery :refer [recovery-page]]
[app.main.ui.auth.recovery-request :refer [recovery-request-page]]
[app.main.ui.auth.register :refer [register-page]]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.forms :as fm]
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.router :as rt] [app.util.router :as rt]
[app.util.timers :as ts] [app.util.timers :as ts]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(defmulti handle-token (fn [token] (:iss token))) (defmulti handle-token (fn [token] (:iss token)))
@ -34,7 +27,7 @@
(st/emit! (du/login-from-token data)))) (st/emit! (du/login-from-token data))))
(defmethod handle-token :change-email (defmethod handle-token :change-email
[data] [_data]
(let [msg (tr "dashboard.notifications.email-changed-successfully")] (let [msg (tr "dashboard.notifications.email-changed-successfully")]
(ts/schedule 100 #(st/emit! (dm/success msg))) (ts/schedule 100 #(st/emit! (dm/success msg)))
(st/emit! (rt/nav :settings-profile) (st/emit! (rt/nav :settings-profile)
@ -57,7 +50,7 @@
(st/emit! (rt/nav :auth-register {} {:invitation-token token}))))) (st/emit! (rt/nav :auth-register {} {:invitation-token token})))))
(defmethod handle-token :default (defmethod handle-token :default
[tdata] [_tdata]
(st/emit! (st/emit!
(rt/nav :auth-login) (rt/nav :auth-login)
(dm/warn (tr "errors.unexpected-token")))) (dm/warn (tr "errors.unexpected-token"))))

View File

@ -11,16 +11,13 @@
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.store :as st] [app.main.store :as st]
[app.main.streams :as ms]
[app.main.ui.components.dropdown :refer [dropdown]] [app.main.ui.components.dropdown :refer [dropdown]]
[app.main.ui.context :as ctx]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :as i18n :refer [t tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.keyboard :as kbd] [app.util.keyboard :as kbd]
[app.util.object :as obj] [app.util.object :as obj]
[app.util.time :as dt] [app.util.time :as dt]
[cuerdas.core :as str]
[okulary.core :as l] [okulary.core :as l]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
@ -105,7 +102,7 @@
:on-focus on-focus :on-focus on-focus
:on-change on-change}] :on-change on-change}]
(when (or @show-buttons? (when (or @show-buttons?
(not (empty? @content))) (seq @content))
[:div.buttons [:div.buttons
[:input.btn-primary {:type "button" :value "Post" :on-click on-submit}] [:input.btn-primary {:type "button" :value "Post" :on-click on-submit}]
[:input.btn-secondary {:type "button" :value "Cancel" :on-click on-cancel}]])])) [:input.btn-secondary {:type "button" :value "Cancel" :on-click on-cancel}]])]))
@ -323,7 +320,7 @@
(mf/defc thread-bubble (mf/defc thread-bubble
{::mf/wrap [mf/memo]} {::mf/wrap [mf/memo]}
[{:keys [thread zoom open? on-click] :as params}] [{:keys [thread zoom on-click] :as params}]
(let [pos (:position thread) (let [pos (:position thread)
pos-x (* (:x pos) zoom) pos-x (* (:x pos) zoom)
pos-y (* (:y pos) zoom) pos-y (* (:y pos) zoom)

View File

@ -6,9 +6,9 @@
(ns app.main.ui.components.color-bullet (ns app.main.ui.components.color-bullet
(:require (:require
[rumext.alpha :as mf] [app.util.color :as uc]
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.color :as uc])) [rumext.alpha :as mf]))
(mf/defc color-bullet [{:keys [color on-click]}] (mf/defc color-bullet [{:keys [color on-click]}]
(if (uc/multiple? color) (if (uc/multiple? color)
@ -31,7 +31,7 @@
(mf/defc color-name [{:keys [color size on-click on-double-click]}] (mf/defc color-name [{:keys [color size on-click on-double-click]}]
(let [color (if (string? color) {:color color :opacity 1} color) (let [color (if (string? color) {:color color :opacity 1} color)
{:keys [name color opacity gradient]} color {:keys [name color gradient]} color
color-str (or name color (gradient-type->string (:type gradient)))] color-str (or name color (gradient-type->string (:type gradient)))]
(when (or (not size) (= size :big)) (when (or (not size) (= size :big))
[:span.color-text {:on-click #(when on-click (on-click %)) [:span.color-text {:on-click #(when on-click (on-click %))

View File

@ -6,16 +6,11 @@
(ns app.main.ui.components.color-input (ns app.main.ui.components.color-input
(:require (:require
[app.common.data :as d]
[app.common.math :as math]
[app.common.spec :as us]
[app.common.uuid :as uuid]
[app.util.color :as uc] [app.util.color :as uc]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]]
[app.util.keyboard :as kbd] [app.util.keyboard :as kbd]
[app.util.object :as obj] [app.util.object :as obj]
[app.util.simple-math :as sm]
[app.util.i18n :as i18n :refer [tr]]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(mf/defc color-input (mf/defc color-input
@ -80,7 +75,7 @@
handle-blur handle-blur
(mf/use-callback (mf/use-callback
(mf/deps parse-value apply-value update-input) (mf/deps parse-value apply-value update-input)
(fn [event] (fn [_]
(let [new-value (parse-value)] (let [new-value (parse-value)]
(if new-value (if new-value
(apply-value new-value) (apply-value new-value)

View File

@ -6,13 +6,12 @@
(ns app.main.ui.components.context-menu (ns app.main.ui.components.context-menu
(:require (:require
[rumext.alpha :as mf]
[goog.object :as gobj]
[app.main.ui.components.dropdown :refer [dropdown']] [app.main.ui.components.dropdown :refer [dropdown']]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.common.uuid :as uuid]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.object :as obj])) [app.util.object :as obj]
[goog.object :as gobj]
[rumext.alpha :as mf]))
(mf/defc context-menu (mf/defc context-menu
{::mf/wrap-props false} {::mf/wrap-props false}
@ -52,7 +51,7 @@
(- node-height) (- node-height)
0)] 0)]
(if (not= target-offset (:offset @local)) (when (not= target-offset (:offset @local))
(swap! local assoc :offset target-offset)))))) (swap! local assoc :offset target-offset))))))
enter-submenu enter-submenu

View File

@ -6,11 +6,11 @@
(ns app.main.ui.components.copy-button (ns app.main.ui.components.copy-button
(:require (:require
[beicon.core :as rx] [app.main.ui.icons :as i]
[rumext.alpha :as mf]
[app.util.webapi :as wapi]
[app.util.timers :as timers] [app.util.timers :as timers]
[app.main.ui.icons :as i])) [app.util.webapi :as wapi]
[beicon.core :as rx]
[rumext.alpha :as mf]))
(mf/defc copy-button [{:keys [data]}] (mf/defc copy-button [{:keys [data]}]
(let [just-copied (mf/use-state false)] (let [just-copied (mf/use-state false)]
@ -24,9 +24,8 @@
[:button.copy-button [:button.copy-button
{:on-click #(when-not @just-copied {:on-click #(when-not @just-copied
(do (reset! just-copied true)
(reset! just-copied true) (wapi/write-to-clipboard data))}
(wapi/write-to-clipboard data)))}
(if @just-copied (if @just-copied
i/tick i/tick
i/copy)])) i/copy)]))

View File

@ -1,11 +1,16 @@
;; 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) UXBOX Labs SL
(ns app.main.ui.components.dropdown (ns app.main.ui.components.dropdown
(:require (:require
[rumext.alpha :as mf]
[app.common.uuid :as uuid]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.keyboard :as kbd] [app.util.keyboard :as kbd]
[goog.events :as events] [goog.events :as events]
[goog.object :as gobj]) [goog.object :as gobj]
[rumext.alpha :as mf])
(:import goog.events.EventType)) (:import goog.events.EventType))
(mf/defc dropdown' (mf/defc dropdown'

View File

@ -7,7 +7,6 @@
(ns app.main.ui.components.editable-label (ns app.main.ui.components.editable-label
(:require (:require
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.util.data :refer [classnames]]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.keyboard :as kbd] [app.util.keyboard :as kbd]
[app.util.timers :as timers] [app.util.timers :as timers]
@ -32,7 +31,7 @@
cancel-editing (fn [] cancel-editing (fn []
(stop-editing) (stop-editing)
(when on-cancel (on-cancel))) (when on-cancel (on-cancel)))
on-dbl-click (fn [e] (when (not disable-dbl-click?) (start-editing))) on-dbl-click (fn [_] (when (not disable-dbl-click?) (start-editing)))
on-key-up (fn [e] on-key-up (fn [e]
(cond (cond
(kbd/esc? e) (kbd/esc? e)

View File

@ -6,13 +6,13 @@
(ns app.main.ui.components.editable-select (ns app.main.ui.components.editable-select
(:require (:require
[rumext.alpha :as mf]
[app.common.uuid :as uuid]
[app.common.data :as d] [app.common.data :as d]
[app.common.uuid :as uuid]
[app.main.ui.components.dropdown :refer [dropdown]]
[app.main.ui.icons :as i]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.timers :as timers] [app.util.timers :as timers]
[app.main.ui.icons :as i] [rumext.alpha :as mf]))
[app.main.ui.components.dropdown :refer [dropdown]]))
(mf/defc editable-select [{:keys [value type options class on-change placeholder]}] (mf/defc editable-select [{:keys [value type options class on-change placeholder]}]
(let [state (mf/use-state {:id (uuid/next) (let [state (mf/use-state {:id (uuid/next)
@ -24,7 +24,7 @@
open-dropdown #(swap! state assoc :is-open? true) open-dropdown #(swap! state assoc :is-open? true)
close-dropdown #(swap! state assoc :is-open? false) close-dropdown #(swap! state assoc :is-open? false)
select-item (fn [value] select-item (fn [value]
(fn [event] (fn [_]
(swap! state assoc :current-value value) (swap! state assoc :current-value value)
(when on-change (on-change value)))) (when on-change (on-change value))))

View File

@ -6,10 +6,9 @@
(ns app.main.ui.components.file-uploader (ns app.main.ui.components.file-uploader
(:require (:require
[rumext.alpha :as mf]
[app.main.data.workspace :as dw]
[app.main.store :as st] [app.main.store :as st]
[app.util.dom :as dom])) [app.util.dom :as dom]
[rumext.alpha :as mf]))
(mf/defc file-uploader (mf/defc file-uploader
{::mf/forward-ref true} {::mf/forward-ref true}

View File

@ -8,7 +8,6 @@
(:require (:require
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.webapi :as wapi] [app.util.webapi :as wapi]
[beicon.core :as rx]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(def fullscreen-context (def fullscreen-context
@ -21,7 +20,7 @@
change change
(mf/use-callback (mf/use-callback
(fn [event] (fn [_]
(let [val (dom/fullscreen?)] (let [val (dom/fullscreen?)]
(reset! state val)))) (reset! state val))))

View File

@ -132,7 +132,7 @@
handle-blur handle-blur
(mf/use-callback (mf/use-callback
(mf/deps parse-value apply-value update-input) (mf/deps parse-value apply-value update-input)
(fn [event] (fn [_]
(let [new-value (parse-value)] (let [new-value (parse-value)]
(if new-value (if new-value
(apply-value new-value) (apply-value new-value)

View File

@ -6,10 +6,10 @@
(ns app.main.ui.components.select (ns app.main.ui.components.select
(:require (:require
[rumext.alpha :as mf]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.ui.components.dropdown :refer [dropdown]]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.main.ui.components.dropdown :refer [dropdown]])) [rumext.alpha :as mf]))
(mf/defc select [{:keys [default-value options class on-change]}] (mf/defc select [{:keys [default-value options class on-change]}]
(let [state (mf/use-state {:id (uuid/next) (let [state (mf/use-state {:id (uuid/next)
@ -17,9 +17,10 @@
:current-value default-value}) :current-value default-value})
open-dropdown #(swap! state assoc :is-open? true) open-dropdown #(swap! state assoc :is-open? true)
close-dropdown #(swap! state assoc :is-open? false) close-dropdown #(swap! state assoc :is-open? false)
select-item (fn [value] (fn [event] select-item (fn [value]
(swap! state assoc :current-value value) (fn [_]
(when on-change (on-change value)))) (swap! state assoc :current-value value)
(when on-change (on-change value))))
as-key-value (fn [item] (if (map? item) [(:value item) (:label item)] [item item])) as-key-value (fn [item] (if (map? item) [(:value item) (:label item)] [item item]))
value->label (into {} (->> options value->label (into {} (->> options
(map as-key-value))) ] (map as-key-value))) ]

View File

@ -8,7 +8,7 @@
(:require [rumext.alpha :as mf])) (:require [rumext.alpha :as mf]))
(mf/defc tab-element (mf/defc tab-element
[{:keys [children id title]}] [{:keys [children]}]
[:div.tab-element [:div.tab-element
[:div.tab-element-content children]]) [:div.tab-element-content children]])

View File

@ -57,10 +57,10 @@
(let [on-keydown (let [on-keydown
(fn [event] (fn [event]
(when (k/enter? event) (when (k/enter? event)
(do (dom/prevent-default event) (dom/prevent-default event)
(dom/stop-propagation event) (dom/stop-propagation event)
(st/emit! (modal/hide)) (st/emit! (modal/hide))
(on-accept props)))) (on-accept props)))
key (events/listen js/document EventType.KEYDOWN on-keydown)] key (events/listen js/document EventType.KEYDOWN on-keydown)]
#(events/unlistenByKey key)))) #(events/unlistenByKey key))))

View File

@ -6,9 +6,9 @@
(ns app.main.ui.cursors (ns app.main.ui.cursors
(:require (:require
[app.common.uri :as u]
[clojure.java.io :as io] [clojure.java.io :as io]
[cuerdas.core :as str] [cuerdas.core :as str]))
[app.common.uri :as u]))
(def cursor-folder "images/cursors") (def cursor-folder "images/cursors")

View File

@ -6,9 +6,10 @@
(ns app.main.ui.cursors (ns app.main.ui.cursors
(:require-macros [app.main.ui.cursors :refer [cursor-ref cursor-fn]]) (:require-macros [app.main.ui.cursors :refer [cursor-ref cursor-fn]])
(:require [rumext.alpha :as mf] (:require
[cuerdas.core :as str] [app.util.timers :as ts]
[app.util.timers :as ts])) [cuerdas.core :as str]
[rumext.alpha :as mf]))
;; Static cursors ;; Static cursors
(def comments (cursor-ref :comments 0 2 20)) (def comments (cursor-ref :comments 0 2 20))
@ -40,7 +41,7 @@
(mf/defc debug-preview (mf/defc debug-preview
{::mf/wrap-props false} {::mf/wrap-props false}
[props] []
(let [rotation (mf/use-state 0)] (let [rotation (mf/use-state 0)]
(mf/use-effect (fn [] (ts/interval 100 #(reset! rotation inc)))) (mf/use-effect (fn [] (ts/interval 100 #(reset! rotation inc))))

View File

@ -6,9 +6,7 @@
(ns app.main.ui.dashboard (ns app.main.ui.dashboard
(:require (:require
[app.common.exceptions :as ex]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid]
[app.config :as cf] [app.config :as cf]
[app.main.data.dashboard :as dd] [app.main.data.dashboard :as dd]
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
@ -16,19 +14,13 @@
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.context :as ctx] [app.main.ui.context :as ctx]
[app.main.ui.dashboard.files :refer [files-section]] [app.main.ui.dashboard.files :refer [files-section]]
[app.main.ui.dashboard.fonts :refer [fonts-page font-providers-page]]
[app.main.ui.dashboard.libraries :refer [libraries-page]] [app.main.ui.dashboard.libraries :refer [libraries-page]]
[app.main.ui.dashboard.projects :refer [projects-section]] [app.main.ui.dashboard.projects :refer [projects-section]]
[app.main.ui.dashboard.fonts :refer [fonts-page font-providers-page]]
[app.main.ui.dashboard.search :refer [search-page]] [app.main.ui.dashboard.search :refer [search-page]]
[app.main.ui.dashboard.sidebar :refer [sidebar]] [app.main.ui.dashboard.sidebar :refer [sidebar]]
[app.main.ui.dashboard.team :refer [team-settings-page team-members-page]] [app.main.ui.dashboard.team :refer [team-settings-page team-members-page]]
[app.main.ui.icons :as i]
[app.util.i18n :as i18n :refer [t]]
[app.util.router :as rt]
[app.util.timers :as tm] [app.util.timers :as tm]
[beicon.core :as rx]
[cuerdas.core :as str]
[okulary.core :as l]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(defn ^boolean uuid-str? (defn ^boolean uuid-str?
@ -37,9 +29,8 @@
(boolean (re-seq us/uuid-rx s)))) (boolean (re-seq us/uuid-rx s))))
(defn- parse-params (defn- parse-params
[route profile] [route]
(let [route-name (get-in route [:data :name]) (let [search-term (get-in route [:params :query :search-term])
search-term (get-in route [:params :query :search-term])
team-id (get-in route [:params :path :team-id]) team-id (get-in route [:params :path :team-id])
project-id (get-in route [:params :path :project-id])] project-id (get-in route [:params :path :project-id])]
(cond-> (cond->
@ -87,7 +78,7 @@
[{:keys [route] :as props}] [{:keys [route] :as props}]
(let [profile (mf/deref refs/profile) (let [profile (mf/deref refs/profile)
section (get-in route [:data :name]) section (get-in route [:data :name])
params (parse-params route profile) params (parse-params route)
project-id (:project-id params) project-id (:project-id params)
team-id (:team-id params) team-id (:team-id params)

View File

@ -6,29 +6,15 @@
(ns app.main.ui.dashboard.comments (ns app.main.ui.dashboard.comments
(:require (:require
[okulary.core :as l]
[app.common.data :as d]
[app.common.spec :as us]
[app.config :as cfg]
[app.main.data.dashboard :as dd]
[app.main.data.workspace :as dw]
[app.main.data.workspace.comments :as dwcm]
[app.main.data.comments :as dcm] [app.main.data.comments :as dcm]
[app.main.data.workspace.comments :as dwcm]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.repo :as rp]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.components.dropdown :refer [dropdown]]
[app.main.ui.comments :as cmt] [app.main.ui.comments :as cmt]
[app.main.ui.components.dropdown :refer [dropdown]]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :as i18n :refer [t tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.object :as obj]
[app.util.router :as rt]
[app.util.time :as dt]
[app.util.timers :as tm]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[cuerdas.core :as str]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(mf/defc comments-section (mf/defc comments-section

View File

@ -7,7 +7,6 @@
(ns app.main.ui.dashboard.files (ns app.main.ui.dashboard.files
(:require (:require
[app.main.data.dashboard :as dd] [app.main.data.dashboard :as dd]
[app.main.data.modal :as modal]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.dashboard.grid :refer [grid]] [app.main.ui.dashboard.grid :refer [grid]]
@ -16,18 +15,12 @@
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.keyboard :as kbd]
[app.util.router :as rt]
[okulary.core :as l]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(mf/defc header (mf/defc header
[{:keys [team project] :as props}] [{:keys [project] :as props}]
(let [local (mf/use-state {:menu-open false (let [local (mf/use-state {:menu-open false
:edition false}) :edition false})
project-id (:id project)
team-id (:id team)
on-menu-click on-menu-click
(mf/use-callback (mf/use-callback
(fn [event] (fn [event]
@ -83,7 +76,7 @@
(if (:is-pinned project) (if (:is-pinned project)
i/pin-fill i/pin-fill
i/pin)] i/pin)]
[:div.icon.tooltip.tooltip-bottom [:div.icon.tooltip.tooltip-bottom
{:on-click on-menu-click :alt (tr "dashboard.options")} {:on-click on-menu-click :alt (tr "dashboard.options")}
i/actions]]])) i/actions]]]))

View File

@ -6,27 +6,22 @@
(ns app.main.ui.dashboard.fonts (ns app.main.ui.dashboard.fonts
(:require (:require
[app.common.data :as d]
[app.common.media :as cm] [app.common.media :as cm]
[app.common.uuid :as uuid]
[app.main.data.dashboard :as dd]
[app.main.data.fonts :as df] [app.main.data.fonts :as df]
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
[app.main.ui.components.file-uploader :refer [file-uploader]]
[app.main.ui.components.context-menu :refer [context-menu]]
[app.main.store :as st]
[app.main.repo :as rp]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.repo :as rp]
[app.main.store :as st]
[app.main.ui.components.context-menu :refer [context-menu]]
[app.main.ui.components.file-uploader :refer [file-uploader]]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.logging :as log]
[app.util.keyboard :as kbd] [app.util.keyboard :as kbd]
[app.util.router :as rt] [app.util.logging :as log]
[app.util.webapi :as wa] ;; [app.util.router :as rt]
[cuerdas.core :as str]
[beicon.core :as rx] [beicon.core :as rx]
[okulary.core :as l] [cuerdas.core :as str]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(log/set-level! :trace) (log/set-level! :trace)
@ -47,29 +42,29 @@
(mf/defc header (mf/defc header
{::mf/wrap [mf/memo]} {::mf/wrap [mf/memo]}
[{:keys [section team] :as props}] [{:keys [section team] :as props}]
(let [go-fonts ;; (let [go-fonts
(mf/use-callback ;; (mf/use-callback
(mf/deps team) ;; (mf/deps team)
(st/emitf (rt/nav :dashboard-fonts {:team-id (:id team)}))) ;; (st/emitf (rt/nav :dashboard-fonts {:team-id (:id team)})))
go-providers ;; go-providers
(mf/use-callback ;; (mf/use-callback
(mf/deps team) ;; (mf/deps team)
(st/emitf (rt/nav :dashboard-font-providers {:team-id (:id team)})))] ;; (st/emitf (rt/nav :dashboard-font-providers {:team-id (:id team)})))]
(use-set-page-title team section) (use-set-page-title team section)
[:header.dashboard-header [:header.dashboard-header
[:div.dashboard-title [:div.dashboard-title
[:h1 (tr "labels.fonts")]] [:h1 (tr "labels.fonts")]]
[:nav [:nav
#_[:ul #_[:ul
[:li {:class (when (= section :fonts) "active")} [:li {:class (when (= section :fonts) "active")}
[:a {:on-click go-fonts} (tr "labels.custom-fonts")]] [:a {:on-click go-fonts} (tr "labels.custom-fonts")]]
[:li {:class (when (= section :providers) "active")} [:li {:class (when (= section :providers) "active")}
[:a {:on-click go-providers} (tr "labels.font-providers")]]]] [:a {:on-click go-providers} (tr "labels.font-providers")]]]]
[:div]])) [:div]])
(mf/defc font-variant-display-name (mf/defc font-variant-display-name
[{:keys [variant]}] [{:keys [variant]}]
@ -88,9 +83,6 @@
on-click on-click
(mf/use-callback #(dom/click (mf/ref-val input-ref))) (mf/use-callback #(dom/click (mf/ref-val input-ref)))
font-key-fn
(mf/use-callback (juxt :font-family :font-weight :font-style))
on-selected on-selected
(mf/use-callback (mf/use-callback
(mf/deps team installed-fonts) (mf/deps team installed-fonts)
@ -190,7 +182,7 @@
(reset! state (dom/get-target-val event))) (reset! state (dom/get-target-val event)))
on-save on-save
(fn [event] (fn [_]
(let [font-family @state] (let [font-family @state]
(when-not (str/blank? font-family) (when-not (str/blank? font-family)
(st/emit! (df/update-font (st/emit! (df/update-font
@ -204,7 +196,7 @@
(on-save event))) (on-save event)))
on-cancel on-cancel
(fn [event] (fn [_]
(reset! edit? false) (reset! edit? false)
(reset! state (:font-family font))) (reset! state (:font-family font)))
@ -221,8 +213,7 @@
:title (tr "modals.delete-font.title") :title (tr "modals.delete-font.title")
:message (tr "modals.delete-font.message") :message (tr "modals.delete-font.message")
:accept-label (tr "labels.delete") :accept-label (tr "labels.delete")
:on-accept (fn [props] :on-accept (fn [_props] (delete-font-fn))})))
(delete-font-fn))})))
on-delete-variant on-delete-variant
(fn [id] (fn [id]
@ -231,7 +222,7 @@
:title (tr "modals.delete-font-variant.title") :title (tr "modals.delete-font-variant.title")
:message (tr "modals.delete-font-variant.message") :message (tr "modals.delete-font-variant.message")
:accept-label (tr "labels.delete") :accept-label (tr "labels.delete")
:on-accept (fn [props] :on-accept (fn [_props]
(delete-variant-fn id))})))] (delete-variant-fn id))})))]
[:div.font-item.table-row [:div.font-item.table-row
@ -276,7 +267,7 @@
(mf/defc installed-fonts (mf/defc installed-fonts
[{:keys [team fonts] :as props}] [{:keys [fonts] :as props}]
(let [sterm (mf/use-state "") (let [sterm (mf/use-state "")
matches? matches?

View File

@ -7,11 +7,8 @@
(ns app.main.ui.dashboard.grid (ns app.main.ui.dashboard.grid
(:require (:require
[app.common.math :as mth] [app.common.math :as mth]
[app.common.uuid :as uuid]
[app.config :as cfg]
[app.main.data.dashboard :as dd] [app.main.data.dashboard :as dd]
[app.main.data.messages :as dm] [app.main.data.messages :as dm]
[app.main.data.modal :as modal]
[app.main.fonts :as fonts] [app.main.fonts :as fonts]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.store :as st] [app.main.store :as st]
@ -23,12 +20,10 @@
[app.util.dom.dnd :as dnd] [app.util.dom.dnd :as dnd]
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.keyboard :as kbd] [app.util.keyboard :as kbd]
[app.util.router :as rt]
[app.util.time :as dt] [app.util.time :as dt]
[app.util.timers :as ts] [app.util.timers :as ts]
[app.util.webapi :as wapi] [app.util.webapi :as wapi]
[beicon.core :as rx] [beicon.core :as rx]
[cuerdas.core :as str]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
;; --- Grid Item Thumbnail ;; --- Grid Item Thumbnail
@ -59,7 +54,7 @@
(str (tr "ds.updated-at" time)))) (str (tr "ds.updated-at" time))))
(defn create-counter-element (defn create-counter-element
[element file-count] [_element file-count]
(let [counter-el (dom/create-element "div")] (let [counter-el (dom/create-element "div")]
(dom/set-property! counter-el "class" "drag-counter") (dom/set-property! counter-el "class" "drag-counter")
(dom/set-text! counter-el (str file-count)) (dom/set-text! counter-el (str file-count))
@ -215,7 +210,7 @@
[:div.text (tr "dashboard.loading-files")]]) [:div.text (tr "dashboard.loading-files")]])
(mf/defc grid (mf/defc grid
[{:keys [id opts files] :as props}] [{:keys [files] :as props}]
[:section.dashboard-grid [:section.dashboard-grid
(cond (cond
(nil? files) (nil? files)
@ -233,7 +228,7 @@
[:& empty-placeholder])]) [:& empty-placeholder])])
(mf/defc line-grid-row (mf/defc line-grid-row
[{:keys [files team-id selected-files on-load-more dragging?] :as props}] [{:keys [files selected-files on-load-more dragging?] :as props}]
(let [rowref (mf/use-ref) (let [rowref (mf/use-ref)
width (mf/use-state nil) width (mf/use-state nil)
@ -288,7 +283,7 @@
(tr "dashboard.show-all-files")]])])) (tr "dashboard.show-all-files")]])]))
(mf/defc line-grid (mf/defc line-grid
[{:keys [project-id team-id opts files on-load-more] :as props}] [{:keys [project-id team-id files on-load-more] :as props}]
(let [dragging? (mf/use-state false) (let [dragging? (mf/use-state false)
selected-files (mf/deref refs/dashboard-selected-files) selected-files (mf/deref refs/dashboard-selected-files)
@ -326,7 +321,7 @@
on-drop on-drop
(mf/use-callback (mf/use-callback
(mf/deps files selected-files) (mf/deps files selected-files)
(fn [e] (fn [_]
(reset! dragging? false) (reset! dragging? false)
(when (not= selected-project project-id) (when (not= selected-project project-id)
(let [data {:ids (into #{} (keys selected-files)) (let [data {:ids (into #{} (keys selected-files))

View File

@ -7,7 +7,6 @@
(ns app.main.ui.dashboard.import (ns app.main.ui.dashboard.import
(:require (:require
[app.main.ui.components.file-uploader :refer [file-uploader]] [app.main.ui.components.file-uploader :refer [file-uploader]]
[app.main.ui.icons :as i]
[app.main.worker :as uw] [app.main.worker :as uw]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.logging :as log] [app.util.logging :as log]

View File

@ -7,14 +7,11 @@
(ns app.main.ui.dashboard.libraries (ns app.main.ui.dashboard.libraries
(:require (:require
[app.main.data.dashboard :as dd] [app.main.data.dashboard :as dd]
[app.main.refs :as refs]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.dashboard.grid :refer [grid]] [app.main.ui.dashboard.grid :refer [grid]]
[app.main.ui.icons :as i]
[app.main.refs :as refs]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.router :as rt]
[okulary.core :as l]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(mf/defc libraries-page (mf/defc libraries-page

View File

@ -10,7 +10,6 @@
[app.main.data.messages :as dm] [app.main.data.messages :as dm]
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.repo :as rp]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.components.context-menu :refer [context-menu]] [app.main.ui.components.context-menu :refer [context-menu]]
[app.main.ui.context :as ctx] [app.main.ui.context :as ctx]
@ -19,7 +18,6 @@
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.router :as rt] [app.util.router :as rt]
[beicon.core :as rx]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(mf/defc project-menu (mf/defc project-menu
@ -62,7 +60,7 @@
(dd/move-project (with-meta data mdata))))) (dd/move-project (with-meta data mdata)))))
delete-fn delete-fn
(fn [event] (fn [_]
(st/emit! (dm/success (tr "dashboard.success-delete-project")) (st/emit! (dm/success (tr "dashboard.success-delete-project"))
(dd/delete-project project) (dd/delete-project project)
(dd/go-to-projects (:team-id project)))) (dd/go-to-projects (:team-id project))))

View File

@ -6,8 +6,6 @@
(ns app.main.ui.dashboard.projects (ns app.main.ui.dashboard.projects
(:require (:require
[app.common.exceptions :as ex]
[app.main.constants :as c]
[app.main.data.dashboard :as dd] [app.main.data.dashboard :as dd]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.store :as st] [app.main.store :as st]
@ -16,8 +14,7 @@
[app.main.ui.dashboard.project-menu :refer [project-menu]] [app.main.ui.dashboard.project-menu :refer [project-menu]]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :as i18n :refer [t tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.keyboard :as kbd]
[app.util.router :as rt] [app.util.router :as rt]
[app.util.time :as dt] [app.util.time :as dt]
[okulary.core :as l] [okulary.core :as l]
@ -38,7 +35,6 @@
[{:keys [project first? files] :as props}] [{:keys [project first? files] :as props}]
(let [locale (mf/deref i18n/locale) (let [locale (mf/deref i18n/locale)
project-id (:id project)
team-id (:team-id project) team-id (:team-id project)
file-count (or (:count project) 0) file-count (or (:count project) 0)

Some files were not shown because too many files have changed in this diff Show More