Просмотр исходного кода

enhance: p r to add emoji reaction

Tienson Qin 6 дней назад
Родитель
Сommit
daf7fc1475

+ 2 - 2
deps/db-sync/package.json

@@ -10,8 +10,8 @@
     "dev:node-adapter": "clojure -M:cljs watch db-sync-node",
     "start:node-adapter": "node worker/dist/node-adapter.js",
     "migrate:local": "cd ./worker && wrangler d1 migrations apply DB --local",
-    "migrate:staging": "cd ./worker && wrangler d1 migrations apply logseq-sync-graph-meta-staging --env staging",
-    "migrate:prod": "cd ./worker && wrangler d1 migrations apply logseq-sync-graphs-prod --env prod",
+    "migrate:staging": "cd ./worker && wrangler d1 migrations apply logseq-sync-graph-meta-staging --env staging --remote",
+    "migrate:prod": "cd ./worker && wrangler d1 migrations apply logseq-sync-graphs-prod --env prod --remote",
     "test:node-adapter": "clojure -M:cljs compile db-sync-test && node worker/dist/worker-test.js",
     "test": "clojure -M:cljs compile db-sync-test && node worker/dist/worker-test.js",
     "clean": "rm -rf ./worker/dist/",

+ 37 - 0
src/main/frontend/handler/events/ui.cljs

@@ -4,6 +4,7 @@
             [clojure.core.async.interop :refer [p->c]]
             [frontend.components.assets :as assets]
             [frontend.components.cmdk.core :as cmdk]
+            [frontend.components.icon :as icon-component]
             [frontend.components.page :as component-page]
             [frontend.components.page-menu :as page-menu]
             [frontend.components.plugins :as plugin]
@@ -25,6 +26,7 @@
             [frontend.handler.notification :as notification]
             [frontend.handler.page :as page-handler]
             [frontend.handler.plugin :as plugin-handler]
+            [frontend.handler.reaction :as reaction-handler]
             [frontend.handler.repo :as repo-handler]
             [frontend.handler.route :as route-handler]
             [frontend.handler.user :as user-handler]
@@ -229,6 +231,41 @@
      (editor-handler/save-current-block!)
      (editor-new-property block target opts))))
 
+(defn- editor-new-reaction [target]
+  (let [editing-block (state/get-edit-block)
+        target-block-id (or (:block/uuid editing-block)
+                            (first (state/get-selection-block-ids)))
+        target' (or target
+                    (some-> (state/get-edit-input-id)
+                            (gdom/getElement))
+                    (first (state/get-selection-blocks)))
+        on-pick (fn [popup-id icon]
+                  (let [emoji-id (:id icon)
+                        emoji? (= :emoji (:type icon))]
+                    (if emoji?
+                      (do
+                        (reaction-handler/toggle-reaction! target-block-id emoji-id)
+                        (shui/popup-hide! popup-id))
+                      (notification/show! "Please pick an emoji reaction." :warning))))]
+    (when (and target-block-id target')
+      (shui/popup-show!
+       target'
+       (fn [{:keys [id]}]
+         (icon-component/icon-search
+          {:on-chosen (fn [_e icon _keep-popup?] (on-pick id icon))
+           :tabs [[:emoji "Emojis"]]
+           :default-tab :emoji
+           :show-used? true
+           :icon-value nil}))
+       {:align :start
+        :content-props {:class "ls-icon-picker"}}))))
+
+(defmethod events/handle :editor/new-reaction [[_ {:keys [target]}]]
+  (when-not config/publishing?
+    (p/do!
+     (editor-handler/save-current-block!)
+     (editor-new-reaction target))))
+
 (defmethod events/handle :graph/new-db-graph [[_ _opts]]
   (shui/dialog-open!
    repo/new-db-graph

+ 7 - 0
src/main/frontend/modules/shortcut/config.cljs

@@ -281,6 +281,11 @@
                                              :fn      (fn []
                                                         (state/pub-event! [:editor/new-property {:property-key "Icon"}]))}
 
+   :editor/add-reaction                     {:binding "p r"
+                                             :selection? true
+                                             :fn      (fn []
+                                                        (state/pub-event! [:editor/new-reaction {}]))}
+
    :editor/toggle-display-hidden-properties {:binding "p a"
                                              :fn      ui-handler/toggle-show-empty-hidden-properties!}
 
@@ -686,6 +691,7 @@
           :editor/add-property-status
           :editor/add-property-priority
           :editor/add-property-icon
+          :editor/add-reaction
           :editor/toggle-display-hidden-properties
           :ui/toggle-wide-mode
           :ui/select-theme-color
@@ -817,6 +823,7 @@
      :editor/add-property-status
      :editor/add-property-priority
      :editor/add-property-icon
+     :editor/add-reaction
      :editor/toggle-display-hidden-properties]
 
     :shortcut.category/toggle

+ 1 - 0
src/resources/dicts/en.edn

@@ -492,6 +492,7 @@
   :editor/add-property-status     "Add task status to selected block"
   :editor/add-property-priority   "Add task priority to selected block"
   :editor/add-property-icon       "Add icon"
+  :editor/add-reaction            "Add reaction"
   :editor/jump                    "Jump to a property key or value"
   :ui/toggle-brackets             "Toggle whether to display brackets"
   :go/electron-find-in-page       "Find text in page"

+ 17 - 6
src/test/frontend/modules/shortcut/core_test.cljs

@@ -1,6 +1,7 @@
 (ns frontend.modules.shortcut.core-test
   (:require [cljs.test :refer [deftest is testing]]
             [clojure.string :as string]
+            [frontend.modules.shortcut.config :as shortcut-config]
             [frontend.modules.shortcut.data-helper :as dh]
             [frontend.util :as util]))
 
@@ -15,11 +16,11 @@
     (is (= (count (dh/get-conflicts-by-keys "mod+c")) 1))
 
     (is (contains?
-          (->> (dh/get-conflicts-by-keys
-                 "mod+c" :shortcut.handler/editor-global
-                 {:exclude-ids #{:editor/copy} :group-global? true})
-               (vals) (mapcat #(vals %)) (some #(when (= (first %) (if util/mac? "meta+c" "ctrl+c")) (second %))))
-          :misc/copy))
+         (->> (dh/get-conflicts-by-keys
+               "mod+c" :shortcut.handler/editor-global
+               {:exclude-ids #{:editor/copy} :group-global? true})
+              (vals) (mapcat #(vals %)) (some #(when (= (first %) (if util/mac? "meta+c" "ctrl+c")) (second %))))
+         :misc/copy))
 
     (is (->> (dh/get-conflicts-by-keys ["t"])
              (vals)
@@ -45,5 +46,15 @@
     (is (= (dh/parse-conflicts-from-binding ["meta+x" "meta+x t" "t r"] "meta+x x")
            ["meta+x"]))))
 
+(deftest test-add-reaction-shortcut
+  (testing "add reaction shortcut is configured with p r"
+    (is (= ["p r"] (dh/shortcut-binding :editor/add-reaction))))
+  (testing "add reaction shortcut belongs to non-editing handler"
+    (is (= :shortcut.handler/global-non-editing-only
+           (dh/get-group :editor/add-reaction))))
+  (testing "add reaction shortcut appears in block-selection category"
+    (is (some #{:editor/add-reaction}
+              (shortcut-config/get-category-shortcuts :shortcut.category/block-selection)))))
+
 (comment
-  (cljs.test/run-tests))
+  (cljs.test/run-tests))