mirror of
https://github.com/penpot/penpot.git
synced 2025-01-25 16:09:17 -05:00
✨ Enable anonymous users and viewer with token.
This commit is contained in:
parent
fe203fe70c
commit
ce28464251
5 changed files with 41 additions and 23 deletions
|
@ -41,7 +41,7 @@
|
|||
(declare bundle-fetched)
|
||||
|
||||
(defn initialize
|
||||
[page-id]
|
||||
[page-id share-token]
|
||||
(ptk/reify ::initialize
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
@ -49,18 +49,21 @@
|
|||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(rx/of (fetch-bundle page-id)))))
|
||||
(rx/of (fetch-bundle page-id share-token)))))
|
||||
|
||||
;; --- Data Fetching
|
||||
|
||||
(defn fetch-bundle
|
||||
[page-id]
|
||||
[page-id share-token]
|
||||
(ptk/reify ::fetch-file
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(->> (rp/query :viewer-bundle {:page-id page-id})
|
||||
(rx/map bundle-fetched)))))
|
||||
|
||||
(let [params (cond-> {:page-id page-id}
|
||||
(string? share-token) (assoc :share-token share-token))]
|
||||
(->> (rp/query :viewer-bundle params)
|
||||
(rx/map bundle-fetched)
|
||||
(rx/catch (fn [error-data]
|
||||
(rx/of (rt/nav :not-found)))))))))
|
||||
|
||||
(defn- extract-frames
|
||||
[page]
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2017-2019 Andrey Antukh <niwi@niwi.nz>
|
||||
;; Copyright (c) 2020 UXBOX Labs SL
|
||||
|
||||
(ns uxbox.main.refs
|
||||
"A collection of derived refs."
|
||||
|
|
|
@ -101,12 +101,6 @@
|
|||
:profile-recovery
|
||||
[:& profile-recovery-page]
|
||||
|
||||
:viewer
|
||||
(let [index (d/parse-integer (get-in route [:params :query :index]))
|
||||
page-id (uuid (get-in route [:params :path :page-id]))]
|
||||
[:& viewer-page {:page-id page-id
|
||||
:index index}])
|
||||
|
||||
(:settings-profile
|
||||
:settings-password)
|
||||
[:& settings/settings {:route route}]
|
||||
|
@ -126,6 +120,14 @@
|
|||
:dashboard-library-palettes-index)
|
||||
[:& dashboard {:route route}]
|
||||
|
||||
:viewer
|
||||
(let [index (d/parse-integer (get-in route [:params :query :index]))
|
||||
token (get-in route [:params :query :token])
|
||||
page-id (uuid (get-in route [:params :path :page-id]))]
|
||||
[:& viewer-page {:page-id page-id
|
||||
:index index
|
||||
:token token}])
|
||||
|
||||
:workspace
|
||||
(let [project-id (uuid (get-in route [:params :path :project-id]))
|
||||
file-id (uuid (get-in route [:params :path :file-id]))
|
||||
|
|
|
@ -96,8 +96,11 @@
|
|||
(l/derive st/state)))
|
||||
|
||||
(mf/defc viewer-page
|
||||
[{:keys [page-id index] :as props}]
|
||||
(mf/use-effect (mf/deps page-id) #(st/emit! (dv/initialize page-id)))
|
||||
[{:keys [page-id index token] :as props}]
|
||||
(mf/use-effect
|
||||
(mf/deps page-id token)
|
||||
#(st/emit! (dv/initialize page-id token)))
|
||||
|
||||
(let [data (mf/deref viewer-data-ref)
|
||||
local (mf/deref viewer-local-ref)]
|
||||
(when data
|
||||
|
|
|
@ -18,8 +18,10 @@
|
|||
[uxbox.main.store :as st]
|
||||
[uxbox.main.ui.components.dropdown :refer [dropdown]]
|
||||
[uxbox.main.data.viewer :as dv]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.util.data :refer [classnames]]
|
||||
[uxbox.util.dom :as dom]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.util.i18n :as i18n :refer [t tr]]
|
||||
[uxbox.util.math :as mth]
|
||||
[uxbox.util.router :as rt])
|
||||
|
@ -64,7 +66,6 @@
|
|||
create #(st/emit! dv/create-share-link)
|
||||
delete #(st/emit! dv/delete-share-link)
|
||||
href (.-href js/location)]
|
||||
|
||||
[:*
|
||||
[:span.btn-share.tooltip.tooltip-bottom
|
||||
{:alt "Share link"
|
||||
|
@ -78,7 +79,7 @@
|
|||
[:span.share-link-title "Share link"]
|
||||
[:div.share-link-input
|
||||
(if (string? token)
|
||||
[:span.link (str href "&" token)]
|
||||
[:span.link (str href "&token=" token)]
|
||||
[:span "Share link will apear here"])
|
||||
i/chain]
|
||||
[:span.share-link-subtitle "Anyone with the link will have access"]
|
||||
|
@ -87,16 +88,23 @@
|
|||
[:button.btn-delete {:on-click delete} "Remove link"]
|
||||
[:button.btn-primary {:on-click create} "Create link"])]]]]))
|
||||
|
||||
|
||||
(mf/defc header
|
||||
[{:keys [data index local fullscreen? toggle-fullscreen] :as props}]
|
||||
(let [{:keys [project file page frames]} data
|
||||
total (count frames)
|
||||
on-click #(st/emit! dv/toggle-thumbnails-panel)
|
||||
|
||||
profile (mf/deref refs/profile)
|
||||
anonymous? (= uuid/zero (:id profile))
|
||||
|
||||
project-id (get-in data [:project :id])
|
||||
file-id (get-in data [:file :id])
|
||||
page-id (get-in data [:page :id])
|
||||
|
||||
on-edit #(st/emit! (rt/nav :workspace
|
||||
{:project-id (get-in data [:project :id])
|
||||
:file-id (get-in data [:file :id])}
|
||||
{:page-id (get-in data [:page :id])}))]
|
||||
{:project-id project-id
|
||||
:file-id file-id}
|
||||
{:page-id page-id}))]
|
||||
[:header.viewer-header
|
||||
[:div.main-icon
|
||||
[:a i/logo-icon]]
|
||||
|
@ -112,8 +120,10 @@
|
|||
[:span.counters (str (inc index) " / " total)]]
|
||||
|
||||
[:div.options-zone
|
||||
[:& share-link {:page (:page data)}]
|
||||
[:span.btn-primary {:on-click on-edit} "Edit page"]
|
||||
(when-not anonymous?
|
||||
[:& share-link {:page (:page data)}])
|
||||
(when-not anonymous?
|
||||
[:span.btn-primary {:on-click on-edit} "Edit page"])
|
||||
[:& zoom-widget {:zoom (:zoom local)}]
|
||||
[:span.btn-fullscreen.tooltip.tooltip-bottom
|
||||
{:alt "Full screen"
|
||||
|
|
Loading…
Add table
Reference in a new issue