0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 07:29:08 -05:00

Add infor for users

This commit is contained in:
alonso.torres 2024-06-04 16:18:55 +02:00 committed by Andrey Antukh
parent 98c550b20e
commit 3e2ccbc85f
5 changed files with 105 additions and 14 deletions

View file

@ -2016,16 +2016,18 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn change-canvas-color
[color]
(ptk/reify ::change-canvas-color
ptk/WatchEvent
(watch [it state _]
(let [page (wsh/lookup-page state)
changes (-> (pcb/empty-changes it)
(pcb/with-page page)
(pcb/set-page-option :background (:color color)))]
(rx/of (dch/commit-changes changes))))))
([color]
(change-canvas-color nil color))
([page-id color]
(ptk/reify ::change-canvas-color
ptk/WatchEvent
(watch [it state _]
(let [page-id (or page-id (:current-page-id state))
page (wsh/lookup-page state page-id)
changes (-> (pcb/empty-changes it)
(pcb/with-page page)
(pcb/set-page-option :background (:color color)))]
(rx/of (dch/commit-changes changes)))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Read only

View file

@ -24,6 +24,7 @@
[app.plugins.library :as library]
[app.plugins.page :as page]
[app.plugins.shape :as shape]
[app.plugins.user :as user]
[app.plugins.utils :as utils]
[app.plugins.viewport :as viewport]
[app.util.object :as obj]
@ -92,6 +93,18 @@
"dark"
(get-in @st/state [:profile :theme]))))
(getCurrentUser
[_]
(user/current-user-proxy (:session-id @st/state)))
(getActiveUsers
[_]
(apply array
(->> (:workspace-presence @st/state)
(vals)
(remove #(= (:id %) (:session-id @st/state)))
(map #(user/active-user-proxy (:id %))))))
(uploadMediaUrl
[_ name url]
(let [file-id (:current-file-id @st/state)]
@ -190,4 +203,6 @@
{:name "currentPage" :get #(.getPage ^js %)}
{:name "selection" :get #(.getSelectedShapes ^js %)}
{:name "viewport" :get #(.getViewport ^js %)}
{:name "currentUser" :get #(.getCurrentUser ^js %)}
{:name "activeUsers" :get #(.getActiveUsers ^js %)}
{:name "library" :get (fn [_] (library/library-subcontext))}))

View file

@ -7,11 +7,14 @@
(ns app.plugins.page
"RPC for plugins runtime."
(:require
[app.common.colors :as cc]
[app.common.data.macros :as dm]
[app.common.record :as crc]
[app.common.uuid :as uuid]
[app.main.data.workspace :as dw]
[app.main.store :as st]
[app.plugins.shape :as shape]
[app.plugins.utils :refer [locate-page proxy->page]]
[app.plugins.utils :as u]
[app.util.object :as obj]))
(deftype PageProxy [$file $id]
@ -29,7 +32,7 @@
[_]
;; Returns a lazy (iterable) of all available shapes
(when (and (some? $file) (some? $id))
(let [page (locate-page $file $id)]
(let [page (u/locate-page $file $id)]
(apply array (sequence (map shape/shape-proxy) (keys (:objects page))))))))
(crc/define-properties!
@ -48,8 +51,22 @@
:get #(dm/str (obj/get % "$id"))}
{:name "name"
:get #(-> % proxy->page :name)}
:get #(-> % u/proxy->page :name)
:set
(fn [_ value]
(if (string? value)
(st/emit! (dw/rename-page id value))
(u/display-not-valid :page-name value)))}
{:name "root"
:enumerable false
:get #(.getRoot ^js %)}))
:get #(.getRoot ^js %)}
{:name "background"
:enumerable false
:get #(or (-> % u/proxy->page :options :background) cc/canvas)
:set
(fn [_ value]
(if (and (some? value) (string? value) (cc/valid-hex-color? value))
(st/emit! (dw/change-canvas-color id {:color value}))
(u/display-not-valid :page-background-color value)))}))

View file

@ -0,0 +1,48 @@
;; 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) KALEIDOS INC
(ns app.plugins.user
(:require
[app.common.record :as crc]
[app.config :as cfg]
[app.plugins.utils :as u]
[app.util.object :as obj]))
(deftype CurrentUserProxy [$session])
(deftype ActiveUserProxy [$session])
(defn add-user-properties
[user-proxy]
(let [session-id (obj/get user-proxy "$session")]
(crc/add-properties!
user-proxy
{:name "id"
:get (fn [_] (-> (u/locate-profile session-id) :id str))}
{:name "name"
:get (fn [_] (-> (u/locate-profile session-id) :fullname))}
{:name "avatarUrl"
:get (fn [_] (cfg/resolve-profile-photo-url (u/locate-profile session-id)))}
{:name "color"
:get (fn [_] (-> (u/locate-presence session-id) :color))}
{:name "sessionId"
:get (fn [_] (str session-id))})))
(defn current-user-proxy
[session-id]
(-> (CurrentUserProxy. session-id)
(add-user-properties)))
(defn active-user-proxy
[session-id]
(-> (ActiveUserProxy. session-id)
(add-user-properties)
(crc/add-properties!
{:name "position" :get (fn [_] (-> (u/locate-presence session-id) :point u/to-js))}
{:name "zoom" :get (fn [_] (-> (u/locate-presence session-id) :zoom))})))

View file

@ -53,6 +53,15 @@
(assert (uuid? id) "Component not valid uuid")
(dm/get-in (locate-file file-id) [:data :components id]))
(defn locate-presence
[session-id]
(dm/get-in @st/state [:workspace-presence session-id]))
(defn locate-profile
[session-id]
(let [{:keys [profile-id]} (locate-presence session-id)]
(dm/get-in @st/state [:users profile-id])))
(defn proxy->file
[proxy]
(let [id (obj/get proxy "$id")]