Skip to content

Commit

Permalink
fix: click contents page doesn't close the left bar
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Dec 2, 2020
1 parent ed2b68d commit 43e9257
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 42 deletions.
44 changes: 24 additions & 20 deletions src/main/frontend/components/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
[frontend.ui :as ui]
[frontend.handler.editor :as editor-handler]
[frontend.handler.dnd :as dnd]
[frontend.handler.ui :as ui-handler]
[frontend.handler.repeated :as repeated]
[goog.object :as gobj]
[medley.core :as medley]
Expand Down Expand Up @@ -239,7 +240,7 @@
(declare page-reference)

(defn page-cp
[{:keys [html-export? label children] :as config} page]
[{:keys [html-export? label children contents-page?] :as config} page]
(when-let [page-name (:page/name page)]
(let [original-page-name (get page :page/original-name page-name)
original-page-name (if (date/valid-journal-title? original-page-name)
Expand All @@ -259,7 +260,11 @@
(state/get-current-repo)
(:db/id page-entity)
:page
{:page page-entity}))))}
{:page page-entity})))
(when (and contents-page?
(state/get-left-sidebar-open?))
(ui-handler/close-left-sidebar!)))}

(if (seq children)
(for [child children]
(if (= (first child) "Label")
Expand All @@ -275,24 +280,23 @@

(defn page-reference
[html-export? s config label]
[:span.page-reference
(when (and (not html-export?)
(not (= (:id config) "contents"))
(not (= (:id config) "Contents")))
[:span.text-gray-500 "[["])
(if (string/ends-with? s ".excalidraw")
[:a.page-ref
{:href (rfe/href :draw nil {:file (string/replace s (str config/default-draw-directory "/") "")})
:on-click (fn [e] (util/stop e))}
[:span
(svg/excalidraw-logo)
(string/capitalize (draw/get-file-title s))]]
(page-cp (assoc config
:label (mldoc/plain->text label)) {:page/name s}))
(when (and (not html-export?)
(not (= (:id config) "contents"))
(not (= (:id config) "Contents")))
[:span.text-gray-500 "]]"])])
(let [contents-page? (= "contents" (string/lower-case (str (:id config))))]
[:span.page-reference
(when (and (not html-export?) (not contents-page?))
[:span.text-gray-500 "[["])
(if (string/ends-with? s ".excalidraw")
[:a.page-ref
{:href (rfe/href :draw nil {:file (string/replace s (str config/default-draw-directory "/") "")})
:on-click (fn [e]
(util/stop e))}
[:span
(svg/excalidraw-logo)
(string/capitalize (draw/get-file-title s))]]
(page-cp (assoc config
:label (mldoc/plain->text label)
:contents-page? contents-page?) {:page/name s}))
(when (and (not html-export?) (not contents-page?))
[:span.text-gray-500 "]]"])]))

(defn- latex-environment-content
[name option content]
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/components/sidebar.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
:style {:background-color "#002b36"}}
(if @open?
[:div.absolute.top-0.right-0.-mr-14.p-1
[:button.flex.items-center.justify-center.h-12.w-12.rounded-full.focus:outline-none.focus:bg-gray-600
[:button#close-left-bar.flex.items-center.justify-center.h-12.w-12.rounded-full.focus:outline-none.focus:bg-gray-600
{:on-click close-fn}
[:svg.h-6.w-6.text-white
{:viewBox "0 0 24 24", :fill "none", :stroke "currentColor"}
Expand Down
25 changes: 4 additions & 21 deletions src/main/frontend/handler/ui.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,10 @@
[frontend.util :as util :refer-macros [profile]]))

;; sidebars
(defn hide-left-sidebar
(defn close-left-sidebar!
[]
(dom/add-class! (dom/by-id "menu")
"md:block")
(dom/remove-class! (dom/by-id "left-sidebar")
"enter")
(dom/remove-class! (dom/by-id "search")
"sidebar-open")
(dom/remove-class! (dom/by-id "main")
"sidebar-open"))

(defn show-left-sidebar
[]
(dom/remove-class! (dom/by-id "menu")
"md:block")
(dom/add-class! (dom/by-id "left-sidebar")
"enter")
(dom/add-class! (dom/by-id "search")
"sidebar-open")
(dom/add-class! (dom/by-id "main")
"sidebar-open"))
(when-let [elem (gdom/getElement "close-left-bar")]
(.click elem)))

(defn hide-right-sidebar
[]
Expand Down Expand Up @@ -92,5 +75,5 @@
(state/get-custom-css-link)
(db/get-custom-css)
;; (state/get-custom-css-link)
)]
)]
(util/add-style! style)))

0 comments on commit 43e9257

Please sign in to comment.