浏览代码

Merge remote-tracking branch 'origin/master' into feat/support-remove-image

charlie 4 年之前
父节点
当前提交
cdd9ab8950

+ 14 - 12
src/main/frontend/components/page.cljs

@@ -294,23 +294,25 @@
                                              (mapv (fn [{:keys [title options]}]
                                                      (when title
                                                        [:div.it
-                                                        {:on-click #(state/close-modal!)}
                                                         (apply (partial ui/button title) (flatten (seq options)))]))
-                                                   [{:title   (t :page/publish)
-                                                     :options {:on-click (fn []
-                                                                           (page-handler/publish-page! page-name project/add-project))}}
-                                                    {:title   (t :page/publish-as-slide)
-                                                     :options {:on-click (fn []
-                                                                           (page-handler/publish-page-as-slide! page-name project/add-project))}}
-                                                    (when published?
+                                                   [(if published?
                                                       {:title   (t :page/unpublish)
                                                        :options {:on-click (fn []
-                                                                             (page-handler/unpublish-page! page-name))}})
+                                                                             (page-handler/unpublish-page! page-name))}}
+                                                      {:title   (t :page/publish)
+                                                       :options {:on-click (fn []
+                                                                             (page-handler/publish-page! page-name project/add-project))}})
+                                                    (when-not published?
+                                                      {:title   (t :page/publish-as-slide)
+                                                      :options {:on-click (fn []
+                                                                            (page-handler/publish-page-as-slide! page-name project/add-project))}})
                                                     {:title   (t (if public? :page/make-private :page/make-public))
                                                      :options {:background (if public? "gray" "indigo")
-                                                               :on-click #(page-handler/update-public-attribute!
-                                                                           page-name
-                                                                           (if public? false true))}}])])))}}
+                                                               :on-click (fn []
+                                                                           (page-handler/update-public-attribute!
+                                                                            page-name
+                                                                            (if public? false true))
+                                                                           (state/close-modal!))}}])])))}}
                             (when developer-mode?
                               {:title "(Dev) Show page data"
                                :options {:on-click (fn []

+ 5 - 2
src/main/frontend/components/project.cljs

@@ -1,7 +1,9 @@
 (ns frontend.components.project
   (:require [rum.core :as rum]
             [frontend.util :as util :refer-macros [profile]]
-            [frontend.handler.project :as project-handler]))
+            [frontend.handler.project :as project-handler]
+            [frontend.handler.config :as config-handler]
+            [clojure.string :as string]))
 
 (rum/defcs add-project <
   (rum/local "" ::project)
@@ -40,7 +42,8 @@
          :on-click (fn []
                      (let [value @project]
                        (when (and value (>= (count value) 2))
-                         (project-handler/add-project! value))))}
+                         (project-handler/add-project! value
+                                                       config-handler/set-project!))))}
         "Submit"]]
       [:span.mt-3.flex.w-full.rounded-md.shadow-sm.sm:mt-0.sm:w-auto
        [:button.inline-flex.justify-center.w-full.rounded-md.border.border-gray-300.px-4.py-2.bg-white.text-base.leading-6.font-medium.text-gray-700.shadow-sm.hover:text-gray-500.focus:outline-none.focus:border-blue-300.focus:shadow-outline-blue.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5

+ 4 - 4
src/main/frontend/dicts.cljs

@@ -216,7 +216,7 @@ title: How to take dummy notes?
         :page/presentation-mode "Presentation mode (Powered by Reveal.js)"
         :page/edit-properties-placeholder "Click here to edit this page's properties"
         :page/delete-success "Page {1} was deleted successfully!"
-        :page/delete-confirmation "Are you sure you want to delete this page?"
+        :page/delete-confirmation "Are you sure you want to delete this page and its file?"
         :page/rename-to "Rename \"{1}\" to:"
         :page/priority "Priority \"{1}\""
         :page/re-index "Re-index this page"
@@ -225,7 +225,7 @@ title: How to take dummy notes?
         :page/action-publish "Publish"
         :page/make-public "Publish it when exporting to an html file"
         :page/make-private "Make it private"
-        :page/delete "Delete page (will delete the file too)"
+        :page/delete "Delete page"
         :page/publish "Publish this page on Logseq"
         :page/cancel-publishing "Cancel publishing on Logseq"
         :page/publish-as-slide "Publish this page as a slide on Logseq"
@@ -702,7 +702,7 @@ title: How to take dummy notes?
            :page/edit-properties-placeholder "点击这里编辑当前页面的属性 (标签,别名等)"
            :page/presentation-mode "演讲模式 (由 Reveal.js 驱动)"
            :page/delete-success "页面 {1} 删除成功!"
-           :page/delete-confirmation "您确定要删除此页面吗?"
+           :page/delete-confirmation "您确定要删除此页面和文件吗?"
            :page/rename-to "重命名 \"{1}\" 至:"
            :page/priority "优先级 \"{1}\""
            :page/re-index "对此页面重新建立索引"
@@ -711,7 +711,7 @@ title: How to take dummy notes?
            :page/action-publish "发布"
            :page/make-public "导出 HTML 时发布本页面"
            :page/make-private "导出 HTML 时取消发布本页面"
-           :page/delete "删除本页(并删除文件)"
+           :page/delete "删除本页"
            :page/publish "将本页发布至 Logseq"
            :page/cancel-publishing "撤回本页在 Logseq 上的发布"
            :page/publish-as-slide "将本页作为幻灯片发布至 Logseq"

+ 7 - 1
src/main/frontend/handler/config.cljs

@@ -3,7 +3,8 @@
             [frontend.handler.repo :as repo-handler]
             [borkdude.rewrite-edn :as rewrite]
             [frontend.config :as config]
-            [frontend.db :as db]))
+            [frontend.db :as db]
+            [clojure.string :as string]))
 
 (defn set-config!
   [k v]
@@ -25,3 +26,8 @@
 (defn toggle-ui-show-brackets! []
   (let [show-brackets? (state/show-brackets?)]
     (set-config! :ui/show-brackets? (not show-brackets?))))
+
+(defn set-project!
+  [project]
+  (when-not (string/blank? project)
+    (set-config! [:project :name] project)))

+ 20 - 15
src/main/frontend/handler/page.cljs

@@ -14,6 +14,7 @@
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.project :as project-handler]
             [frontend.handler.notification :as notification]
