Skip to content

Commit

Permalink
Merge branch 'master' into feat/i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
thesophiaxu authored Sep 12, 2020
2 parents 0945bd2 + 87a438e commit 9564dc0
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 43 deletions.
30 changes: 14 additions & 16 deletions web/src/main/frontend/components/hiccup.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -228,23 +228,20 @@
(when-let [page-name (:page/name page)]
(let [original-page-name (get page :page/original-name page-name)
page (string/lower-case page-name)
page-entity (db/entity [:page/name page])
href (if html-export?
(util/encode-str page)
(str "/page/" (util/encode-str page)))]
[:a.page-ref
(if page-entity
{:href href
:on-click (fn [e]
(util/stop e)
(when (gobj/get e "shiftKey")
{:href href
:on-click (fn [e]
(util/stop e)
(when (gobj/get e "shiftKey")
(when-let [page-entity (db/entity [:page/name page])]
(state/sidebar-add-block!
(state/get-current-repo)
(:db/id page-entity)
:page
{:page page-entity})))}
{:class "warning"
:title "Orphan page"})
(state/get-current-repo)
(:db/id page-entity)
:page
{:page page-entity}))))}
(if (seq children)
(for [child children]
(if (= (first child) "Label")
Expand Down Expand Up @@ -955,10 +952,11 @@
(when (and (not pre-block?) (seq body))
[:div.block-body {:style {:display (if collapsed? "none" "")}}
;; TODO: consistent id instead of the idx (since it could be changed later)
(for [[idx child] (medley/indexed (:block/body block))]
(when-let [block (block-cp config child)]
(rum/with-key (block-child block)
(str uuid "-" idx))))])]
(let [body (block/trim-break-lines! (:block/body block))]
(for [[idx child] (medley/indexed body)]
(when-let [block (block-cp config child)]
(rum/with-key (block-child block)
(str uuid "-" idx)))))])]
(when (and block-refs-count (> block-refs-count 0))
[:div
[:a.block.py-0.px-2.rounded.bg-base-2.opacity-50.hover:opacity-100
Expand Down
14 changes: 12 additions & 2 deletions web/src/main/frontend/components/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,18 @@
(for [[page modified-at] pages]
(let [encoded-page (util/encode-str page)]
[:tr {:key encoded-page}
[:td [:a.text-gray-700 {:href (str "/page/" encoded-page)}
page]]
[:td [:a.text-gray-700 {:on-click (fn [e]
(util/stop e)
(let [repo (state/get-current-repo)
page (db/pull repo '[*] [:page/name (string/lower-case page)])]
(when (gobj/get e "shiftKey")
(state/sidebar-add-block!
repo
(:db/id page)
:page
{:page page}))))
:href (str "/page/" encoded-page)}
page]]
[:td [:span.text-gray-500.text-sm
(if (zero? modified-at)
(t :file/no-data)
Expand Down
5 changes: 3 additions & 2 deletions web/src/main/frontend/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,8 +1160,9 @@
(string/replace "_" " ")
(util/capitalize-all))))]
(or directive-name
first-block-name
file-name)))))
(if (= (state/page-name-order) "file")
(or file-name first-block-name)
(or first-block-name file-name)))))))

(defn get-block-content
[utf8-content block]
Expand Down
1 change: 1 addition & 0 deletions web/src/main/frontend/external/roam.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
[edn-data]
(load-all-refed-uids! edn-data)
(let [files (map ->file edn-data)
files (remove #(nil? (:title %)) files)
files (group-by (fn [f] (string/lower-case (:title f)))
files)]
(map
Expand Down
10 changes: 10 additions & 0 deletions web/src/main/frontend/format/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,13 @@
(rest args)
(inc n))
s)))

