|
@@ -368,25 +368,23 @@
|
|
|
n))))
|
|
|
|
|
|
(defn- review-finished?
|
|
|
- [global? cards *card-index]
|
|
|
- (if global?
|
|
|
- (<= (count cards) 1)
|
|
|
- (>= @*card-index (count cards))))
|
|
|
+ [cards]
|
|
|
+ (<= (count cards) 1))
|
|
|
|
|
|
-(defn- score-and-next-card [score card *card-index cards *phase *review-records cb global?]
|
|
|
+(defn- score-and-next-card [score card *card-index cards *phase *review-records cb]
|
|
|
(operation-score! card score)
|
|
|
(swap! *review-records #(update % score (fn [ov] (conj ov card))))
|
|
|
- (if (review-finished? global? cards *card-index)
|
|
|
+ (if (review-finished? cards)
|
|
|
(when cb (cb @*review-records))
|
|
|
(reset! *phase 1))
|
|
|
(swap! *card-index inc)
|
|
|
(when @global-cards-mode?
|
|
|
(dec-cards-due-count!)))
|
|
|
|
|
|
-(defn- skip-card [card *card-index cards *phase *review-records cb global?]
|
|
|
+(defn- skip-card [card *card-index cards *phase *review-records cb]
|
|
|
(swap! *review-records #(update % "skip" (fn [ov] (conj ov card))))
|
|
|
(swap! *card-index inc)
|
|
|
- (if (review-finished? global? cards *card-index)
|
|
|
+ (if (review-finished? cards)
|
|
|
(when cb (cb @*review-records))
|
|
|
(reset! *phase 1)))
|
|
|
|
|
@@ -416,7 +414,6 @@
|
|
|
state)}
|
|
|
[state blocks {preview? :preview?
|
|
|
modal? :modal?
|
|
|
- global? :global?
|
|
|
cb :callback}
|
|
|
card-index]
|
|
|
(let [cards (map ->card blocks)
|
|
@@ -460,7 +457,7 @@
|
|
|
(ui/button [:span "Next " (ui/render-keyboard-shortcut [:n])]
|
|
|
:id "card-next"
|
|
|
:class "mr-2"
|
|
|
- :on-click #(skip-card card card-index cards phase review-records cb global?)))
|
|
|
+ :on-click #(skip-card card card-index cards phase review-records cb)))
|
|
|
|
|
|
(when (and (not preview?) (= 1 next-phase))
|
|
|
[:div.flex.flex-row.justify-between
|
|
@@ -469,20 +466,20 @@
|
|
|
:id "card-forgotten"
|
|
|
:background "red"
|
|
|
:on-click (fn []
|
|
|
- (score-and-next-card 1 card card-index cards phase review-records cb global?)
|
|
|
+ (score-and-next-card 1 card card-index cards phase review-records cb)
|
|
|
(let [tomorrow (tc/to-string (t/plus (t/today) (t/days 1)))]
|
|
|
(editor-handler/set-block-property! root-block-id card-next-schedule-property tomorrow)))})
|
|
|
|
|
|
(btn-with-shortcut {:btn-text (if (util/mobile?) "Hard" "Took a while to recall")
|
|
|
:shortcut "t"
|
|
|
:id "card-recall"
|
|
|
- :on-click #(score-and-next-card 3 card card-index cards phase review-records cb global?)})
|
|
|
+ :on-click #(score-and-next-card 3 card card-index cards phase review-records cb)})
|
|
|
|
|
|
(btn-with-shortcut {:btn-text "Remembered"
|
|
|
:shortcut "r"
|
|
|
:id "card-remembered"
|
|
|
:background "green"
|
|
|
- :on-click #(score-and-next-card 5 card card-index cards phase review-records cb global?)})])]
|
|
|
+ :on-click #(score-and-next-card 5 card card-index cards phase review-records cb)})])]
|
|
|
|
|
|
(when preview?
|
|
|
(ui/tippy {:html [:div.text-sm
|
|
@@ -501,7 +498,11 @@
|
|
|
rum/reactive
|
|
|
db-mixins/query
|
|
|
[blocks option card-index]
|
|
|
- (let [blocks (if (fn? blocks) (blocks) blocks)]
|
|
|
+ (let [option (update option :random-mode? (fn [v] (if (boolean? v) v @v)))
|
|
|
+ blocks (if (fn? blocks) (blocks) blocks)
|
|
|
+ blocks (if (:random-mode? option)
|
|
|
+ (shuffle blocks)
|
|
|
+ blocks)]
|
|
|
(if (seq blocks)
|
|
|
(view blocks option card-index)
|
|
|
review-finished)))
|
|
@@ -553,10 +554,12 @@
|
|
|
count))))
|
|
|
|
|
|
;;; register cards macro
|
|
|
-(rum/defcs cards < rum/reactive db-mixins/query
|
|
|
+(rum/defcs ^:large-vars/cleanup-todo cards < rum/reactive db-mixins/query
|
|
|
(rum/local 0 ::card-index)
|
|
|
+ (rum/local false ::random-mode?)
|
|
|
[state config options]
|
|
|
- (let [repo (state/get-current-repo)
|
|
|
+ (let [*random-mode? (::random-mode? state)
|
|
|
+ repo (state/get-current-repo)
|
|
|
query-string (string/join ", " (:arguments options))
|
|
|
query-result (query repo query-string)
|
|
|
card-index (::card-index state)
|
|
@@ -598,10 +601,25 @@
|
|
|
(let [blocks-f (fn [] (query repo query-string))]
|
|
|
(state/set-modal! #(view-modal
|
|
|
blocks-f
|
|
|
- {:preview? true}
|
|
|
+ {:preview? true
|
|
|
+ :random-mode? *random-mode?}
|
|
|
card-index)
|
|
|
{:id :srs})))}
|
|
|
- "A"])]]
|
|
|
+ "A"])
|
|
|
+
|
|
|
+ (ui/tippy
|
|
|
+ {:html [:div.text-sm "Toggle random mode"]
|
|
|
+ :delay [1000, 100]
|
|
|
+ :class "tippy-hover"
|
|
|
+ :interactive true}
|
|
|
+ [:a.mt-1.ml-2.block.opacity-60.hover:opacity-100 {:on-mouse-down (fn [e]
|
|
|
+ (util/stop e)
|
|
|
+ (swap! *random-mode? not))}
|
|
|
+ (ui/icon "arrows-shuffle" {:style (cond->
|
|
|
+ {:font-size 18
|
|
|
+ :font-weight 600}
|
|
|
+ @*random-mode?
|
|
|
+ (assoc :color "orange"))})])]]
|
|
|
(if (seq review-cards)
|
|
|
[:div.px-1
|
|
|
(when-not modal?
|
|
@@ -612,6 +630,7 @@
|
|
|
(state/set-modal! #(view-modal
|
|
|
blocks-f
|
|
|
{:modal? true
|
|
|
+ :random-mode? *random-mode?
|
|
|
:callback
|
|
|
(fn [review-records]
|
|
|
(operation-card-info-summary!
|
|
@@ -623,6 +642,7 @@
|
|
|
(view-fn review-cards
|
|
|
(merge config
|
|
|
{:global? global?
|
|
|
+ :random-mode? @*random-mode?
|
|
|
:callback
|
|
|
(fn [review-records]
|
|
|
(operation-card-info-summary!
|