0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-25 16:25:56 -05:00

Merge pull request #2148 from penpot/eva-onboarding-zoom-url

🎉 Add zoom style to share link url
This commit is contained in:
Alejandro 2022-08-10 11:24:23 +02:00 committed by GitHub
commit 2d24529165
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 35 deletions

View file

@ -42,6 +42,8 @@
(declare fetch-comment-threads)
(declare fetch-bundle)
(declare bundle-fetched)
(declare zoom-to-fill)
(declare zoom-to-fit)
(s/def ::file-id ::us/uuid)
(s/def ::index ::us/integer)
@ -145,8 +147,13 @@
(let [route (:route state)
qparams (:query-params route)
index (:index qparams)]
(when (nil? index)
(rx/of (go-to-frame-auto))))))))
(rx/merge
(rx/of (case (:zoom qparams)
"fit" zoom-to-fit
"fill" zoom-to-fill
nil))
(when (nil? index)
(rx/of (go-to-frame-auto)))))))))
(defn fetch-comment-threads
[{:keys [file-id page-id share-id] :as params}]
@ -196,32 +203,39 @@
ptk/UpdateEvent
(update [_ state]
(let [increase #(min (* % 1.3) 200)]
(update-in state [:viewer-local :zoom] (fnil increase 1))))))
(-> state
(update-in [:viewer-local :zoom] (fnil increase 1))
(d/dissoc-in [:viewer-local :zoom-type]))))))
(def decrease-zoom
(ptk/reify ::decrease-zoom
ptk/UpdateEvent
(update [_ state]
(let [decrease #(max (/ % 1.3) 0.01)]
(update-in state [:viewer-local :zoom] (fnil decrease 1))))))
(-> state
(update-in [:viewer-local :zoom] (fnil decrease 1))
(d/dissoc-in [:viewer-local :zoom-type]))))))
(def reset-zoom
(ptk/reify ::reset-zoom
ptk/UpdateEvent
(update [_ state]
(assoc-in state [:viewer-local :zoom] 1))))
(-> state
(assoc-in [:viewer-local :zoom] 1)
(d/dissoc-in [:viewer-local :zoom-type])))))
(def zoom-to-fit
(ptk/reify ::zoom-to-fit
ptk/UpdateEvent
(update [_ state]
(let [page-id (get-in state [:route :query-params :page-id])
frame-idx (get-in state [:route :query-params :index])
srect (get (nth (get-in state [:viewer :pages page-id :frames]) frame-idx) :selrect)
original-size (get-in state [:viewer-local :viewport-size])
wdiff (/ (:width original-size) (:width srect))
hdiff (/ (:height original-size) (:height srect))
minzoom (min wdiff hdiff)]
(let [srect (as-> (get-in state [:route :query-params :page-id]) %
(get-in state [:viewer :pages % :frames])
(nth % (get-in state [:route :query-params :index]))
(get % :selrect))
orig-size (get-in state [:viewer-local :viewport-size])
wdiff (/ (:width orig-size) (:width srect))
hdiff (/ (:height orig-size) (:height srect))
minzoom (min wdiff hdiff)]
(-> state
(assoc-in [:viewer-local :zoom] minzoom)
(assoc-in [:viewer-local :zoom-type] :fit))))))
@ -230,13 +244,14 @@
(ptk/reify ::zoom-to-fill
ptk/UpdateEvent
(update [_ state]
(let [page-id (get-in state [:route :query-params :page-id])
frame-idx (get-in state [:route :query-params :index])
srect (get (nth (get-in state [:viewer :pages page-id :frames]) frame-idx) :selrect)
original-size (get-in state [:viewer-local :viewport-size])
wdiff (/ (:width original-size) (:width srect))
hdiff (/ (:height original-size) (:height srect))
maxzoom (max wdiff hdiff)]
(let [srect (as-> (get-in state [:route :query-params :page-id]) %
(get-in state [:viewer :pages % :frames])
(nth % (get-in state [:route :query-params :index]))
(get % :selrect))
orig-size (get-in state [:viewer-local :viewport-size])
wdiff (/ (:width orig-size) (:width srect))
hdiff (/ (:height orig-size) (:height srect))
maxzoom (max wdiff hdiff)]
(-> state
(assoc-in [:viewer-local :zoom] maxzoom)
(assoc-in [:viewer-local :zoom-type] :fill))))))

View file

@ -398,6 +398,11 @@
(dm/get-in state [:viewer-local :fullscreen?]))
st/state))
(def viewer-zoom-type
(l/derived (fn [state]
(dm/get-in state [:viewer-local :zoom-type]))
st/state))
(def thumbnail-data
(l/derived #(dm/get-in % [:workspace-file :thumbnails] {}) st/state))

View file

@ -23,13 +23,13 @@
[app.main.ui.context :as ctx]
[app.main.ui.hooks :as hooks]
[app.main.ui.icons :as i]
[app.main.ui.share-link]
[app.main.ui.static :as static]
[app.main.ui.viewer.comments :refer [comments-layer comments-sidebar]]
[app.main.ui.viewer.handoff :as handoff]
[app.main.ui.viewer.header :refer [header]]
[app.main.ui.viewer.interactions :as interactions]
[app.main.ui.viewer.login]
[app.main.ui.viewer.share-link]
[app.main.ui.viewer.thumbnails :refer [thumbnails-panel]]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]]

View file

@ -4,7 +4,7 @@
;;
;; Copyright (c) UXBOX Labs SL
(ns app.main.ui.share-link
(ns app.main.ui.viewer.share-link
(:require
[app.common.data :as d]
[app.common.logging :as log]
@ -37,20 +37,21 @@
::mf/register-as :share-link}
[{:keys [file page]}]
(let [current-page page
slinks (mf/deref refs/share-links)
router (mf/deref refs/router)
route (mf/deref refs/route)
slinks (mf/deref refs/share-links)
router (mf/deref refs/router)
route (mf/deref refs/route)
zoom-type (mf/deref refs/viewer-zoom-type)
link (mf/use-state nil)
confirm (mf/use-state false)
open-ops (mf/use-state false)
link (mf/use-state nil)
confirm (mf/use-state false)
open-ops (mf/use-state false)
opts (mf/use-state
{:pages-mode "current"
:all-pages false
:pages #{(:id page)}
:who-comment "team"
:who-inspect "team"})
opts (mf/use-state
{:pages-mode "current"
:all-pages false
:pages #{(:id page)}
:who-comment "team"
:who-inspect "team"})
close
@ -137,8 +138,12 @@
href (when slink
(let [pparams (:path-params route)
qparams (-> (:query-params route)
(assoc :share-id (:id slink))
(assoc :index "0"))
(assoc :share-id (:id slink))
(assoc :index "0"))
qparams (if (nil? zoom-type)
(dissoc qparams :zoom)
(assoc qparams :zoom zoom-type))
href (rt/resolve router :viewer pparams qparams)]
(assoc cf/public-uri :fragment href)))]
(reset! link (some-> href str)))))