Просмотр исходного кода

fix: only enable whiteboard for alpha testers

Peng Xiao 3 лет назад
Родитель
Сommit
0156eb0414

+ 18 - 16
src/main/frontend/components/settings.cljs

@@ -28,7 +28,8 @@
             [reitit.frontend.easy :as rfe]
             [rum.core :as rum]
             [frontend.mobile.util :as mobile-util]
-            [frontend.db :as db]))
+            [frontend.db :as db]
+            [frontend.handler.user :as user]))
 
 (defn toggle
   [label-for name state on-toggle & [detail-text]]
@@ -511,14 +512,6 @@
                  (config-handler/set-config! :feature/enable-flashcards? value)))
              true))
 
-(rum/defc whiteboards-enabled-switcher
-  [enable-whiteboards?]
-  (ui/toggle enable-whiteboards?
-             (fn []
-               (let [value (not enable-whiteboards?)]
-                 (config-handler/set-config! :feature/enable-whiteboards? value)))
-             true))
-
 (rum/defc user-proxy-settings
   [{:keys [protocol host port] :as agent-opts}]
   (ui/button [:span
@@ -539,11 +532,6 @@
    {:left-label (t :settings-page/enable-flashcards)
     :action (flashcards-enabled-switcher enable-flashcards?)}))
 
-(defn whiteboards-switcher-row [enable-whiteboards?]
-  (row-with-button-action
-   {:left-label (t :settings-page/enable-whiteboards)
-    :action (whiteboards-enabled-switcher enable-whiteboards?)}))
-
 (defn https-user-agent-row [agent-opts]
   (row-with-button-action
    {:left-label (t :settings-page/network-proxy)
@@ -645,6 +633,19 @@
    {:left-label (str (t :settings-page/sync) " 🔐")
     :action (sync-enabled-switcher enabled?)}))
 
+(rum/defc whiteboards-enabled-switcher
+  [enabled?]
+  (ui/toggle enabled?
+             (fn []
+               (let [value (not enabled?)]
+                 (config-handler/set-config! :feature/enable-whiteboards? value)))
+             true))
+
+(defn whiteboards-switcher-row [enabled?]
+  (row-with-button-action
+   {:left-label (t :settings-page/enable-whiteboards)
+    :action (whiteboards-enabled-switcher enabled?)}))
+
 (rum/defc settings-features < rum/reactive
   []
   (let [current-repo (state/get-current-repo)
@@ -672,13 +673,14 @@
      (flashcards-switcher-row enable-flashcards?)
      (zotero-settings-row)
      (encryption-row enable-encryption?)
-     (when (util/electron?) (whiteboards-switcher-row enable-whiteboards?))
 
      (when-not web-platform?
        [:div
         [:hr]
         [:h2.mb-4 "Alpha test (sponsors only)"]
-        (sync-switcher-row enable-sync?)])]))
+        [:div.flex.flex-col.gap-4
+         (sync-switcher-row enable-sync?)
+         (whiteboards-switcher-row enable-whiteboards?)]])]))
 
 (rum/defcs settings
   < (rum/local [:general :general] ::active)

+ 36 - 32
src/main/frontend/components/whiteboard.cljs

@@ -6,6 +6,7 @@
             [frontend.context.i18n :refer [t]]
             [frontend.db.model :as model]
             [frontend.handler.route :as route-handler]
+            [frontend.handler.user :as user-handler]
             [frontend.handler.whiteboard :as whiteboard-handler]
             [frontend.state :as state]
             [frontend.ui :as ui]
@@ -149,35 +150,37 @@
 
 (rum/defc whiteboard-dashboard
   []
-  (let [whiteboards (->> (model/get-all-whiteboards (state/get-current-repo))
-                         (sort-by :block/updated-at)
-                         reverse)
-        whiteboard-names (map :block/name whiteboards)
-        ref (rum/use-ref nil)
-        rect (use-component-size ref)
-        [container-width] (when rect [(.-width rect) (.-height rect)])
-        cols (cond (< container-width 600) 1
-                   (< container-width 900) 2
-                   (< container-width 1200) 3
-                   :else 4)
-        total-whiteboards (count whiteboards)
-        empty-cards (- (max (* (math/ceil (/ (inc total-whiteboards) cols)) cols) (* 2 cols))
-                       (inc total-whiteboards))]
-    [:<>
-     [:h1.title.select-none
-      "All whiteboards"
-      [:span.opacity-50
-       (str " · " total-whiteboards)]]
-     [:div
-      {:ref ref}
-      [:div.gap-8.grid.grid-rows-auto
-       {:style {:visibility (when (nil? container-width) "hidden")
-                :grid-template-columns (str "repeat(" cols ", minmax(0, 1fr))")}}
-       (dashboard-create-card)
-       (for [whiteboard-name whiteboard-names]
-         [:<> {:key whiteboard-name} (dashboard-preview-card whiteboard-name)])
-       (for [n (range empty-cards)]
-         [:div.dashboard-card.dashboard-bg-card {:key n}])]]]))
+  (if (user-handler/alpha-user?)
+    (let [whiteboards (->> (model/get-all-whiteboards (state/get-current-repo))
+                           (sort-by :block/updated-at)
+                           reverse)
+          whiteboard-names (map :block/name whiteboards)
+          ref (rum/use-ref nil)
+          rect (use-component-size ref)
+          [container-width] (when rect [(.-width rect) (.-height rect)])
+          cols (cond (< container-width 600) 1
+                     (< container-width 900) 2
+                     (< container-width 1200) 3
+                     :else 4)
+          total-whiteboards (count whiteboards)
+          empty-cards (- (max (* (math/ceil (/ (inc total-whiteboards) cols)) cols) (* 2 cols))
+                         (inc total-whiteboards))]
+      [:<>
+       [:h1.title.select-none
+        "All whiteboards"
+        [:span.opacity-50
+         (str " · " total-whiteboards)]]
+       [:div
+        {:ref ref}
+        [:div.gap-8.grid.grid-rows-auto
+         {:style {:visibility (when (nil? container-width) "hidden")
+                  :grid-template-columns (str "repeat(" cols ", minmax(0, 1fr))")}}
+         (dashboard-create-card)
+         (for [whiteboard-name whiteboard-names]
+           [:<> {:key whiteboard-name} (dashboard-preview-card whiteboard-name)])
+         (for [n (range empty-cards)]
+           [:div.dashboard-card.dashboard-bg-card {:key n}])]]])
+    [:div "This feature is not public available yet."]))
 
 (rum/defc whiteboard-page
   [name block-id]
@@ -209,6 +212,7 @@
 
 (rum/defc whiteboard-route
   [route-match]
-  (let [name (get-in route-match [:parameters :path :name])
-        {:keys [block-id]} (get-in route-match [:parameters :query])]
-    (whiteboard-page name block-id)))
+  (when (user-handler/alpha-user?)
+    (let [name (get-in route-match [:parameters :path :name])
+          {:keys [block-id]} (get-in route-match [:parameters :query])]
+      (whiteboard-page name block-id))))

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

@@ -548,6 +548,7 @@ Similar to re-frame subscriptions"
   ([repo]
    (and
     (util/electron?)
+    ((resolve 'frontend.handler.user/alpha-user?)) ;; using resolve to avoid circular dependency
     (not (false? (:feature/enable-whiteboards? (sub-config repo)))))))
 
 (defn export-heading-to-list?