Browse Source

feat(chrome native ui): better ui

Tienson Qin 5 years ago
parent
commit
9d9ce7f76a

+ 62 - 66
src/main/frontend/components/header.cljs

@@ -58,11 +58,6 @@
          {:title (t :graph)
           :options {:href (rfe/href :graph)}
           :icon svg/graph-sm})
-       (when (and logged? current-repo)
-         {:title (t :publishing)
-          :options {:on-click (fn []
-                                (export/export-repo-as-html! current-repo))}
-          :icon nil})
        (when logged?
          {:title (t :all-repos)
           :options {:href (rfe/href :repos)}
@@ -79,12 +74,20 @@
          {:title (t :all-journals)
           :options {:href (rfe/href :all-journals)}
           :icon svg/calendar-sm})
-       {:title (t :excalidraw-title)
-        :options {:href (rfe/href :draw)}
-        :icon (svg/excalidraw-logo)}
        {:title (t :settings)
         :options {:href (rfe/href :settings)}
         :icon svg/settings-sm}
+       (when-let [project (and current-repo (state/get-current-project))]
+         (let [link (str config/website "/" project)]
+           {:title (str (t :go-to) "/" project)
+            :options {:href link
+                      :target "_blank"}
+            :icon svg/external-link}))
+       (when (and logged? current-repo)
+         {:title (t :export)
+          :options {:on-click (fn []
+                                (export/export-repo-as-html! current-repo))}
+          :icon nil})
        (when current-repo
          {:title (t :import)
           :options {:href (rfe/href :import)}
@@ -110,61 +113,54 @@
 
 (rum/defc header
   [{:keys [open-fn current-repo white? logged? page? route-match me default-home new-block-mode]}]
-  (rum/with-context [[t] i18n/*tongue-context*]
-    [:div.cp__header#head
-     (left-menu-button {:on-click (fn []
-                                    (open-fn)
-                                    (state/set-left-sidebar-open! true))})
-
-     (logo {:white? white?})
-
-     (if current-repo
-       (search/search)
-       [:div.flex-1])
-
-     (new-block-mode)
-
-     [:a.text-sm.font-medium.login.opacity-70.hover:opacity-100.mr-4
-      {:on-click (fn []
-                   (nfs/ls-dir-files))}
-      "Open a directory"]
-
-     (when (and (not logged?)
-                (not config/publishing?))
-       [:a.text-sm.font-medium.login.opacity-70.hover:opacity-100
-        {:href "/login/github"
-         :on-click (fn []
-                     (storage/remove :git/current-repo))}
-        (t :login-github)])
-
-     (repo/sync-status)
-
-     [:div.repos.hidden.md:block
-      (repo/repos-dropdown true)]
-
-     (when-let [project (and current-repo (state/get-current-project))]
-       [:a.opacity-70.hover:opacity-100.ml-4
-        {:title (str (t :go-to) "/" project)
-         :href (str config/website "/" project)
-         :target "_blank"}
-        svg/external-link])
-
-     (when (and page? current-repo (not config/mobile?))
-       (let [page (get-in route-match [:path-params :name])
-             page (string/lower-case (util/url-decode page))
-             page (db/entity [:page/name page])]
-         (page/presentation current-repo page (:journal? page))))
-
-     (if config/publishing?
-       [:a.text-sm.font-medium.ml-3 {:href (rfe/href :graph)}
-        (t :graph)]
-
-       (dropdown-menu {:me me
-                       :t t
-                       :current-repo current-repo
-                       :default-home default-home}))
-
-     [:a#download-as-html.hidden]
-     [:a#download-as-zip.hidden]
-
-     (right-menu-button)]))
+  (let [local-repo? (= current-repo config/local-repo)]
+    (rum/with-context [[t] i18n/*tongue-context*]
+      [:div.cp__header#head
+       (left-menu-button {:on-click (fn []
+                                      (open-fn)
+                                      (state/set-left-sidebar-open! true))})
+
+       (logo {:white? white?})
+
+       (if current-repo
+         (search/search)
+         [:div.flex-1])
+
+       (new-block-mode)
+
+       (when (and (not logged?)
+                  (not config/publishing?))
+         [:a.text-sm.font-medium.login.opacity-70.hover:opacity-100
+          {:href "/login/github"
+           :on-click (fn []
+                       (storage/remove :git/current-repo))}
+          (t :login-github)])
+
+       (repo/sync-status)
+
+       [:div.repos.hidden.md:block
+        (repo/repos-dropdown true)]
+
+       [:a.text-sm.font-medium.opacity-70.hover:opacity-100.ml-3
+        {:on-click (fn []
+                     (nfs/ls-dir-files))
+         :title (t :open-a-directory)}
+        [:div.flex.flex-row.text-center
+         [:span.inline-block svg/folder-add]
+         (when-not config/mobile?
+           [:span.ml-1 {:style {:margin-top 2}}
+            (t :open)])]]
+
+       (if config/publishing?
+         [:a.text-sm.font-medium.ml-3 {:href (rfe/href :graph)}
+          (t :graph)]
+
+         (dropdown-menu {:me me
+                         :t t
+                         :current-repo current-repo
+                         :default-home default-home}))
+
+       [:a#download-as-html.hidden]
+       [:a#download-as-zip.hidden]
+
+       (right-menu-button)])))

+ 13 - 9
src/main/frontend/components/page.cljs

@@ -87,16 +87,15 @@
       (page-blocks-cp repo contents file-path name original-name name true false false nil format))))
 
 (defn presentation
-  [repo page journal?]
-  [:a.opacity-50.hover:opacity-100.ml-4
+  [repo page]
+  [:a.opacity-50.hover:opacity-100
    {:title "Presentation mode (Powered by Reveal.js)"
     :on-click (fn []
                 (state/sidebar-add-block!
                  repo
                  (:db/id page)
                  :page-presentation
-                 {:page page
-                  :journal? journal?}))}
+                 {:page page}))}
    svg/slideshow])
 
 (rum/defc today-queries < rum/reactive
@@ -354,11 +353,16 @@
                          (not block?)
                          (not (state/hide-file?))
                          (not config/publishing?))
-                [:div.text-sm.ml-1.mb-4.flex-1 {:key "page-file"}
-                 [:span.opacity-50 (t :file/file)]
-                 [:a.bg-base-2.p-1.ml-1 {:style {:border-radius 4}
-                                         :href (str "/file/" (util/url-encode file-path))}
-                  file-path]])]
+                [:div.text-sm.ml-1.mb-4.flex-1.inline-flex
+                 {:key "page-file"}
+                 [:span.opacity-50 {:style {:margin-top 2}} (t :file/file)]
+                 [:a.bg-base-2.px-1.ml-1.mr-3 {:style {:border-radius 4}
+                                               :href (str "/file/" (util/url-encode file-path))}
+                  file-path]
+
+                 (when (and (not config/mobile?)
+                            (not journal?))
+                   (presentation repo page))])]
 
              (when (and repo (not block?))
                (let [alias (db/get-page-alias-names repo page-name)]

+ 14 - 4
src/main/frontend/components/svg.cljs

@@ -126,6 +126,17 @@
      :x1 "10.5"}]])
 
 (def graph-sm [:div {:style {:transform "rotate(90deg)"}} (hero-icon "M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z" {:height "16" :width "16"})])
+
+(def folder-add
+  [:svg
+   {:stroke "currentColor", :view-box "0 0 24 24", :fill "none" :width 24 :height 24 :display "inline-block"}
+   [:path
+    {:d
+     "M9 13h6m-3-3v6m-9 1V7a2 2 0 012-2h6l2 2h6a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z",
+     :stroke-width "2",
+     :stroke-linejoin "round",
+     :stroke-linecap "round"}]])
+
 (def folder (hero-icon "M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"))
 (def folder-sm (hero-icon "M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" {:height "16" :width "16"}))
 (def pages-sm [:svg {:viewbox "0 0 20 20", :fill "currentColor", :height "16", :width "16"}
@@ -331,10 +342,9 @@
 (def slideshow
   [:svg
    {:view-box "0 0 24 24"
-    :height 23
-    :width 23
-    :fill "currentColor"
-    :display "inline-block"}
+    :height 24
+    :width 24
+    :fill "currentColor"}
    [:path
     {:d "M10 8v8l5-4-5-4zm9-5H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14z"}]])
 

+ 9 - 8
src/main/frontend/dicts.cljs

@@ -301,6 +301,7 @@ title: How to take dummy notes?
         :new-file "New file"
         :graph "Graph"
         :publishing "Publishing"
+        :export "Export public pages"
         :all-repos "All repos"
         :all-pages "All pages"
         :all-files "All files"
@@ -316,7 +317,6 @@ title: How to take dummy notes?
         :parsing-files "Parsing files"
         :loading-files "Loading files"
         :login-github "Login with Github"
-        :excalidraw-title "Draw with Excalidraw"
         :go-to "Go to "
         :or "or"
         :download "Download"
@@ -324,7 +324,9 @@ title: How to take dummy notes?
         :language "Language"
         :white "Light"
         :dark "Dark"
-        :remove-background "Remove background"}
+        :remove-background "Remove background"
+        :open "Open"
+        :open-a-directory "Open a directory"}
 
    :fr {:help/about "A propos de Logseq"
         :help/bug "Signaler une anomalie"
@@ -517,7 +519,6 @@ title: How to take dummy notes?
         :parsing-files "Analyse des fichiers"
         :loading-files "Chargement des fichiers"
         :login-github "S'authentifier avec Github"
-        :excalidraw-title "Dessiner avec Excalidraw"
         :go-to "Aller à "
         :or "ou"
         :download "Télécharger"
@@ -749,7 +750,8 @@ title: How to take dummy notes?
            :new-page "新页面"
            :new-file "新文件"
            :graph "图谱"
-           :publishing "发布/下载 HTML 文件"
+           :publishing "发布"
+           :export "导出公开页面"
            :all-repos "所有库"
            :all-pages "所有页面"
            :all-files "所有文件"
@@ -764,7 +766,6 @@ title: How to take dummy notes?
            :parsing-files "正在解析文件"
            :loading-files "正在加载文件"
            :login-github "用 Github 登录"
-           :excalidraw-title "用 Excalidraw 画图"
            :go-to "转到"
            :or "或"
            :download "下载"
@@ -772,7 +773,9 @@ title: How to take dummy notes?
            :language "语言"
            :white "亮色"
            :dark "暗黑"
-           :remove-background "去除背景"}
+           :remove-background "去除背景"
+           :open "导入"
+           :open-a-directory "导入本地文件夹"}
 
    :zh-Hant {:on-boarding/title "你好,歡迎使用 Logseq!"
              :on-boarding/sharing "分享"
@@ -1008,7 +1011,6 @@ title: How to take dummy notes?
              :parsing-files "正在解析文件"
              :loading-files "正在加載文件"
              :login-github "用 Github 登錄"
-             :excalidraw-title "用 Excalidraw 畫圖"
              :go-to "轉到"
              :or "或"
              :download "下載"
@@ -1246,7 +1248,6 @@ title: How to take dummy notes?
         :parsing-files "Lêer ontleding"
         :loading-files "Laai lêers"
         :login-github "Aantekening deur Github"
-        :excalidraw-title "Teken met Excalidraw"
         :go-to "Gaan na "
         :or "of"
         :download "Laai af"

+ 6 - 6
src/main/frontend/handler/file.cljs

@@ -15,7 +15,8 @@
             [frontend.format :as format]
             [clojure.string :as string]
             [frontend.history :as history]
-            [frontend.handler.project :as project-handler]))
+            [frontend.handler.project :as project-handler]
+            [lambdaisland.glogi :as log]))
 
 (defn load-file
   [repo-url path]
@@ -103,13 +104,12 @@
 
                                         (seq images)
                                         (merge (zipmap images (repeat (count images) ""))))
-                        files-contents (for [[file content] file-contents]
-                                         {:file/path file
-                                          :file/content content})]
+                        file-contents (for [[file content] file-contents]
+                                        {:file/path file
+                                         :file/content content})]
                     (ok-handler file-contents))))
         (p/catch (fn [error]
-                   (println "load files failed: ")
-                   (js/console.dir error))))))
+                   (log/error :load-files-error error))))))
 
 (defn alter-file
   [repo path content {:keys [reset? re-render-root? add-history? update-status?]

+ 3 - 2
src/main/frontend/handler/repo.cljs

@@ -157,7 +157,7 @@
   (create-custom-theme repo-url))
 
 (defn- parse-files-and-load-to-db!
-  [repo-url files {:keys [first-clone? delete-files delete-blocks re-render? re-render-opts]}]
+  [repo-url files {:keys [first-clone? delete-files delete-blocks re-render? re-render-opts] :as opts}]
   (state/set-state! :repo/loading-files? false)
   (state/set-state! :repo/importing-to-db? true)
   (let [file-paths (map :file/path files)
@@ -187,7 +187,8 @@
                         (file-handler/load-files-contents!
                          repo-url
                          files
-                         (fn [files-contents] (parse-files-and-load-to-db! repo-url files-contents option))))]
+                         (fn [files-contents]
+                           (parse-files-and-load-to-db! repo-url files-contents option))))]
     (cond
       (and (not (seq diffs)) (seq nfs-files))
       (parse-files-and-load-to-db! repo-url nfs-files {:first-clone? true})