Skip to content

Commit

Permalink
optimize loads
Browse files Browse the repository at this point in the history
  • Loading branch information
lgessler committed Dec 21, 2021
1 parent 544588a commit ee12b6e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
30 changes: 20 additions & 10 deletions src/main/glam/client/ui/document/interlinear_editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
["react-window" :refer [FixedSizeList]]
[glam.client.router :as r]
[glam.client.util :as gcu]
[glam.client.ui.common.core :refer [loader]]
[glam.client.ui.material-ui :as mui]
[glam.algos.text :as ta]
[glam.models.span :as span]
Expand Down Expand Up @@ -72,6 +73,7 @@


(declare batched-update)
(declare InterlinearEditor)
(m/defmutation apply-schema
"Called by g.c.u.d.document. Makes changes to the document on load to make it consistent with schematic requirements
of the interface."
Expand Down Expand Up @@ -187,9 +189,14 @@
(m/defmutation batched-update
[params]
(action [_] nil)
(remote [{:keys [ast]}]
(remote [{:keys [ast state ref]}]
(swap! state assoc-in (conj ref :ui/busy?) true)
(let [ast (assoc ast :key `span/batched-update)]
ast)))
ast))
(result-action [{:keys [component app result ref]}]
(df/load! app ref InterlinearEditor
{:post-action (fn [{:keys [state]}]
(swap! state assoc-in (conj ref :ui/busy?) false))})))

(m/defmutation save-span
[{doc-id :document/id :as params}]
Expand Down Expand Up @@ -450,7 +457,7 @@
(ui-sentence-level-span span)
(log/error "No span found for span layer " id "!"))))))))]

(let [page-count 5]
(let [page-count 10]
(dom/div {}
(mui/typography {:variant "h5" :style {:marginBottom "1em"}} name)

Expand All @@ -463,7 +470,7 @@
(mui/pagination
{:count (js/Math.ceil (/ (count filtered-lines) page-count))
:page page
:onChange #(do (log/info %2) (m/set-integer! this :ui/page :value %2))}))))))
:onChange #(m/set-integer! this :ui/page :value %2)}))))))

(def ui-token-layer (c/computed-factory TokenLayer {:keyfn :token-layer/id}))

Expand All @@ -489,19 +496,22 @@
(def ui-text-layer (c/computed-factory TextLayer {:keyfn :text-layer/id}))

(defsc ProjectQuery [_ _] {:ident :project/id :query [:project/config :project/id]})
(defsc InterlinearEditor [this {:document/keys [id name text-layers project] :as props}]
(defsc InterlinearEditor [this {:document/keys [id name text-layers project] :ui/keys [busy?] :as props}]
{:query [:document/id :document/name
{:document/text-layers (c/get-query TextLayer)}
{:document/project (c/get-query ProjectQuery)}]
{:document/project (c/get-query ProjectQuery)}
:ui/busy?]
:ident :document/id}
;;(if (empty? (-> props :document/project :project/config))
;; (dom/p "The interlinear editor must have at least one span layer designated as ")
;; )
(dom/div
(when text-layers
(c/fragment
(mapv ui-text-layer (map #(c/computed % {:config (-> project :project/config :editors :interlinear)})
text-layers))))))
(if busy?
(loader)
(when text-layers
(c/fragment
(mapv ui-text-layer (map #(c/computed % {:config (-> project :project/config :editors :interlinear)})
text-layers)))))))

(def ui-interlinear-editor (c/factory InterlinearEditor))

Expand Down
6 changes: 2 additions & 4 deletions src/main/glam/client/ui/document/text_editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
(when message
(snack/message! {:message message
:severity (if error? "error" "success")}))
;; disable for now--push notification loading handles this
#_ (df/load! app [:document/id doc-id] TextEditor))))
(df/load! app [:document/id doc-id] TextEditor))))

(m/defmutation create-text
[{doc-id :document/id :as params}]
Expand All @@ -59,8 +58,7 @@
(snack/message! {:message message
:severity (if error? "error" "success")}))
(tempid/resolve-tempids! app (get-in env [:result :body]))
;; disable for now--push notification loading handles this
#_(df/load! app [:document/id doc-id] TextEditor))))
(df/load! app [:document/id doc-id] TextEditor))))

(defsc Text
[this {:text/keys [id body] :ui/keys [busy? pristine-body ops] :as props} {document-id :document/id
Expand Down
3 changes: 1 addition & 2 deletions src/main/glam/client/ui/document/token_editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
(snack/message! {:message message
:severity (if error? "error" "success")}))
;; we may need new token offsets--trigger a load
;; (actually, disable since we're using push notifications for new loads)
#_(df/load! app [:document/id doc-id] TokenEditor))))
(df/load! app [:document/id doc-id] TokenEditor))))

(defsc Text
[this {:text/keys [id body] :as props}]
Expand Down

0 comments on commit ee12b6e

Please sign in to comment.