Browse Source

feat(publishing): add publishing list and delete operation

defclass 5 years ago
parent
commit
437b31b3fc

+ 6 - 0
src/main/frontend/components/header.cljs

@@ -74,6 +74,12 @@
          {:title (t :all-journals)
           :options {:href (rfe/href :all-journals)}
           :icon svg/calendar-sm})
+       (when current-repo
+         {:title (t :my-publishing)
+          :options {:href (rfe/href :my-publishing)}})
+       {: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}

+ 79 - 0
src/main/frontend/components/publishing.cljs

@@ -0,0 +1,79 @@
+(ns frontend.components.publishing
+  (:require [rum.core :as rum]
+            [frontend.context.i18n :as i18n]
+            [frontend.db :as db]
+            [frontend.state :as state]
+            [frontend.util :as util]
+            [reitit.frontend.easy :as rfe]
+            [frontend.db-mixins :as db-mixins]
+            [frontend.config :as config]
+            [lambdaisland.glogi :as log]
+            [promesa.core :as p]
+            [frontend.handler.page :as page-handler]))
+
+
+(defn get-published-pages
+  []
+  (when-let [repo (state/get-current-repo)]
+    (when (db/get-conn repo)
+      (->> (db/q repo [:page/published] {:use-cache? false}
+             '[:find (pull ?page [*])
+               :in $
+               :where
+               [?page :page/properties ?properties]
+               [(get ?properties :published) ?publish]
+               [(= "true" ?publish)]])
+        db/react))))
+
+
+(defn delete-page-from-logseq
+  [project permalink]
+  (let [url (util/format "%s%s/%s" config/api project permalink)]
+    (js/Promise.
+      (fn [resolve reject]
+       (util/delete url
+         (fn [result]
+           (resolve result))
+         (fn [error]
+           (log/error :publish/delete-page-failed error)
+           (reject error)))))))
+
+(rum/defc my-publishing
+  < rum/reactive db-mixins/query
+  []
+  (let [current-repo (state/sub :git/current-repo)
+        current-project (state/get-current-project)
+        pages (get-published-pages)]
+    (rum/with-context [[t] i18n/*tongue-context*]
+      [:div.flex-1
+       [:h1.title (t :my-publishing)]
+       (when current-repo
+         [:table.table-auto
+          [:thead
+           [:tr
+            [:th (t :page/name)]
+            [:th (t :page/cancel-publishing)]]]
+          [:tbody
+           (for [page pages]
+             (let [page (first page)
+                   {:keys [title permalink]} (:page/properties page)
+                   page-name (:page/name page)]
+               (prn page)
+               [:tr {:key permalink}
+                [:td [:a {:on-click (fn [e]
+                                      (util/stop e))
+                          :href (rfe/href :page {:name title})}
+                      page-name]]
+                [:td [:span.text-gray-500.text-sm
+                      [:a {:on-click
+                           (fn [e]
+                             (util/stop e)
+                             (-> (p/let [_ (delete-page-from-logseq current-project permalink)]
+                                   (page-handler/page-add-properties! page-name {:published false}))
+                                 (p/catch
+                                   (fn [error]
+                                     (let [status (.-status error)
+                                           not-found-on-server 404]
+                                       (when (= not-found-on-server status)
+                                         (page-handler/page-add-properties! page-name {:published false})))))))}
+                       (t :page/cancel-publishing)]]]]))]])])))

+ 16 - 1
src/main/frontend/db.cljs

@@ -309,7 +309,8 @@
                               blocks)
 
                              (when pre-block?
-                               [[:contents]])
+                               [[:contents]
+                                [:page/published]])
 
                              ;; affected priority
                              (when current-priority
@@ -785,6 +786,20 @@
            (map :page/name)
            distinct))))
 
+(defn get-published-pages
+  []
+  (when-let [repo (state/get-current-repo)]
+    (when (get-conn repo)
+      (->> (q repo [:page/published] {}
+             '[:find (pull ?page [*])
+               :in $
+               :where
+               [?page :page/properties ?properties]
+               [(get ?properties :published) ?publish]
+               [(= "true" ?publish)]])
+        react
+        first))))
+
 (defn get-files
   [repo]
   (when-let [conn (get-conn repo)]

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

@@ -235,6 +235,7 @@ title: How to take dummy notes?
         :page/make-private "Make it private"
         :page/delete "Delete page (will delete the file too)"
         :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"
         :page/unpublish "Un-publish this page on Logseq"
         :page/add-to-contents "Add to Contents"
@@ -307,6 +308,7 @@ title: How to take dummy notes?
         :all-pages "All pages"
         :all-files "All files"
         :all-journals "All journals"
+        :my-publishing "My publishing"
         :settings "Settings"
         :import "Import"
         :join-community "Join the community"
@@ -439,6 +441,7 @@ title: How to take dummy notes?
         :page/make-private "Rendre la page privée"
         :page/delete "Supprimer la page (supprime le fichier)"
         :page/publish "Publier cette page sur Logseq"
+        :page/cancel-publishing "Cancel publishing on Logseq"
         :page/publish-as-slide "Publier cette page en présentation sur Logseq"
         :page/unpublish "Dépublier cette page de Logseq"
         :page/add-to-contents "Ajouter au Contenu"
@@ -509,6 +512,7 @@ title: How to take dummy notes?
         :all-pages "Toutes les pages"
         :all-files "Tous les fichiers"
         :all-journals "Tous les journaux"
+        :my-publishing "My publishing"
         :settings "Préférences"
         :import "Importer"
         :join-community "Rejoindre la communauté"
@@ -686,6 +690,7 @@ title: How to take dummy notes?
            :page/make-private "导出 HTML 时取消发布本页面"
            :page/delete "删除本页(并删除文件)"
            :page/publish "将本页发布至 Logseq"
+           :page/cancel-publishing "撤回本页在 Logseq 上的发布"
            :page/publish-as-slide "将本页作为幻灯片发布至 Logseq"
            :page/unpublish "取消将本页发布至 Logseq"
            :page/add-to-contents "将本页添加到目录"
@@ -757,6 +762,7 @@ title: How to take dummy notes?
            :all-repos "所有库"
            :all-pages "所有页面"
            :all-files "所有文件"
+           :my-publishing "我的发布"
            :settings "设置"
            :import "导入"
            :join-community "加入社区"
@@ -935,6 +941,7 @@ title: How to take dummy notes?
              :page/make-private "導出 HTML 時取消發布本頁面"
              :page/delete "刪除本頁(並刪除文件)"
              :page/publish "將本頁發布至 Logseq"
+             :page/cancel-publishing "Cancel publishing on Logseq"
              :page/publish-as-slide "將本頁作為幻燈片發布至 Logseq"
              :page/unpublish "取消將本頁發布至 Logseq"
              :page/add-to-contents "將本頁添加到目錄"
@@ -1002,6 +1009,7 @@ title: How to take dummy notes?
              :all-repos "所有庫"
              :all-pages "所有頁面"
              :all-files "所有文件"
+             :my-publishing "My publishing"
              :settings "設置"
              :import "導入"
              :join-community "加入社區"
@@ -1175,6 +1183,7 @@ title: How to take dummy notes?
         :page/rename "Hernoem die bladsy"
         :page/delete "Delete page (will delete the file too)"
         :page/publish "Publiseer hierdie blad op Logseq"
+        :page/cancel-publishing "Cancel publishing on Logseq"
         :page/publish-as-slide "Publiseer hierdie blad as 'n skyfie op Logseq"
         :page/unpublish "Verwyder blad publikasie op Logseq"
         :page/add-to-contents "Voeg by inhoud"

+ 7 - 2
src/main/frontend/routes.cljs

@@ -7,7 +7,8 @@
             [frontend.components.draw :as draw]
             [frontend.components.journal :as journal]
             [frontend.components.settings :as settings]
-            [frontend.components.external :as external]))
+            [frontend.components.external :as external]
+            [frontend.components.publishing :as publishing]))
 
 (def routes
   [["/"
@@ -64,4 +65,8 @@
 
    ["/all-journals"
     {:name :all-journals
-     :view journal/all-journals}]])
+     :view journal/all-journals}]
+
+   ["/my-publishing"
+    {:name :my-publishing
+     :view publishing/my-publishing}]])