(defn break-line-paragraph?
[[typ break-lines]]
(and (= typ "Paragraph")
(every? #(= % ["Break_Line"]) break-lines)))

(defn trim-break-lines!
[ast]
(->> (drop-while break-line-paragraph? ast)
(take-while (complement break-line-paragraph?))))
24 changes: 12 additions & 12 deletions web/src/main/frontend/handler/notification.cljs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
(ns frontend.handler.notification
(:require [frontend.state :as state]))
(:require [frontend.state :as state]
[frontend.util :as util]))

(defn clear!
[e]
(swap! state/state assoc
:notification/show? false
:notification/content nil
:notification/status nil))
[uid]
(let [contents (state/get-notification-contents)]
(state/set-state! :notification/contents (dissoc contents uid))))

(defn show!
([content status]
(show! content status true))
([content status clear?]
(swap! state/state assoc
:notification/show? true
:notification/content content
:notification/status status)
(let [contents (state/get-notification-contents)
uid (keyword (util/unique-id))]
(state/set-state! :notification/contents (assoc contents
uid {:content content
:status status}))

(when clear?
(js/setTimeout clear! 3000))))
(when clear?
(js/setTimeout #(clear! uid) 3000)))))
15 changes: 14 additions & 1 deletion web/src/main/frontend/state.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
:sidebar/blocks '()

:preferred-language (storage/get :preferred-language)

;; all notification contents as k-v pairs
:notification/contents {}

}))

(defn get-route-match
Expand Down Expand Up @@ -159,6 +163,10 @@
[]
(:hide-file-in-page? (get-config)))

(defn page-name-order
[]
(:page-name-order (get-config)))

(defn get-repos
[]
(get-in @state [:me :repos]))
Expand Down Expand Up @@ -722,4 +730,9 @@
(defn set-developer-mode!
[value]
(set-state! :ui/developer-mode? value)
(storage/set "developer-mode" (str value)))
(storage/set "developer-mode" (str value)))

(defn get-notification-contents
[]
(get-in @state [:notification/contents]))

26 changes: 16 additions & 10 deletions web/src/main/frontend/ui.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
["react-textarea-autosize" :as TextareaAutosize]
[frontend.util :as util]
[frontend.mixins :as mixins]
[frontend.handler.notification :as notification-handler]
[frontend.state :as state]
[frontend.components.svg :as svg]
[clojure.string :as string]
Expand Down Expand Up @@ -86,7 +87,7 @@
text])))

(rum/defc notification-content
[state content status]
[state content status uid]
(when (and content status)
(let [[color-class svg]
(case status
Expand Down Expand Up @@ -117,7 +118,7 @@
:d
"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",
:fill-rule "evenodd"}]]])]
[:div.fixed.inset-0.flex.items-end.justify-center.px-4.py-6.pointer-events-none.sm:p-6.sm:items-start.sm:justify-end
[:div.inset-0.flex.items-end.justify-center.px-4.py-3.pointer-events-none.sm:px-6.sm:py-3.sm:items-start.sm:justify-end
{:style {:z-index (if (or (= state "exiting")
(= state "exited"))
-1
Expand All @@ -141,7 +142,7 @@
[:div.ml-4.flex-shrink-0.flex
[:button.inline-flex.text-gray-400.focus:outline-none.focus:text-gray-500.transition.ease-in-out.duration-150
{:on-click (fn []
(swap! state/state assoc :notification/show? false))}
(notification-handler/clear! uid))}
[:svg.h-5.w-5
{:fill "currentColor", :view-Box "0 0 20 20"}
[:path
Expand All @@ -152,13 +153,18 @@

(rum/defc notification < rum/reactive
[]
(let [show? (state/sub :notification/show?)
status (state/sub :notification/status)
content (state/sub :notification/content)]
(css-transition
{:in show? :timeout 100}
(fn [state]
(notification-content state content status)))))
(let [contents (state/sub :notification/contents)]
(transition-group
{:class-name "notifications"}
(doall (map (fn [el]
(let [k (first el)
v (second el)]
(css-transition
{:timeout 100
:key (name k)}
(fn [state]
(notification-content state (:content v) (:status v) k)))))
contents)))))

(defn checkbox
[option]
Expand Down

0 comments on commit 9564dc0

Please sign in to comment.