Add logseq logo (which links to the docs) at the bottom of the left sidebar

pull/645/head
Tienson Qin 2020-05-15 11:50:29 +08:00
parent a402d3daa0
commit c48d5c9fe6
4 changed files with 73 additions and 60 deletions

View File

@ -1,12 +1,17 @@
(ns frontend.components.demo
(ns frontend.components.docs
(:require [rum.core :as rum]
[frontend.handler :as handler]
[frontend.ui :as ui]
[frontend.state :as state]
[frontend.components.widgets :as widgets]))
(rum/defc demo
(rum/defc docs <
{:will-mount (fn [state]
(if (state/logged?)
(handler/load-docs!))
state)}
[]
[:div#demo
[:div#docs
[:h1.title {:style {:margin-bottom "0.25rem"}}
"What's your preferred mode?"]
[:span.text-gray-500.text-sm.ml-1
@ -18,7 +23,7 @@
:on-click
(fn []
(handler/set-preferred-format! :markdown)
(handler/run-demo!)))
(handler/load-docs!)))
[:span.ml-2.mr-2 "-OR-"]
@ -27,4 +32,4 @@
:on-click
(fn []
(handler/set-preferred-format! :org)
(handler/run-demo!)))]])
(handler/load-docs!)))]])

View File

@ -16,49 +16,37 @@
[dommy.core :as d]
[clojure.string :as string]))
(rum/defc logo-or-repos < rum/reactive
(rum/defc logo
[]
[:div#logo.p-4
[:a.opacity-50.hover:opacity-100 {:href "/docs"}
[:img.h-6.w-auto
{:alt "Logseq",
:src "/static/img/logo.png"}]]])
(rum/defc repos < rum/reactive
[current-repo close-modal-fn]
(if current-repo
(let [repos (state/sub [:me :repos])
repos (->> repos
(remove #(= (:url %) current-repo))
(util/distinct-by :url))]
[:div.flex.flex-row.align-center.whitespace-no-wrap
[:a.hover:text-gray-300.text-gray-400
{:style {:margin-right 13
:margin-top -1}
:on-click (fn []
(d/add-class! (d/by-id "menu")
"md:block")
(d/remove-class! (d/by-id "left-sidebar")
"enter")
(d/remove-class! (d/by-id "search")
"sidebar-open")
(d/remove-class! (d/by-id "main")
"sidebar-open"))}
(svg/menu "currentColor")]
(if (>= (count repos) 1)
(ui/dropdown-with-links
(fn [{:keys [toggle-fn]}]
[:a.hover:text-gray-300.text-gray-400.font-bold {:on-click toggle-fn}
[:span (string/capitalize (util/take-at-most (db/get-repo-name current-repo) 20))]
[:span.dropdown-caret.ml-1 {:style {:border-top-color "#6b7280"}}]])
(mapv
(fn [{:keys [id url]}]
{:title (db/get-repo-name url)
:options {:on-click (fn []
(state/set-current-repo! url))}})
repos)
(util/hiccup->class
"origin-top-right.absolute.left-0.mt-2.w-48.rounded-md.shadow-lg "))
[:a.hover:text-gray-300.text-gray-400.font-bold
{:href current-repo
:target "_blank"}
(string/capitalize (util/take-at-most (db/get-repo-name current-repo) 20))])])
[:img.h-8.w-auto
{:alt "Logseq",
:src "/static/img/logo.png"}]))
(let [repos (state/sub [:me :repos])]
(if (>= (count repos) 1)
(ui/dropdown-with-links
(fn [{:keys [toggle-fn]}]
[:a.hover:text-gray-300.text-gray-400.font-bold {:on-click toggle-fn}
[:span (string/capitalize (util/take-at-most (db/get-repo-name current-repo) 20))]
[:span.dropdown-caret.ml-1 {:style {:border-top-color "#6b7280"}}]])
(mapv
(fn [{:keys [id url]}]
{:title (db/get-repo-name url)
:options {:on-click (fn []
(state/set-current-repo! url))}})
repos)
(util/hiccup->class
"origin-top-right.absolute.left-0.mt-2.w-48.rounded-md.shadow-lg "))
[:a.hover:text-gray-300.text-gray-400.font-bold
{:href current-repo
:target "_blank"}
(string/capitalize (util/take-at-most (db/get-repo-name current-repo) 20))])))
)
(defn nav-item
[title href svg-d active? close-modal-fn]
@ -193,12 +181,28 @@
(rum/defc left-sidebar < rum/reactive
[current-repo route-match close-fn]
[:div#left-sidebar.flex.flex-col.w-64.sidebar.enter
[:div.flex.items-center.flex-shrink-0.px-4.h-16 {:class (if current-repo
"sm:h-10"
"sm:h-16")}
(logo-or-repos current-repo)]
[:div.flex.items-center.flex-shrink-0.px-4.h-10
[:div.flex.flex-row.align-center.whitespace-no-wrap
[:a.hover:text-gray-300.text-gray-400
{:style {:margin-right 13
:margin-top -1}
:on-click (fn []
(d/add-class! (d/by-id "menu")
"md:block")
(d/remove-class! (d/by-id "left-sidebar")
"enter")
(d/remove-class! (d/by-id "search")
"sidebar-open")
(d/remove-class! (d/by-id "main")
"sidebar-open"))}
(svg/menu "currentColor")]
(repos current-repo close-fn)
]]
[:div.h-0.flex-1.flex.flex-col.overflow-y-auto
(sidebar-nav route-match close-fn)]])
(sidebar-nav route-match close-fn)]
(logo)])
(rum/defcs sidebar < (mixins/modal)
rum/reactive
@ -232,7 +236,7 @@
:stroke-linejoin "round",
:stroke-linecap "round"}]]]])
[:div.flex-shrink-0.flex.items-center.px-4.h-16 {:style {:background-color "#202225"}}
(logo-or-repos current-repo close-fn)]
(repos current-repo close-fn)]
[:div.flex-1.h-0.overflow-y-auto
(sidebar-nav route-match close-fn)]]]
[:div.hidden.md:flex.md:flex-shrink-0

View File

@ -930,12 +930,16 @@
(periodically-pull-and-push repo {:pull-now? true}))
(clone-and-pull repo))))))))))))
(defn run-demo!
(defn load-docs!
[]
(redirect! {:to :home})
(let [test-repo "https://github.com/logseq/docs"]
(p/let [_ (clone test-repo)]
(load-db-and-journals! test-repo nil true))))
;; TODO: Allow user to overwrite this repo
(let [docs-repo "https://github.com/logseq/docs"]
(if (db/cloned? docs-repo)
;; switch to docs repo
(state/set-current-repo! docs-repo)
(p/let [_ (clone docs-repo)]
(load-db-and-journals! docs-repo nil true)))))
(comment

View File

@ -6,7 +6,7 @@
[frontend.components.page :as page]
[frontend.components.diff :as diff]
[frontend.components.draw :as draw]
[frontend.components.demo :as demo]
[frontend.components.docs :as docs]
[frontend.components.agenda :as agenda]))
(def routes
@ -50,6 +50,6 @@
{:name :draw
:view draw/draw}]
["/demo"
{:name :demo
:view demo/demo}]])
["/docs"
{:name :doc
:view docs/docs}]])