mirror of
https://github.com/logseq/logseq.git
synced 2026-05-29 23:19:38 +00:00
feat(deeplink): support deeplink across graphs
This commit is contained in:
@@ -1,26 +1,32 @@
|
||||
(ns frontend.mobile.deeplink
|
||||
(:require
|
||||
[clojure.string :as string]
|
||||
[frontend.config :as config]
|
||||
[frontend.db.model :as db-model]
|
||||
[frontend.handler.editor :as editor-handler]
|
||||
[frontend.handler.notification :as notification]
|
||||
[frontend.handler.route :as route-handler]
|
||||
[frontend.handler.user :as user-handler]
|
||||
[frontend.mobile.intent :as intent]
|
||||
[frontend.state :as state]
|
||||
[frontend.text :as text]))
|
||||
|
||||
(def *link-to-another-graph (atom false))
|
||||
|
||||
(defn deeplink [url]
|
||||
(let [parsed-url (js/URL. url)
|
||||
hostname (.-hostname parsed-url)
|
||||
pathname (.-pathname parsed-url)
|
||||
search-params (.-searchParams parsed-url)
|
||||
current-repo-url (state/get-current-repo)
|
||||
current-graph-name (-> (text/get-graph-name-from-path current-repo-url)
|
||||
get-graph-name-fn #(-> (text/get-graph-name-from-path %)
|
||||
(string/split "/")
|
||||
last
|
||||
string/lower-case)]
|
||||
|
||||
string/lower-case)
|
||||
current-graph-name (get-graph-name-fn current-repo-url)
|
||||
repos (->> (state/sub [:me :repos])
|
||||
(remove #(= (:url %) config/local-repo))
|
||||
(map :url))
|
||||
repo-names (map #(get-graph-name-fn %) repos)]
|
||||
(cond
|
||||
(= hostname "auth-callback")
|
||||
(when-let [code (.get search-params "code")]
|
||||
@@ -34,26 +40,32 @@
|
||||
["page" "block-id"])]
|
||||
|
||||
(when-not (string/blank? graph-name)
|
||||
(if (= graph-name current-graph-name)
|
||||
(cond
|
||||
page-name
|
||||
(let [db-page-name (db-model/get-redirect-page-name page-name)]
|
||||
(editor-handler/insert-first-page-block-if-not-exists! db-page-name))
|
||||
(when-not (= graph-name current-graph-name)
|
||||
(let [graph-idx (.indexOf repo-names graph-name)
|
||||
graph-url (when (not= graph-idx -1)
|
||||
(nth repos graph-idx))]
|
||||
(if graph-url
|
||||
(do (state/pub-event! [:graph/switch graph-url])
|
||||
(reset! *link-to-another-graph true))
|
||||
(notification/show! (str "Open graph failed. Graph `" graph-name "` doesn't exist.") :error false))))
|
||||
|
||||
block-uuid
|
||||
(if (db-model/get-block-by-uuid block-uuid)
|
||||
(route-handler/redirect-to-page! block-uuid)
|
||||
(notification/show! (str "Open link failed. Block-id `" block-uuid "` doesn't exist in the graph.") :error false))
|
||||
(js/setTimeout
|
||||
(fn []
|
||||
(cond
|
||||
page-name
|
||||
(let [db-page-name (db-model/get-redirect-page-name page-name)]
|
||||
(editor-handler/insert-first-page-block-if-not-exists! db-page-name))
|
||||
|
||||
:else
|
||||
(notification/show! (str "Opening File link is not supported on mobile.") :error false))
|
||||
(notification/show! (str "The SCHEME across graphs has not been supported yet.") :error false))))
|
||||
block-uuid
|
||||
(if (db-model/get-block-by-uuid block-uuid)
|
||||
(route-handler/redirect-to-page! block-uuid)
|
||||
(notification/show! (str "Open link failed. Block-id `" block-uuid "` doesn't exist in the graph.") :error false))
|
||||
|
||||
(= hostname "shared")
|
||||
(let [result (into {} (map (fn [key]
|
||||
[(keyword key) (.get search-params key)])
|
||||
["title" "url" "type"]))]
|
||||
(intent/handle-result result))
|
||||
:else
|
||||
nil))
|
||||
(if @*link-to-another-graph
|
||||
1000
|
||||
0))))
|
||||
|
||||
:else
|
||||
nil)))
|
||||
(notification/show! (str "The url has not been supported yet.") :error false))))
|
||||
|
||||
Reference in New Issue
Block a user