+            [frontend.handler.config :as config-handler]
             [frontend.handler.ui :as ui-handler]
             [frontend.commands :as commands]
             [frontend.date :as date]
@@ -171,6 +172,7 @@
   ([page-name blocks project-add-modal]
    (project-handler/exists-or-create!
     (fn [project]
+      (config-handler/set-config! [:project :name] project)
       (page-add-properties! page-name {"published" true
                                        "slide" true})
       (let [properties (db/get-page-properties page-name)
@@ -202,26 +204,29 @@
                         (= "true" slide)))
            blocks (db/get-page-blocks page-name)
            plugins (get-plugins blocks)]
-       (if slide?
-         (publish-page-as-slide! page-name blocks project-add-modal)
-         (do
-           (page-add-properties! page-name {"published" true})
-           (let [data {:project project
-                       :title page-name
-                       :permalink (:permalink properties)
-                       :html (html-export/export-page page-name blocks notification/show!)
-                       :tags (:tags properties)
-                       :settings (merge properties plugins)
-                       :repo (state/get-current-repo)}]
-             (util/post (str config/api "pages")
-                        data
-                        (published-success-handler page-name)
-                        published-failed-handler))))))
+       (p/let [_ (config-handler/set-config! [:project :name] project)]
+         (if slide?
+           (publish-page-as-slide! page-name blocks project-add-modal)
+           (do
+             (page-add-properties! page-name {"published" true})
+             (let [data {:project project
+                         :title page-name
+                         :permalink (:permalink properties)
+                         :html (html-export/export-page page-name blocks notification/show!)
+                         :tags (:tags properties)
+                         :settings (merge properties plugins)
+                         :repo (state/get-current-repo)}]
+               (util/post (str config/api "pages")
+                          data
+                          (published-success-handler page-name)
+                          published-failed-handler))))
+         (state/close-modal!))))
    project-add-modal))
 
 (defn unpublished-success-handler
   [page-name]
   (fn [result]
+    (state/close-modal!)
     (notification/show!
      "Un-publish successfully!"
      :success)))

+ 5 - 3
src/main/frontend/handler/project.cljs

@@ -40,6 +40,7 @@
                              update-in [:me :projects]
                              (fn [projects]
                                (util/distinct-by :name (conj projects (:result result)))))
+                      ;; update config
                       (ok-handler project)))
                   (fn [error]
                     (js/console.dir error)
@@ -55,10 +56,11 @@
       (state/set-modal! modal-content))))
 
 (defn add-project!
-  [project]
+  [project ok-handler]
   (when (state/logged?)
     (create-project! project
-                     (fn []
+                     (fn [project]
+                       (when ok-handler (ok-handler project))
                        (notification/show! (util/format "Project \"%s\" was created successfully." project) :success)
                        (state/close-modal!)))))
 
@@ -83,7 +85,7 @@
          (when (and settings
                     (not (string/blank? (:name settings)))
                     (>= (count (string/trim (:name settings))) 2))
-           (add-project! (:name settings))))))))
+           (add-project! (:name settings) nil)))))))
 
 (defn update-project
   [project-name data]

+ 3 - 5
src/main/frontend/state.cljs

@@ -820,11 +820,9 @@
 
 (defn get-current-project
   []
-  (when-let [repo (get-current-repo)]
-    (let [projects (:projects (get-me))
-          project (:name (first (filter (fn [p] (= (:repo p) repo)) projects)))]
-      (when-not (string/blank? project)
-        project))))
+  (when-let [project (get-in (get-config) [:project :name])]
+    (when-not (string/blank? project)
+      project)))
 
 (defn update-current-project
   [& kv]

+ 1 - 1
src/main/frontend/version.cljs

@@ -1,3 +1,3 @@
 (ns frontend.version)
 
-(defonce version "0.0.5.1-1")
+(defonce version "0.0.5.1-3")