Explorar o código

fix(pdf): incorrect condition

charlie hai 8 meses
pai
achega
2ad3a8eae1
Modificáronse 1 ficheiros con 11 adicións e 15 borrados
  1. 11 15
      src/main/frontend/extensions/pdf/core.cljs

+ 11 - 15
src/main/frontend/extensions/pdf/core.cljs

@@ -176,13 +176,13 @@
                              (if-not id
                              (if-not id
                                ;; add highlight
                                ;; add highlight
                                (let [highlight (merge highlight
                                (let [highlight (merge highlight
-                                                      {:id         (pdf-utils/gen-uuid)
-                                                       :properties properties})]
+                                                 {:id (pdf-utils/gen-uuid)
+                                                  :properties properties})]
                                  (p/let [highlight' (add-hl! highlight)]
                                  (p/let [highlight' (add-hl! highlight)]
                                    (pdf-utils/clear-all-selection owner-win)
                                    (pdf-utils/clear-all-selection owner-win)
                                    (pdf-assets/copy-hl-ref! highlight' viewer)))
                                    (pdf-assets/copy-hl-ref! highlight' viewer)))
 
 
-;; update highlight
+                               ;; update highlight
                                (upd-hl! (assoc highlight :properties properties)))
                                (upd-hl! (assoc highlight :properties properties)))
 
 
                              (reset! *highlight-last-color (keyword action)))))
                              (reset! *highlight-last-color (keyword action)))))
@@ -568,18 +568,14 @@
                           highlights' (conj highlights hl)]
                           highlights' (conj highlights hl)]
                       (set-highlights! highlights')
                       (set-highlights! highlights')
 
 
-                      (when-let [vw-pos (and (pdf-assets/area-highlight? hl)
-                                          (pdf-utils/scaled-to-vw-pos viewer (:position hl)))]
-                        ;; exceptions
-                        (->
-                          (p/let [result (pdf-assets/persist-hl-area-image$ viewer (:pdf/current @state/state)
-                                           hl nil (:bounding vw-pos))]
-                            (when (de/entity? result)
-                              (let [hl' (assoc-in hl [:content :image] (:db/id result))]
-                                (set-highlights! (map (fn [hl] (if (= (:id hl) (:id hl')) hl' hl)) highlights'))
-                                hl')
-                              ;(throw (js/Error. (str "[pdf] unexpected persist asset image return:" result)))
-                              ))
+                      (if-let [vw-pos (and (pdf-assets/area-highlight? hl)
+                                        (pdf-utils/scaled-to-vw-pos viewer (:position hl)))]
+                        (-> (p/let [result (pdf-assets/persist-hl-area-image$ viewer (:pdf/current @state/state)
+                                             hl nil (:bounding vw-pos))]
+                              (when (de/entity? result)
+                                (let [hl' (assoc-in hl [:content :image] (:db/id result))]
+                                  (set-highlights! (map (fn [hl] (if (= (:id hl) (:id hl')) hl' hl)) highlights'))
+                                  hl')))
                           (p/catch (fn [e] (js/console.error e))))
                           (p/catch (fn [e] (js/console.error e))))
                         hl))))
                         hl))))
         upd-hl! (fn [hl]
         upd-hl! (fn [hl]