Jelajahi Sumber

fix: temporal fix for srs cards

Tienson Qin 4 tahun lalu
induk
melakukan
ea2d0cbce3

+ 19 - 9
src/main/frontend/extensions/srs.cljs

@@ -31,6 +31,8 @@
 ;;; ================================================================
 ;;; const & vars
 
+;; TODO: simplify state
+
 (def card-hash-tag "card")
 
 (def card-last-interval-property        :card-last-interval)
@@ -378,8 +380,9 @@
   (swap! *review-records #(update % score (fn [ov] (conj ov card))))
   (if (>= (inc @*card-index) (count cards))
     (when cb
-      (swap! *card-index inc)
-      (cb @*review-records))
+      (do
+        (swap! *card-index inc)
+        (cb @*review-records)))
     (do
       (swap! *card-index inc)
       (reset! *phase 1))))
@@ -399,18 +402,24 @@
   (rum/local 1 ::phase)
   (rum/local 0 ::card-index)
   (rum/local {} ::review-records)
+  {:will-mount (fn [state]
+                 (state/set-state! :srs/mode? true)
+                 state)
+   :will-unmount (fn [state]
+                   (state/set-state! :srs/mode? false)
+                   state)}
   [state blocks {preview? :preview?
                  modal? :modal?
+                 global? :global?
                  cb :callback}]
   (let [cards (map ->card blocks)
         review-records (::review-records state)
         card-index (::card-index state)
-        card-index (if (> (count cards) @card-index)
-                     card-index
-                     (do
-                       (swap! card-index dec)
-                       card-index))
-        card (util/nth-safe cards @card-index)]
+        idx (if (and global?
+                     (>= (inc @card-index) (count blocks)))
+              (dec @card-index)
+              @card-index)
+        card (util/nth-safe cards idx)]
     (if-not card
       review-finished
       (let [phase (::phase state)
@@ -625,7 +634,8 @@
 
 (rum/defc global-cards
   []
-  (cards {:modal? true} {}))
+  (cards {:modal? true
+          :global? true} {}))
 
 (component-macro/register query-macro-name cards)
 

+ 2 - 1
src/main/frontend/handler/ui.cljs

@@ -50,7 +50,8 @@
 
 (defn toggle-settings-modal!
   []
-  (state/toggle-settings!))
+  (when-not (:srs/mode? @state/state)
+    (state/toggle-settings!)))
 
 ;; FIXME: re-render all embedded blocks since they will not be re-rendered automatically
 

+ 3 - 1
src/main/frontend/state.cljs

@@ -175,7 +175,9 @@
 
       :encryption/graph-parsing? false
 
-      :favorites/dragging nil})))
+      :favorites/dragging nil
+
+      :srs/mode? false})))
 
 
 (defn sub