From b452b87b9ed61b0828797a065ca0b272698f3f30 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Tue, 29 Sep 2020 12:49:29 +0800 Subject: [PATCH] wip --- web/src/main/frontend/components/commit.cljs | 1 - web/src/main/frontend/components/content.cljs | 1 - web/src/main/frontend/components/diff.cljs | 1 - web/src/main/frontend/components/draw.cljs | 1 - web/src/main/frontend/components/editor.cljs | 1 - web/src/main/frontend/components/file.cljs | 1 - web/src/main/frontend/components/hiccup.cljs | 1 - web/src/main/frontend/components/journal.cljs | 4 +- web/src/main/frontend/components/page.cljs | 1 - web/src/main/frontend/components/project.cljs | 1 - .../main/frontend/components/reference.cljs | 1 - web/src/main/frontend/components/repo.cljs | 1 - .../frontend/components/right_sidebar.cljs | 1 - web/src/main/frontend/components/search.cljs | 1 - .../main/frontend/components/settings.cljs | 1 - web/src/main/frontend/components/sidebar.cljs | 1 - web/src/main/frontend/components/widgets.cljs | 1 - web/src/main/frontend/core.cljs | 1 - web/src/main/frontend/graph.cljs | 3 +- web/src/main/frontend/handler.cljs | 6 --- web/src/main/frontend/handler/dnd.cljs | 3 +- web/src/main/frontend/handler/page.cljs | 7 ++- web/src/main/frontend/keyboards.cljs | 3 +- web/src/main/frontend/publishing.cljs | 51 +++++++++++++++++++ 24 files changed, 62 insertions(+), 32 deletions(-) create mode 100644 web/src/main/frontend/publishing.cljs diff --git a/web/src/main/frontend/components/commit.cljs b/web/src/main/frontend/components/commit.cljs index 4555ddd42..e31ca70dd 100644 --- a/web/src/main/frontend/components/commit.cljs +++ b/web/src/main/frontend/components/commit.cljs @@ -1,7 +1,6 @@ (ns frontend.components.commit (:require [rum.core :as rum] [frontend.util :as util :refer-macros [profile]] - [frontend.handler :as handler] [frontend.handler.git :as git-handler] [frontend.handler.repo :as repo-handler] [frontend.state :as state] diff --git a/web/src/main/frontend/components/content.cljs b/web/src/main/frontend/components/content.cljs index 0fb17ab8f..0ae27622b 100644 --- a/web/src/main/frontend/components/content.cljs +++ b/web/src/main/frontend/components/content.cljs @@ -3,7 +3,6 @@ [frontend.db :as db] [frontend.format :as format] [frontend.format.protocol :as protocol] - [frontend.handler :as handler] [frontend.handler.editor :as editor-handler] [frontend.handler.export :as export-handler] [frontend.handler.image :as image-handler] diff --git a/web/src/main/frontend/components/diff.cljs b/web/src/main/frontend/components/diff.cljs index ef49de996..0cf8d3e21 100644 --- a/web/src/main/frontend/components/diff.cljs +++ b/web/src/main/frontend/components/diff.cljs @@ -2,7 +2,6 @@ (:require [rum.core :as rum] [frontend.util :as util] [frontend.config :as config] - [frontend.handler :as handler] [frontend.handler.git :as git-handler] [frontend.handler.file :as file] [frontend.handler.notification :as notification] diff --git a/web/src/main/frontend/components/draw.cljs b/web/src/main/frontend/components/draw.cljs index 75ba26538..ae4b6029a 100644 --- a/web/src/main/frontend/components/draw.cljs +++ b/web/src/main/frontend/components/draw.cljs @@ -11,7 +11,6 @@ [dommy.core :as d] [clojure.string :as string] [frontend.date :as date] - [frontend.handler :as handler] [frontend.handler.notification :as notification] [frontend.handler.draw :as draw :refer [*files diff --git a/web/src/main/frontend/components/editor.cljs b/web/src/main/frontend/components/editor.cljs index 8f79800c3..d96d12c29 100644 --- a/web/src/main/frontend/components/editor.cljs +++ b/web/src/main/frontend/components/editor.cljs @@ -2,7 +2,6 @@ (:require [rum.core :as rum] [frontend.components.svg :as svg] [frontend.config :as config] - [frontend.handler :as handler] [frontend.handler.editor :as editor-handler :refer [get-state]] [frontend.handler.image :as image-handler] [frontend.util :as util :refer-macros [profile]] diff --git a/web/src/main/frontend/components/file.cljs b/web/src/main/frontend/components/file.cljs index 05430f033..0141ec517 100644 --- a/web/src/main/frontend/components/file.cljs +++ b/web/src/main/frontend/components/file.cljs @@ -1,7 +1,6 @@ (ns frontend.components.file (:require [rum.core :as rum] [frontend.util :as util] - [frontend.handler :as handler] [frontend.handler.project :as project] [frontend.handler.ui :as ui-handler] [frontend.handler.image :as image-handler] diff --git a/web/src/main/frontend/components/hiccup.cljs b/web/src/main/frontend/components/hiccup.cljs index edc34887a..ecde6cd9f 100644 --- a/web/src/main/frontend/components/hiccup.cljs +++ b/web/src/main/frontend/components/hiccup.cljs @@ -17,7 +17,6 @@ [frontend.components.block :as block-comp] [frontend.ui :as ui] [frontend.components.widgets :as widgets] - [frontend.handler :as handler] [frontend.handler.ui :as ui-handler] [frontend.handler.image :as image-handler] [frontend.handler.editor :as editor-handler] diff --git a/web/src/main/frontend/components/journal.cljs b/web/src/main/frontend/components/journal.cljs index b09112904..a806b912c 100644 --- a/web/src/main/frontend/components/journal.cljs +++ b/web/src/main/frontend/components/journal.cljs @@ -2,9 +2,9 @@ (:require [rum.core :as rum] [frontend.util :as util :refer-macros [profile]] [frontend.date :as date] - [frontend.handler :as handler] [frontend.handler.notification :as notification] [frontend.handler.repo :as repo-handler] + [frontend.handler.page :as page-handler] [frontend.handler.editor :as editor] [frontend.handler.ui :as ui-handler] [frontend.db :as db] @@ -106,7 +106,7 @@ [:div.journal.content {:key journal-name} (journal-cp [journal-name format])]) {:on-load (fn [] - (handler/load-more-journals!))})]) + (page-handler/load-more-journals!))})]) (rum/defc all-journals < rum/reactive [] diff --git a/web/src/main/frontend/components/page.cljs b/web/src/main/frontend/components/page.cljs index e0ceff4d7..97d99af91 100644 --- a/web/src/main/frontend/components/page.cljs +++ b/web/src/main/frontend/components/page.cljs @@ -2,7 +2,6 @@ (:require [rum.core :as rum] [medley.core :as medley] [frontend.util :as util :refer-macros [profile]] - [frontend.handler :as handler] [frontend.handler.file :as file] [frontend.handler.page :as page-handler] [frontend.handler.ui :as ui-handler] diff --git a/web/src/main/frontend/components/project.cljs b/web/src/main/frontend/components/project.cljs index cccf5ff4c..87c23c970 100644 --- a/web/src/main/frontend/components/project.cljs +++ b/web/src/main/frontend/components/project.cljs @@ -1,7 +1,6 @@ (ns frontend.components.project (:require [rum.core :as rum] [frontend.util :as util :refer-macros [profile]] - [frontend.handler :as handler] [frontend.handler.project :as project-handler] [frontend.state :as state] [clojure.string :as string] diff --git a/web/src/main/frontend/components/reference.cljs b/web/src/main/frontend/components/reference.cljs index 86d401b79..d2e04bddd 100644 --- a/web/src/main/frontend/components/reference.cljs +++ b/web/src/main/frontend/components/reference.cljs @@ -1,7 +1,6 @@ (ns frontend.components.reference (:require [rum.core :as rum] [frontend.util :as util] - [frontend.handler :as handler] [frontend.state :as state] [clojure.string :as string] [frontend.db :as db] diff --git a/web/src/main/frontend/components/repo.cljs b/web/src/main/frontend/components/repo.cljs index f00e8a0c3..ab37203ff 100644 --- a/web/src/main/frontend/components/repo.cljs +++ b/web/src/main/frontend/components/repo.cljs @@ -4,7 +4,6 @@ [frontend.ui :as ui] [frontend.state :as state] [frontend.db :as db] - [frontend.handler :as handler] [frontend.handler.repo :as repo-handler] [frontend.handler.route :as route-handler] [frontend.handler.export :as export-handler] diff --git a/web/src/main/frontend/components/right_sidebar.cljs b/web/src/main/frontend/components/right_sidebar.cljs index 89fd7ef2f..058f9bd1f 100644 --- a/web/src/main/frontend/components/right_sidebar.cljs +++ b/web/src/main/frontend/components/right_sidebar.cljs @@ -7,7 +7,6 @@ [frontend.components.block :as block] [frontend.extensions.graph-2d :as graph-2d] [frontend.components.onboarding :as onboarding] - [frontend.handler :as handler] [frontend.handler.route :as route-handler] [frontend.handler.editor :as editor-handler] [frontend.handler.page :as page-handler] diff --git a/web/src/main/frontend/components/search.cljs b/web/src/main/frontend/components/search.cljs index f68b50f73..072d53462 100644 --- a/web/src/main/frontend/components/search.cljs +++ b/web/src/main/frontend/components/search.cljs @@ -1,7 +1,6 @@ (ns frontend.components.search (:require [rum.core :as rum] [frontend.util :as util] - [frontend.handler :as handler] [frontend.handler.route :as route] [frontend.handler.editor :as editor-handler] [frontend.handler.page :as page-handler] diff --git a/web/src/main/frontend/components/settings.cljs b/web/src/main/frontend/components/settings.cljs index 88ebbd990..211ff26be 100644 --- a/web/src/main/frontend/components/settings.cljs +++ b/web/src/main/frontend/components/settings.cljs @@ -1,7 +1,6 @@ (ns frontend.components.settings (:require [rum.core :as rum] [frontend.ui :as ui] - [frontend.handler :as handler] [frontend.handler.notification :as notification] [frontend.handler.user :as user-handler] [frontend.handler.ui :as ui-handler] diff --git a/web/src/main/frontend/components/sidebar.cljs b/web/src/main/frontend/components/sidebar.cljs index 9b234dd96..7d172f5a9 100644 --- a/web/src/main/frontend/components/sidebar.cljs +++ b/web/src/main/frontend/components/sidebar.cljs @@ -16,7 +16,6 @@ [goog.crypt.base64 :as b64] [frontend.util :as util] [frontend.state :as state] - [frontend.handler :as handler] [frontend.handler.notification :as notification] [frontend.handler.ui :as ui-handler] [frontend.handler.user :as user-handler] diff --git a/web/src/main/frontend/components/widgets.cljs b/web/src/main/frontend/components/widgets.cljs index e0437d2d0..2ab5ef198 100644 --- a/web/src/main/frontend/components/widgets.cljs +++ b/web/src/main/frontend/components/widgets.cljs @@ -1,7 +1,6 @@ (ns frontend.components.widgets (:require [rum.core :as rum] [frontend.util :as util] - [frontend.handler :as handler] [frontend.handler.user :as user-handler] [frontend.handler.git :as git-handler] [frontend.handler.repo :as repo-handler] diff --git a/web/src/main/frontend/core.cljs b/web/src/main/frontend/core.cljs index fe24f75d4..13fc5f9a2 100644 --- a/web/src/main/frontend/core.cljs +++ b/web/src/main/frontend/core.cljs @@ -6,7 +6,6 @@ [frontend.routes :as routes] [frontend.util :as util] [reitit.frontend :as rf] - [frontend.config :as config] [reitit.frontend.easy :as rfe])) (defn set-router! diff --git a/web/src/main/frontend/graph.cljs b/web/src/main/frontend/graph.cljs index 69c12a8dc..98f5b6890 100644 --- a/web/src/main/frontend/graph.cljs +++ b/web/src/main/frontend/graph.cljs @@ -1,6 +1,5 @@ (ns frontend.graph - (:require [frontend.handler :as handler] - [frontend.handler.ui :as ui-handler] + (:require [frontend.handler.ui :as ui-handler] [frontend.handler.route :as route-handler] [frontend.util :as util] [clojure.string :as string] diff --git a/web/src/main/frontend/handler.cljs b/web/src/main/frontend/handler.cljs index c585dac42..967f6b848 100644 --- a/web/src/main/frontend/handler.cljs +++ b/web/src/main/frontend/handler.cljs @@ -15,12 +15,6 @@ [frontend.history :as history] [frontend.ui :as ui])) -(defn load-more-journals! - [] - (let [current-length (:journals-length @state/state)] - (when (< current-length (db/get-journals-length)) - (state/update-state! :journals-length inc)))) - (defn- watch-for-date! [] (js/setInterval (fn [] diff --git a/web/src/main/frontend/handler/dnd.cljs b/web/src/main/frontend/handler/dnd.cljs index ba9a1cce3..bc61a868d 100644 --- a/web/src/main/frontend/handler/dnd.cljs +++ b/web/src/main/frontend/handler/dnd.cljs @@ -1,6 +1,5 @@ (ns frontend.handler.dnd - (:require [frontend.handler :as handler] - [frontend.handler.notification :as notification] + (:require [frontend.handler.notification :as notification] [frontend.handler.repo :as repo-handler] [frontend.config :as config] [frontend.util :as util :refer-macros [profile]] diff --git a/web/src/main/frontend/handler/page.cljs b/web/src/main/frontend/handler/page.cljs index a37babf10..aca3146d7 100644 --- a/web/src/main/frontend/handler/page.cljs +++ b/web/src/main/frontend/handler/page.cljs @@ -6,7 +6,6 @@ [frontend.util :as util :refer-macros [profile]] [frontend.tools.html-export :as html-export] [frontend.config :as config] - [frontend.handler :as handler] [frontend.handler.route :as route-handler] [frontend.handler.file :as file-handler] [frontend.handler.git :as git-handler] @@ -321,3 +320,9 @@ :with-level? true :new-level 2 :current-page "Contents"}))) + +(defn load-more-journals! + [] + (let [current-length (:journals-length @state/state)] + (when (< current-length (db/get-journals-length)) + (state/update-state! :journals-length inc)))) diff --git a/web/src/main/frontend/keyboards.cljs b/web/src/main/frontend/keyboards.cljs index a22f7c81c..83009ef50 100644 --- a/web/src/main/frontend/keyboards.cljs +++ b/web/src/main/frontend/keyboards.cljs @@ -1,6 +1,5 @@ (ns frontend.keyboards - (:require [frontend.handler :as handler] - [frontend.handler.editor :as editor-handler] + (:require [frontend.handler.editor :as editor-handler] [frontend.handler.history :as history-handler] [frontend.handler.ui :as ui-handler] [frontend.handler.route :as route-handler] diff --git a/web/src/main/frontend/publishing.cljs b/web/src/main/frontend/publishing.cljs new file mode 100644 index 000000000..c7e6346d5 --- /dev/null +++ b/web/src/main/frontend/publishing.cljs @@ -0,0 +1,51 @@ +(ns frontend.publishing + (:require [frontend.state :as state] + [datascript.core :as d] + [frontend.db :as db] + [frontend.db-schema :as db-schema] + [rum.core :as rum] + [frontend.handler.route :as route] + [frontend.page :as page] + [frontend.routes :as routes] + [frontend.util :as util] + [reitit.frontend :as rf] + [reitit.frontend.easy :as rfe])) + +;; The publishing site should be as thin as possible. +;; Both files and git libraries can be removed. +;; Maybe we can remove some handlers and components too. + +(defn restore-from-transit-str! + [] + (state/set-current-repo! "local") + (when-let [data js/window.logseq_db] + (let [db-conn (d/create-conn db-schema/schema) + _ (swap! db/conns assoc "local" db-conn) + db (string->db logseq_db)] + (reset! db-conn db)))) + +(defn set-router! + [] + (rfe/start! + (rf/router routes/routes {}) + route/set-route-match! + ;; set to false to enable HistoryAPI + {:use-fragment false})) + +(defn start [] + (when-let [node (.getElementById js/document "root")] + (set-router!) + (rum/mount (page/current-page) node))) + +(defn ^:export init [] + ;; init is called ONCE when the page loads + ;; this is called in the index.html and must be exported + ;; so it is available even in :advanced release builds + + (db/restore-from-transit-str!) + (start)) + +(defn stop [] + ;; stop is called before any code is reloaded + ;; this is controlled by :before-load in the config + (js/console.log "stop"))