ux: copy logseq URL of block

pull/4922/head
Junyi Du 2022-04-13 22:11:08 +08:00 committed by Tienson Qin
parent 724eb92990
commit dd7cc6a70f
4 changed files with 44 additions and 6 deletions

View File

@ -131,7 +131,7 @@
(let [params (.-searchParams parsed-url)]
(map (fn [key]
(when-let [value (.get params key)]
(js/decodeURI value)))
(js/decodeURIComponent value)))
keys)))
;; Keep update with the normalization in main

View File

@ -6,6 +6,7 @@
[frontend.components.editor :as editor]
[frontend.components.page-menu :as page-menu]
[frontend.components.export :as export]
[frontend.components.repo :as repo]
[frontend.config :as config]
[frontend.context.i18n :refer [t]]
[frontend.db :as db]
@ -21,6 +22,7 @@
[frontend.state :as state]
[frontend.ui :as ui]
[frontend.util :as util]
[frontend.util.url :as url-util]
[goog.dom :as gdom]
[goog.object :as gobj]
[rum.core :as rum]))
@ -211,6 +213,19 @@
:on-click (fn [_e]
(editor-handler/copy-block-ref! block-id #(util/format "{{embed ((%s))}}" %)))}
"Copy block embed")
;; TODO Logseq protocol mobile support
(when (util/electron?)
(ui/menu-link
{:key "Copy block URL"
:on-click (fn [_e]
(let [current-repo (state/get-current-repo)
repo-path (repo/get-repo-name current-repo)
short-repo-name (repo/get-short-repo-name repo-path)
tap-f (fn [block-id]
(url-util/get-local-logseq-url-by-uuid short-repo-name block-id))]
(editor-handler/copy-block-ref! block-id tap-f)))}
"Copy block URL"))
(block-template block-id)

View File

@ -183,7 +183,8 @@
(p/let [multiple-windows? (ipc/ipc "graphHasMultipleWindows" (state/get-current-repo))]
(reset! (::electron-multiple-windows? state) multiple-windows?))))
(defn- get-repo-name [repo]
;; TODO move to else where?
(defn get-repo-name [repo]
(cond
(mobile-util/is-native-platform?)
(text/get-graph-name-from-path repo)
@ -194,6 +195,15 @@
:else
(db/get-repo-path repo)))
;; TODO move to else where?
(defn get-short-repo-name
"repo-path: output of `get-repo-name`"
[repo-path]
(if (or (util/electron?)
(mobile-util/is-native-platform?))
(text/get-file-basename repo-path)
repo-path))
(defn- repos-dropdown-links [repos current-repo *multiple-windows?]
(let [switch-repos (remove (fn [repo] (= current-repo (:url repo))) repos) ; exclude current repo
repo-links (mapv
@ -274,10 +284,7 @@
links (repos-dropdown-links repos current-repo multiple-windows?)
render-content (fn [{:keys [toggle-fn]}]
(let [repo-path (get-repo-name current-repo)
short-repo-name (if (or (util/electron?)
(mobile-util/is-native-platform?))
(text/get-file-basename repo-path)
repo-path)]
short-repo-name (get-short-repo-name repo-path)]
[:a.item.group.flex.items-center.px-2.py-2.text-sm.font-medium.rounded-md
{:on-click (fn []
(check-multiple-windows? state)

View File

@ -0,0 +1,16 @@
(ns frontend.util.url)
;; Keep same as electron/core.cljs
(def LSP_SCHEME "logseq")
(def encoder js/encodeURIComponent)
(defn get-logseq-url-by-uuid
"Only the name of repo is required (not full path)"
[host repo-name uuid]
(str LSP_SCHEME "://" host "/open?graph=" (encoder repo-name) "&block-id=" uuid))
(defn get-local-logseq-url-by-uuid
"Ensure repo-name and uuid are valid string before hand.
Only the name of repo is required (not full path)"
[repo-name uuid]
(get-logseq-url-by-uuid "local" repo-name uuid))