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

enhance(ux): add graphs tab

move settings to sheet
Tienson Qin 3 недель назад
Родитель
Сommit
60689b25fa

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

@@ -228,11 +228,12 @@
        [:h1.title (t :graph/all-graphs)])
 
      [:div.pl-1.content.mt-8
-      [:div.flex.flex-row.my-8
-       [:div.mr-8
-        (ui/button
-         "Create a new graph"
-         :on-click #(state/pub-event! [:graph/new-db-graph]))]]
+      (when-not (util/mobile?)
+        [:div.flex.flex-row.my-8
+         [:div.mr-8
+          (ui/button
+           "Create a new graph"
+           :on-click #(state/pub-event! [:graph/new-db-graph]))]])
 
       [:div
        [:h2.text-lg.font-medium.mb-4 (t :graph/local-graphs)]

+ 2 - 2
src/main/mobile/bottom_tabs.cljs

@@ -119,6 +119,6 @@
   []
   (configure-tabs
    [{:id "home"       :title "Home"       :systemImage "house" :role "normal"}
-    {:id "favorites"  :title "Favorites"  :systemImage "star"  :role "normal"}
+    {:id "graphs"     :title "Graphs"     :systemImage "app.background.dotted"  :role "normal"}
     {:id "capture"    :title "Capture"    :systemImage "tray"  :role "normal"}
-    {:id "settings"   :title "Settings"   :systemImage "gear"  :role "normal"}]))
+    {:id "favorites"  :title "Favorites"  :systemImage "star"  :role "normal"}]))

+ 2 - 2
src/main/mobile/components/app.cljs

@@ -16,11 +16,11 @@
             [mobile.bottom-tabs :as bottom-tabs]
             [mobile.components.editor-toolbar :as editor-toolbar]
             [mobile.components.favorites :as favorites]
+            [mobile.components.graphs :as graphs]
             [mobile.components.header :as mobile-header]
             [mobile.components.popup :as popup]
             [mobile.components.search :as search]
             [mobile.components.selection-toolbar :as selection-toolbar]
-            [mobile.components.settings :as settings]
             [mobile.components.ui :as ui-component]
             [mobile.state :as mobile-state]
             [rum.core :as rum]))
@@ -90,7 +90,7 @@
   (let [tab' (keyword tab)]
     [:div#main-content-container.px-5.ls-layer
      (case tab'
-       :settings (settings/page)
+       :graphs (graphs/page)
        (if view
          (view route-match)
          (case tab'

+ 4 - 0
src/main/mobile/components/app.css

@@ -321,3 +321,7 @@ div[data-radix-menu-content] {
 .ls-nlp-calendar {
     @apply flex-1;
 }
+
+.mobile-setting-item {
+    @apply rounded-2xl px-3 py-3 shadow-sm flex items-center justify-between bg-gray-03;
+}

+ 10 - 0
src/main/mobile/components/graphs.cljs

@@ -0,0 +1,10 @@
+(ns mobile.components.graphs
+  "Mobile graphs"
+  (:require [frontend.components.repo :as repo]
+            [rum.core :as rum]))
+
+(rum/defc page < rum/reactive
+  []
+  [:div.app-index-graphs
+   [:div.mt-8
+    (repo/repos-cp)]])

+ 11 - 84
src/main/mobile/components/header.cljs

@@ -2,7 +2,6 @@
   "App top header"
   (:require ["@capacitor/dialog" :refer [Dialog]]
             [clojure.string :as string]
-            [frontend.common.missionary :as c.m]
             [frontend.components.repo :as repo]
             [frontend.components.rtc.indicator :as rtc-indicator]
             [frontend.date :as date]
@@ -17,7 +16,6 @@
             [frontend.mobile.util :as mobile-util]
             [frontend.state :as state]
             [frontend.ui :as ui]
-            [frontend.util :as util]
             [goog.date :as gdate]
             [logseq.common.util :as common-util]
             [logseq.db :as ldb]
@@ -25,8 +23,8 @@
             [logseq.shui.hooks :as hooks]
             [logseq.shui.ui :as shui]
             [missionary.core :as m]
+            [mobile.components.settings :as mobile-settings]
             [mobile.components.ui :as ui-component]
-            [mobile.state :as mobile-state]
             [promesa.core :as p]
             [rum.core :as rum]))
 
@@ -42,86 +40,11 @@
     (-> (.showDatePicker mobile-util/ui-local)
         (p/then (fn [^js e] (some-> e (.-value) (apply-date!)))))))
 
-(rum/defc log
-  []
-  (let [[error-only? set-error-only!] (hooks/use-state false)
-        [reversed? set-reversed!] (hooks/use-state false)
-        [show-worker-log? set-show-worker-log!] (hooks/use-state false)
-        [worker-records set-worker-records!] (hooks/use-state [])]
-    (hooks/use-effect!
-     #(c.m/run-task*
-       (m/sp
-         (set-worker-records! (c.m/<? (state/<invoke-db-worker :thread-api/mobile-logs)))))
-     [])
-    [:div.flex.flex-col.gap-1.p-2.ls-debug-log
-     [:div.flex.flex-row.justify-between
-      [:div.text-lg.font-medium.mb-2 "Full log: "]
-
-      (shui/button
-       {:variant :ghost
-        :size :sm
-        :on-click (fn []
-                    (util/copy-to-clipboard! (str (string/join "\n\n" @mobile-state/*log)
-                                                  "\n\n================================================================\n\n"
-                                                  (string/join "\n\n" worker-records))))}
-       "Copy")]
-
-     [:div.flex.flex-row.gap-2
-      (shui/button
-       {:size :sm
-        :on-click (fn []
-                    (set-error-only! (not error-only?)))}
-       (if error-only?
-         "All"
-         "Errors only"))
-
-      (shui/button
-       {:size :sm
-        :on-click (fn []
-                    (set-reversed! (not reversed?)))}
-       (if reversed?
-         "New record first"
-         "Old record first"))
-
-      (shui/button
-       {:size :sm
-        :on-click (fn []
-                    (set-show-worker-log! (not show-worker-log?)))}
-       (if show-worker-log?
-         "UI logs"
-         "worker logs"))]
-
-     (let [records (cond->> (if show-worker-log? worker-records @mobile-state/*log)
-                     error-only?
-                     (filter (fn [record] (contains? #{:error :severe} (:level record))))
-                     reversed?
-                     reverse)]
-       [:ul
-        (for [record records]
-          [:li (str (:level record) " " (:message record))])])]))
-
 (defn- open-settings-actions! []
   (ui-component/open-popup!
    (fn []
-     [:div
-      (when (user-handler/logged-in?)
-        (ui/menu-link {:on-click #(p/do!
-                                   (user-handler/logout)
-                                   (shui/popup-hide!))}
-                      [:span.text-lg.flex.gap-2.items-center.text-red-700
-                       (shui/tabler-icon "logout" {:class "opacity-80" :size 22})
-                       "Logout"]))
-      (ui/menu-link {:on-click #(js/window.open "https://github.com/logseq/db-test/issues")}
-                    [:span.text-lg.flex.gap-2.items-center
-                     (shui/tabler-icon "bug" {:class "opacity-70" :size 22})
-                     "Report bug"])
-      (ui/menu-link {:on-click (fn []
-                                 (shui/popup-show! nil (fn [] (log)) {}))}
-                    [:span.text-lg.flex.gap-2.items-center
-                     (shui/tabler-icon "square-letter-l" {:class "opacity-70" :size 22})
-                     "Check log"])])
-   {:title "Actions"
-    :default-height false}))
+     (mobile-settings/page))
+   {}))
 
 (defn open-page-settings
   [block]
@@ -178,7 +101,8 @@
                     (case (.-id e)
                       "title" (open-graph-switcher!)
                       "calendar" (open-journal-calendar!)
-                      "settings-actions" (open-settings-actions!)
+                      "add-graph" (state/pub-event! [:graph/new-db-graph])
+                      "home-setting" (open-settings-actions!)
                       "sync" (shui/popup-show! nil
                                                (rtc-indicator/details)
                                                {})
@@ -210,11 +134,13 @@
           base {:title title
                 :hidden (boolean hidden?)}
           page? (= route-name :page)
+          left-buttons (when (and (= tab "home") (nil? route-view))
+                         [(conj {:id "calendar" :systemIcon "calendar"})])
           right-buttons (cond
                           (= tab "home")
                           (cond-> []
                             (nil? route-view)
-                            (conj {:id "calendar" :systemIcon "calendar"})
+                            (conj {:id "home-setting" :systemIcon "ellipsis"})
                             (and rtc-indicator? (not page?))
                             (conj {:id "sync" :systemIcon "circle.fill" :color sync-color
                                    :size "small"})
@@ -222,11 +148,12 @@
                             (into [{:id "page-setting" :systemIcon "ellipsis"}
                                    {:id "favorite" :systemIcon (if favorited? "star.fill" "star")}]))
 
-                          (= tab "settings")
-                          [{:id "settings-actions" :systemIcon "ellipsis"}]
+                          (= tab "graphs")
+                          [{:id "add-graph" :systemIcon "plus"}]
 
                           :else nil)
           header (cond-> base
+                   left-buttons (assoc :leftButtons left-buttons)
                    right-buttons (assoc :rightButtons right-buttons)
                    (and (= tab "home") (not route-view)) (assoc :titleClickable true))]
       (.configure ^js mobile-util/native-top-bar

+ 146 - 18
src/main/mobile/components/settings.cljs

@@ -1,34 +1,162 @@
 (ns mobile.components.settings
   "Mobile settings"
-  (:require [frontend.components.repo :as repo]
+  (:require [clojure.string :as string]
+            [frontend.common.missionary :as c.m]
             [frontend.components.user.login :as login]
+            [frontend.config :as config]
             [frontend.handler.user :as user-handler]
             [frontend.state :as state]
+            [frontend.ui :as ui]
+            [frontend.util :as util]
+            [frontend.version :as version]
+            [logseq.shui.hooks :as hooks]
             [logseq.shui.ui :as shui]
+            [missionary.core :as m]
+            [mobile.state :as mobile-state]
+            [promesa.core :as p]
             [rum.core :as rum]))
 
 (rum/defc user-profile
   [login?]
-  (if-not login?
-    (shui/button
-     {:variant :default
-      :class "text-1xl flex flex-1 w-full my-8"
-      :on-click #(shui/dialog-open! login/page-impl
-                                    {:close-btn? false
-                                     :label "user-login"
-                                     :align :top
-                                     :content-props {:class "app-login-modal"}})}
-     "Login")
-    [:div.py-2
-     [:h2.py-3.flex.justify-between.items-center
-      [:strong.text-4xl.font-semibold (user-handler/username)]]
-     [:div.text-sm.text-muted-foreground.px-1 (user-handler/email)]]))
+  (let [username (user-handler/username)
+        email (user-handler/email)
+        initial  (or (some-> username (subs 0 1) string/upper-case) "?")]
+    [:div.pt-4
+     (if-not login?
+       (shui/button
+        {:variant :default
+         :class "text-1xl flex flex-1 w-full my-8"
+         :on-click #(shui/dialog-open! login/page-impl
+                                       {:close-btn? false
+                                        :label "user-login"
+                                        :align :top
+                                        :content-props {:class "app-login-modal"}})}
+        "Login")
+       ;; Logged in: account cell
+       [:div.mobile-setting-item
+        [:div.flex.items-center.gap-3
+         [:div.w-10.h-10.rounded-full.flex.items-center.justify-center.text-base.font-semibold
+          initial]
+         [:div.flex.flex-col.items-start
+          [:span.text-base.font-semibold (or username "Account")]
+          [:span.text-xs email]]]])]))
+
+(defn theme-select
+  [{:keys [value on-change]}]
+  [:select
+   {:value     (name value)
+    :class     "text-sm bg-transparent rounded border-none focus:outline-none"
+    :on-change (fn [e]
+                 (let [new-value (keyword (.. e -target -value))]
+                   (on-change new-value)))}
+   [:option {:value "system"} "System"]
+   [:option {:value "light"}  "Light"]
+   [:option {:value "dark"}   "Dark"]])
+
+(rum/defc log
+  []
+  (let [[error-only? set-error-only!]       (hooks/use-state false)
+        [reversed? set-reversed!]           (hooks/use-state false)
+        [show-worker-log? set-show-worker-log!] (hooks/use-state false)
+        [worker-records set-worker-records!] (hooks/use-state [])]
+    (hooks/use-effect!
+     #(c.m/run-task*
+       (m/sp
+         (set-worker-records! (c.m/<? (state/<invoke-db-worker :thread-api/mobile-logs)))))
+     [])
+    [:div.flex.flex-col.gap-1.p-2.ls-debug-log
+     [:div.flex.flex-row.justify-between
+      [:div.text-lg.font-medium.mb-2 "Full log: "]
+
+      (shui/button
+       {:variant :ghost
+        :size :sm
+        :on-click (fn []
+                    (util/copy-to-clipboard! (str (string/join "\n\n" @mobile-state/*log)
+                                                  "\n\n================================================================\n\n"
+                                                  (string/join "\n\n" worker-records))))}
+       "Copy")]
+
+     [:div.flex.flex-row.gap-2
+      (shui/button
+       {:size :sm
+        :on-click (fn [] (set-error-only! (not error-only?)))}
+       (if error-only? "All" "Errors only"))
+
+      (shui/button
+       {:size :sm
+        :on-click (fn [] (set-reversed! (not reversed?)))}
+       (if reversed? "New record first" "Old record first"))
+
+      (shui/button
+       {:size :sm
+        :on-click (fn [] (set-show-worker-log! (not show-worker-log?)))}
+       (if show-worker-log? "UI logs" "worker logs"))]
+
+     (let [records (cond->> (if show-worker-log? worker-records @mobile-state/*log)
+                     error-only?
+                     (filter (fn [record] (contains? #{:error :severe} (:level record))))
+                     reversed?
+                     reverse)]
+       [:ul
+        (for [record records]
+          [:li (str (:level record) " " (:message record))])])]))
 
 (rum/defc page < rum/reactive
   []
   (let [login? (and (state/sub :auth/id-token)
                     (user-handler/logged-in?))]
-    [:div.app-index-settings
+    [:div.app-index-settings.min-h-full.py-4.space-y-4
      (user-profile login?)
-     [:div.mt-8
-      (repo/repos-cp)]]))
+     [:div.space-y-4
+      [:div.mobile-setting-item
+       [:span.text-base "Theme"]
+       [:div.flex.items-center
+        (theme-select {:value (state/sub :ui/theme)
+                       :on-change state/use-theme-mode!})]]
+
+      [:div.mobile-setting-item
+       [:span.text-base "Version"]
+       [:span.text-sm version/version]]
+
+      (let [revision (string/replace config/revision "-dirty" "")]
+        [:div.mobile-setting-item
+         {:on-click (fn []
+                      (js/window.open (str "https://github.com/logseq/logseq/commit/" revision)))}
+         [:span.text-base "Revision"]
+         [:span.text-sm revision]])
+
+      [:div.mobile-setting-item
+       {:on-click (fn []
+                    (js/window.open "https://github.com/logseq/db-test/issues"))}
+       [:span.text-base "Report bug"]]
+
+      [:div.mobile-setting-item
+       {:on-click (fn []
+                    (shui/popup-show! nil (fn [] (log)) {}))}
+       [:span.text-base "Check log"]]
+
+      (when login?
+        [:div.mobile-setting-item
+         {:on-click (fn []
+                      (p/do!
+                       (user-handler/logout)
+                       (shui/popup-hide!)))}
+         [:span.text-base "Logout"]])
+
+      [:div.flex.flex-row.flex-row.gap-4
+       [:a {:href "https://discord.com/invite/KpN4eHY"
+            :target "_blank"}
+        [:div.flex.items-center
+         (ui/icon "brand-discord")
+         [:span.ml-1 "Discord community"]]]
+       [:a {:href "https://discuss.logseq.com"
+            :target "_blank"}
+        [:div.flex.items-center
+         (ui/icon "message")
+         [:span.ml-1 "Forum"]]]
+       [:a {:href "https://github.com/logseq/logseq"
+            :target "_blank"}
+        [:div.flex.items-center
+         (ui/icon "brand-github")
+         [:span.ml-1 "GitHub"]]]]]]))