🎉 Render dashbaord thumbnails on webworker.

This commit is contained in:
Andrey Antukh 2020-05-05 19:48:51 +02:00 committed by Alonso Torres
parent f2274d8617
commit adfa117dc0
7 changed files with 41 additions and 35 deletions

View file

@ -124,15 +124,16 @@
(defmethod load-font :google (defmethod load-font :google
[{:keys [id family variants ::on-loaded] :as font}] [{:keys [id family variants ::on-loaded] :as font}]
(js/console.log "[debug:fonts]: loading google font" id) (when (exists? js/window)
(let [base (str "https://fonts.googleapis.com/css?family=" family) (js/console.log "[debug:fonts]: loading google font" id)
variants (str/join "," (map :id variants)) (let [base (str "https://fonts.googleapis.com/css?family=" family)
uri (str base ":" variants "&display=block") variants (str/join "," (map :id variants))
node (create-link-node uri)] uri (str base ":" variants "&display=block")
(.addEventListener node "load" (fn [event] (when (fn? on-loaded) node (create-link-node uri)]
(on-loaded id)))) (.addEventListener node "load" (fn [event] (when (fn? on-loaded)
(.append (.-head js/document) node) (on-loaded id))))
nil)) (.append (.-head js/document) node)
nil)))
(defmethod load-font :default (defmethod load-font :default
[{:keys [backend] :as font}] [{:keys [backend] :as font}]

View file

@ -27,7 +27,6 @@
[uxbox.main.ui.profile.recovery-request :refer [profile-recovery-request-page]] [uxbox.main.ui.profile.recovery-request :refer [profile-recovery-request-page]]
[uxbox.main.ui.profile.register :refer [profile-register-page]] [uxbox.main.ui.profile.register :refer [profile-register-page]]
[uxbox.main.ui.settings :as settings] [uxbox.main.ui.settings :as settings]
[uxbox.main.ui.shapes]
[uxbox.main.ui.viewer :refer [viewer-page]] [uxbox.main.ui.viewer :refer [viewer-page]]
[uxbox.main.ui.workspace :as workspace] [uxbox.main.ui.workspace :as workspace]
[uxbox.util.i18n :refer [tr]] [uxbox.util.i18n :refer [tr]]

View file

@ -1,15 +1,17 @@
(ns uxbox.main.ui.dashboard.grid (ns uxbox.main.ui.dashboard.grid
(:require (:require
[cuerdas.core :as str] [cuerdas.core :as str]
[beicon.core :as rx]
[rumext.alpha :as mf] [rumext.alpha :as mf]
[uxbox.builtins.icons :as i] [uxbox.builtins.icons :as i]
[uxbox.main.data.dashboard :as dsh] [uxbox.main.data.dashboard :as dsh]
[uxbox.main.store :as st] [uxbox.main.store :as st]
[uxbox.main.exports :as exports]
[uxbox.main.ui.modal :as modal] [uxbox.main.ui.modal :as modal]
[uxbox.main.ui.keyboard :as kbd] [uxbox.main.ui.keyboard :as kbd]
[uxbox.main.ui.confirm :refer [confirm-dialog]] [uxbox.main.ui.confirm :refer [confirm-dialog]]
[uxbox.main.ui.components.context-menu :refer [context-menu]] [uxbox.main.ui.components.context-menu :refer [context-menu]]
[uxbox.main.worker :as wrk]
[uxbox.main.fonts :as fonts]
[uxbox.util.dom :as dom] [uxbox.util.dom :as dom]
[uxbox.util.i18n :as i18n :refer [t tr]] [uxbox.util.i18n :as i18n :refer [t tr]]
[uxbox.util.router :as rt] [uxbox.util.router :as rt]
@ -19,12 +21,19 @@
;; --- Grid Item Thumbnail ;; --- Grid Item Thumbnail
(mf/defc grid-item-thumbnail (mf/defc grid-item-thumbnail
{::mf/wrap [#(mf/deferred % ts/schedule-on-idle)]} {::mf/wrap [mf/memo]}
[{:keys [file] :as props}] [{:keys [file] :as props}]
[:div.grid-item-th (let [container (mf/use-ref)]
[:& exports/page-svg {:data (:data file) (mf/use-effect
:width "290" (mf/deps file)
:height "150"}]]) (fn []
(-> (wrk/ask! {:cmd :thumbnails/generate
:data (:data file)})
(rx/subscribe (fn [{:keys [svg fonts]}]
(run! fonts/ensure-loaded! fonts)
(let [node (mf/ref-val container)]
(set! (.-innerHTML node) svg)))))))
[:div.grid-item-th {:ref container}]))
;; --- Grid Item ;; --- Grid Item

View file

@ -117,8 +117,8 @@
(mf/defc text-shape (mf/defc text-shape
{::mf/wrap-props false} {::mf/wrap-props false}
[props] [props]
(let [shape (unchecked-get props "shape") (let [shape (unchecked-get props "shape")
shape (unchecked-get props "selected?") selected? (unchecked-get props "selected?")
{:keys [id x y width height rotation content]} shape] {:keys [id x y width height rotation content]} shape]
[:foreignObject {:x x [:foreignObject {:x x
:y y :y y

View file

@ -7,14 +7,16 @@
(ns uxbox.util.http (ns uxbox.util.http
"A http client with rx streams interface." "A http client with rx streams interface."
(:refer-clojure :exclude [get]) (:refer-clojure :exclude [get])
(:require [beicon.core :as rx] (:require
[goog.events :as events] [beicon.core :as rx]
[clojure.string :as str]) [goog.events :as events]
(:import [goog.net ErrorCode EventType] [clojure.string :as str])
[goog.net.XhrIo ResponseType] (:import
[goog.net XhrIo] [goog.net ErrorCode EventType]
[goog.Uri QueryData] [goog.net.XhrIo ResponseType]
[goog Uri])) [goog.net XhrIo]
[goog.Uri QueryData]
[goog Uri]))
(defn translate-method (defn translate-method
[method] [method]

View file

@ -18,6 +18,7 @@
[uxbox.common.uuid :as uuid] [uxbox.common.uuid :as uuid]
[uxbox.worker.impl :as impl] [uxbox.worker.impl :as impl]
[uxbox.worker.selection] [uxbox.worker.selection]
[uxbox.worker.thumbnails]
[uxbox.util.transit :as t] [uxbox.util.transit :as t]
[uxbox.util.worker :as w])) [uxbox.util.worker :as w]))

View file

@ -13,22 +13,16 @@
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[uxbox.common.exceptions :as ex] [uxbox.common.exceptions :as ex]
[uxbox.common.spec :as us] [uxbox.common.spec :as us]
[uxbox.main.fonts :as fonts]
[uxbox.main.exports :as exports] [uxbox.main.exports :as exports]
[uxbox.worker.impl :as impl] [uxbox.worker.impl :as impl]
["react-dom/server" :as rds])) ["react-dom/server" :as rds]))
(mf/defc foobar
[{:keys [name]}]
[:span name])
(defmethod impl/handler :echo
[message]
{:result (rds/renderToString (mf/element foobar {:name "foobar"}))})
(defmethod impl/handler :thumbnails/generate (defmethod impl/handler :thumbnails/generate
[{:keys [data] :as message}] [{:keys [data] :as message}]
(let [elem (mf/element exports/page-svg #js {:data data (let [elem (mf/element exports/page-svg #js {:data data
:width "290" :width "290"
:height "150"})] :height "150"})]
(rds/renderToStaticMarkup elem))) {:svg (rds/renderToStaticMarkup elem)
:fonts @fonts/loaded}))