-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.cljs
46 lines (36 loc) · 1.04 KB
/
state.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(ns roam-plugin-tools.state
(:require [clojure.string :as str]
[roam-plugin-tools.query :refer [q-first]]))
(defn url [] js/window.location.href)
(defn graph-name []
(if-let [tail (->> (url)
(re-find #"(#/app/)(.+)")
(last))]
(if (str/includes? tail "/")
(last (re-find #"^(.*?)/" tail))
tail)))
(defn base-url []
(let [head (->> (url)
(re-find #"(.*)#")
(last))]
(str head "#/app/" (graph-name))))
(defn base-page-url []
(str (base-url) "/page/"))
(defn get-page-url [uid]
(str (base-page-url) uid))
(defn current-user-email []
(-> "globalAppState"
(js/localStorage.getItem)
(js/JSON.parse)
(seq)
(last)
(nth 2)))
(defn go-to-url! [url]
(set! (.. js/window -location -href) url))
(defn go-to-uid! [uid]
(go-to-url! (get-page-url uid)))
(defn go-to-page! [name]
(->> name
(q-first '[:find (pull ?e [:block/uid]) :in $ ?n :where [?e :node/title ?n]])
(:uid)
(go-to-uid!)))