Browse Source

feat: toggle displaying flashcards

Tienson Qin 3 years ago
parent
commit
1857f884d2

+ 20 - 5
src/main/frontend/components/settings.cljs

@@ -491,7 +491,15 @@
          {:style {:top -18 :left 10}}
          (ui/button (t :plugin/restart)
                     :on-click #(js/logseq.api.relaunch)
-                    :small? true :intent "logseq")]])]))
+           :small? true :intent "logseq")]])]))
+
+(rum/defc flashcards-enabled-switcher
+  [enable-flashcards?]
+  (ui/toggle enable-flashcards?
+             (fn []
+               (let [value (not enable-flashcards?)]
+                 (config-handler/set-config! :feature/enable-flashcards? value)))
+             true))
 
 (rum/defc user-proxy-settings
   [{:keys [protocol host port] :as agent-opts}]
@@ -508,6 +516,11 @@
    {:left-label (t :settings-page/plugin-system)
     :action (plugin-enabled-switcher t)}))
 
+(defn flashcards-switcher-row [enable-flashcards?]
+  (row-with-button-action
+   {:left-label (t :settings-page/enable-flashcards)
+    :action (flashcards-enabled-switcher enable-flashcards?)}))
+
 (defn https-user-agent-row [agent-opts]
   (row-with-button-action
    {:left-label (t :settings-page/network-proxy)
@@ -596,16 +609,18 @@
      :warning
      [:p (t :settings-page/git-confirm)])])
 
-(rum/defcs settings-advanced < rum/reactive
-  [_state]
+(rum/defc settings-advanced < rum/reactive
+  [current-repo]
   (let [instrument-disabled? (state/sub :instrument/disabled?)
         developer-mode? (state/sub [:ui/developer-mode?])
-        https-agent-opts (state/sub [:electron/user-cfgs :settings/agent])]
+        https-agent-opts (state/sub [:electron/user-cfgs :settings/agent])
+        enable-flashcards? (state/enable-flashcards? current-repo)]
     [:div.panel-wrap.is-advanced
      (when (and util/mac? (util/electron?)) (app-auto-update-row t))
      (usage-diagnostics-row t instrument-disabled?)
      (when-not (mobile-util/native-platform?) (developer-mode-row t developer-mode?))
      (when (util/electron?) (plugin-system-switcher-row))
+     (flashcards-switcher-row enable-flashcards?)
      (when (util/electron?) (https-user-agent-row https-agent-opts))
      (clear-cache-row t)
 
@@ -678,6 +693,6 @@
          (settings-git)
 
          :advanced
-         (settings-advanced)
+         (settings-advanced current-repo)
 
          nil)]]]))

+ 6 - 5
src/main/frontend/components/sidebar.cljs

@@ -245,8 +245,9 @@
              :on-click-handler route-handler/go-to-journals!
              :icon             "calendar"}))
 
-        [:div.flashcards-nav
-         (flashcards srs-open?)]
+        (when (state/enable-flashcards? (state/get-current-repo))
+          [:div.flashcards-nav
+           (flashcards srs-open?)])
 
         (sidebar-item
           {:class  "graph-view-nav"
@@ -333,7 +334,7 @@
 
       (when show-action-bar?
         (action-bar/action-bar))
-      
+
       [:div.cp__sidebar-main-content
        {:data-is-global-graph-pages global-graph-pages?
         :data-is-full-width         (or global-graph-pages?
@@ -344,11 +345,11 @@
 
        (mobile-bar)
        (footer/footer)
-       
+
        (when (and (not (mobile-util/native-platform?))
                   (contains? #{:page :home} route-name))
          (widgets/demo-graph-alert))
-       
+
        (cond
          (not indexeddb-support?)
          nil

+ 5 - 4
src/main/frontend/dicts.cljc

@@ -183,6 +183,7 @@
         :settings-page/tab-version-control "Version control"
         :settings-page/tab-advanced "Advanced"
         :settings-page/plugin-system "Plug-in system"
+        :settings-page/enable-flashcards "Flashcards"
         :settings-page/network-proxy "Network proxy"
         :logseq "Logseq"
         :on "ON"
@@ -1886,7 +1887,7 @@
            :settings-page/edit-export-css "Rediger export.css"
            :settings-page/network-proxy "Nettverksproxy"
            :settings-page/plugin-system "System for utvidelser"}
-   
+
    :pt-BR {:on-boarding/demo-graph "Esse é um gráfico de demonstração, mudanças não serão salvas enquanto uma pasta local não for aberta."
            :on-boarding/add-graph "Adicionar gráfico"
            :on-boarding/open-local-dir "Abrir pasta local"
@@ -2198,7 +2199,7 @@
 
            :file-sync/other-user-graph "O gráfico local atual é obrigado ao gráfico remoto de outro usuário. Portanto, não consigo iniciar a sincronização."
            :file-sync/graph-deleted "O gráfico remoto atual foi excluído"
-           
+
            :page/copy-page-url "Copiar URL da página"
            :page/file-sync-versions "Versões da página"
            :plugin/not-installed "Não instalado"
@@ -3750,7 +3751,7 @@
 
         :file-sync/other-user-graph "Geçerli yerel grafik, diğer kullanıcının uzak grafiğine bağlıdır. Bu yüzden senkronizasyon başlatılamıyor."
         :file-sync/graph-deleted "Geçerli uzak grafik silindi"}
-   
+
    :ko {:tutorial/text #?(:cljs (rc/inline "tutorial-ko.md")
                           :default "tutorial-ko.md")
         :tutorial/dummy-notes #?(:cljs (rc/inline "dummy-notes-ko.md")
@@ -4077,7 +4078,7 @@
         :file-sync/other-user-graph "현재 로컬 그래프가 다른 유저의 리모트 그래프와 충돌합니다. 동기화를 시작할 수 없습니다."
         :file-sync/graph-deleted "현재 리모트 그래프를 삭제했습니다."
         }
-     
+
      :tongue/fallback :en})
 
 (def languages [{:label "English" :value :en}

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

@@ -367,7 +367,12 @@
 (defn enable-journals?
   [repo]
   (not (false? (:feature/enable-journals?
-                 (get (sub-config) repo)))))
+                (get (sub-config) repo)))))
+
+(defn enable-flashcards?
+  [repo]
+  (not (false? (:feature/enable-flashcards?
+                (get (sub-config) repo)))))
 
 (defn export-heading-to-list?
   []