From 5e0a39437ef0a0bf50bb6550da5f0a38553779ea Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 23 Apr 2020 15:44:29 +0800 Subject: [PATCH] Page wip --- web/src/main/frontend/components/hiccup.cljs | 3 +- web/src/main/frontend/components/journal.cljs | 5 ++- web/src/main/frontend/components/page.cljs | 35 +++++++++++++++++++ web/src/main/frontend/db.cljs | 17 ++------- web/src/main/frontend/routes.cljs | 5 +++ 5 files changed, 48 insertions(+), 17 deletions(-) create mode 100644 web/src/main/frontend/components/page.cljs diff --git a/web/src/main/frontend/components/hiccup.cljs b/web/src/main/frontend/components/hiccup.cljs index c145ca6db..dccef4da8 100644 --- a/web/src/main/frontend/components/hiccup.cljs +++ b/web/src/main/frontend/components/hiccup.cljs @@ -352,7 +352,8 @@ name]]) tags))) element (keyword (str "h" level)) - level-str (str (apply str (repeat level "*")) " ") + level-str [:a {:href (str "/page/" uuid)} + (str (apply str (repeat level "*")) " ")] heading-part (->elem element {:id anchor :uuid (str uuid)} diff --git a/web/src/main/frontend/components/journal.cljs b/web/src/main/frontend/components/journal.cljs index 7b3e413fe..3d2c81c86 100644 --- a/web/src/main/frontend/components/journal.cljs +++ b/web/src/main/frontend/components/journal.cljs @@ -19,7 +19,10 @@ hiccup (hiccup/->hiccup headings {:id page-id})] [:div.flex-1 [:h1.mb-2.font-medium.text-2xl {:style {:color "#161E2E"}} - (str "* " title)] + [:a {:href (str "/page/" (:heading/uuid (first headings)))} + "* "] + + title] (content/content page-id :org {:hiccup hiccup})])) diff --git a/web/src/main/frontend/components/page.cljs b/web/src/main/frontend/components/page.cljs new file mode 100644 index 000000000..8be43e4a2 --- /dev/null +++ b/web/src/main/frontend/components/page.cljs @@ -0,0 +1,35 @@ +(ns frontend.components.page + (: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] + [frontend.components.sidebar :as sidebar] + [frontend.components.hiccup :as hiccup] + [frontend.ui :as ui] + [frontend.format.org-mode :as org] + [frontend.format :as format] + [frontend.components.content :as content] + [frontend.config :as config] + [goog.crypt.base64 :as b64])) + +(defn- get-page-name + [state] + (let [route-match (first (:rum/args state))] + (get-in route-match [:parameters :path :name]))) + +;; A page is just a logical heading + +(rum/defcs page + [state] + (let [page-name (get-page-name state) + id (uuid page-name)] + (prn id) + (sidebar/sidebar + [:div "page"] + ;; (let [headings (db/get-file-by-concat-headings path) + ;; headings (db/with-dummy-heading headings) + ;; hiccup (hiccup/->hiccup headings {:id encoded-path})] + ;; (content/content encoded-path format {:hiccup hiccup})) + ))) diff --git a/web/src/main/frontend/db.cljs b/web/src/main/frontend/db.cljs index 613acb8e1..13c8900f8 100644 --- a/web/src/main/frontend/db.cljs +++ b/web/src/main/frontend/db.cljs @@ -57,6 +57,7 @@ :heading/tags {:db/valueType :db.type/ref :db/cardinality :db.cardinality/many :db/isComponent true} + ;; :heading/parent {:db/valueType :db.type/ref} ;; tag :tag/name {:db/unique :db.unique/identity} @@ -111,23 +112,9 @@ :meta :heading/meta :content :heading/content :page :heading/page + ;; :parent :heading/parent }) -;; (def schema -;; [{:db/ident {:db/unique :db.unique/identity}} - -;; ;; {:db/ident :heading/title -;; ;; :db/valueType :db.type/string -;; ;; :db/cardinality :db.cardinality/one} - -;; ;; {:db/ident :heading/parent-title -;; ;; :db/valueType :db.type/string -;; ;; :db/cardinality :db.cardinality/one} - -;; ;; TODO: timestamps, meta -;; ;; scheduled, deadline -;; ]) - (defn- safe-headings [headings] (mapv (fn [heading] diff --git a/web/src/main/frontend/routes.cljs b/web/src/main/frontend/routes.cljs index aa7baac07..8df856c1a 100644 --- a/web/src/main/frontend/routes.cljs +++ b/web/src/main/frontend/routes.cljs @@ -3,6 +3,7 @@ [frontend.components.sidebar :as sidebar] [frontend.components.repo :as repo] [frontend.components.file :as file] + [frontend.components.page :as page] [frontend.components.agenda :as agenda] [clojure.string :as string])) @@ -19,6 +20,10 @@ {:name :file :view file/file}] + ["/page/:name" + {:name :page + :view page/page}] + ["/agenda" {:name :agenda :view agenda/agenda}]