Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: leaner reactions #2269

Merged
merged 7 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 20 additions & 31 deletions src/cljs/athens/views/blocks/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
["/components/Block/PropertyName" :refer [PropertyName]]
["/components/Block/Reactions" :refer [Reactions]]
["/components/Block/Toggle" :refer [Toggle]]
["/components/EmojiPicker/EmojiPicker" :refer [EmojiPickerPopoverContent]]
["/components/References/InlineReferences" :refer [ReferenceGroup ReferenceBlock]]
["@chakra-ui/react" :refer [VStack PopoverAnchor Popover Button Breadcrumb BreadcrumbItem BreadcrumbLink HStack]]
["@chakra-ui/react" :refer [VStack Button Breadcrumb BreadcrumbItem BreadcrumbLink HStack]]
["react-intersection-observer" :refer [useInView]]
[athens.common-db :as common-db]
[athens.db :as db]
Expand Down Expand Up @@ -154,7 +153,7 @@


(defn editor-component
[block-el block-o children? linked-ref-data uid-sanitized-block state-hooks opts menu show-emoji-picker? hide-emoji-picker-fn]
[block-el block-o children? linked-ref-data uid-sanitized-block state-hooks opts menu]
(let [{:keys [linked-ref
parent-uids]} linked-ref-data
uid (:block/uid block-o)
Expand Down Expand Up @@ -209,34 +208,24 @@
:on-drag-end (fn [e] (bullet-drag-end e uid))}])


[:> Popover {:isOpen @show-emoji-picker?
:placement "bottom-end"
:isLazy true
:onClose hide-emoji-picker-fn}

[:> PopoverAnchor
[:> Anchor {:isClosedWithChildren (when (and (seq children)
(or (and (true? linked-ref) (not @linked-ref-open?))
(and (false? linked-ref) (not open))))
"closed-with-children")
:uidSanitizedBlock uid-sanitized-block
:shouldShowDebugDetails (util/re-frame-10x-open?)
:menu menu
:onClick (fn [e]
(let [shift? (.-shiftKey e)]
(rf/dispatch [:reporting/navigation {:source :block-bullet
:target :block
:pane (if shift?
:right-pane
:main-pane)}])
(router/navigate-uid uid e)))
:on-drag-start (fn [e] (bullet-drag-start e uid))
:on-drag-end (fn [e] (bullet-drag-end e uid))
:unreadNotification (actions/unread-notification? properties)}]]
(when (and reactions-enabled? in-view?)
[:> EmojiPickerPopoverContent
{:onClose hide-emoji-picker-fn
:onEmojiSelected (fn [e] (toggle-reaction [:block/uid uid] (.. e -detail -unicode) user-id))}])]
[:> Anchor {:isClosedWithChildren (when (and (seq children)
(or (and (true? linked-ref) (not @linked-ref-open?))
(and (false? linked-ref) (not open))))
"closed-with-children")
:uidSanitizedBlock uid-sanitized-block
:shouldShowDebugDetails (util/re-frame-10x-open?)
:menu menu
:onClick (fn [e]
(let [shift? (.-shiftKey e)]
(rf/dispatch [:reporting/navigation {:source :block-bullet
:target :block
:pane (if shift?
:right-pane
:main-pane)}])
(router/navigate-uid uid e)))
:on-drag-start (fn [e] (bullet-drag-start e uid))
:on-drag-end (fn [e] (bullet-drag-end e uid))
:unreadNotification (actions/unread-notification? properties)}]

[content/block-content-el block-o state-hooks]

Expand Down
30 changes: 29 additions & 1 deletion src/cljs/athens/views/blocks/reactions.cljs
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
(ns athens.views.blocks.reactions
(:require
["@chakra-ui/react" :refer [Box
Tooltip
VStack
HStack
MenuItem
MenuGroup
Text]]
[athens.common-db :as common-db]
[athens.common-events.graph.ops :as graph-ops]
[athens.db :as db]
[re-frame.core :as rf]))
[re-frame.core :as rf]
[reagent.core :as r]))


(def common-reactions ["❤️" "💔" "😐" "😕" "😡"])


(defn toggle-reaction
Expand Down Expand Up @@ -57,3 +68,20 @@
(sort-by first)
(into [])))


(defn reactions-menu-list-item
[props]
(let [{:keys [icon fn command]} props]
[:> Box {:display "inline-flex" :flex 1}
[:> Tooltip {:label (r/as-element [:> VStack {:align "center"}
[:> Text "React with '" icon "'"]
(when command [:> Text command])])}
[:> MenuItem {:justifyContent "center" :on-click fn} icon]]]))


(defn reactions-menu-list
[uid user-id]
[:> MenuGroup {:title "Add reaction"}
[:> HStack {:spacing 0 :justifyContent "stretch"}
(for [reaction-icon common-reactions]
[reactions-menu-list-item {:icon reaction-icon :fn (toggle-reaction uid reaction-icon user-id)}])]])
18 changes: 7 additions & 11 deletions src/cljs/athens/views/blocks/types/default.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
A.k.a standard `:block/string` blocks"
(:require
["/components/Block/Container" :refer [Container]]
["/components/Icons/Icons" :refer [PencilIcon BlockEmbedIcon TextIcon ChatIcon ThumbUpFillIcon ArchiveIcon]]
["@chakra-ui/react" :refer [Box Button ButtonGroup IconButton MenuList MenuItem Divider]]
["/components/Icons/Icons" :refer [PencilIcon BlockEmbedIcon TextIcon ChatIcon ArchiveIcon]]
["@chakra-ui/react" :refer [Box Button ButtonGroup IconButton MenuDivider MenuList MenuItem Divider]]
[athens.common-db :as common-db]
[athens.common.logging :as log]
[athens.db :as db]
Expand All @@ -24,6 +24,7 @@
[athens.views.blocks.context-menu :as ctx-menu]
[athens.views.blocks.drop-area-indicator :as drop-area-indicator]
[athens.views.blocks.editor :as editor]
[athens.views.blocks.reactions :as reactions]
[athens.views.blocks.types :as types]
[athens.views.blocks.types.dispatcher :as dispatcher]
[athens.views.notifications.actions :as actions]
Expand Down Expand Up @@ -297,9 +298,6 @@
reactions-enabled? (:reactions @feature-flags)
comments-enabled? (:comments @feature-flags)
notifications-enabled? (:notifications @feature-flags)
show-emoji-picker? (r/atom false)
hide-emoji-picker-fn #(reset! show-emoji-picker? false)
show-emoji-picker-fn #(reset! show-emoji-picker? true)
menu (r/as-element
[:> MenuList
[:> MenuItem {:children (if (> (count @selected-items) 1)
Expand All @@ -316,9 +314,9 @@
:onClick #(ctx-menu/handle-click-comment % uid)
:icon (r/as-element [:> ChatIcon])}])
(when reactions-enabled?
[:> MenuItem {:children "Add reaction"
:onClick show-emoji-picker-fn
:icon (r/as-element [:> ThumbUpFillIcon])}])
[:<>
[:> MenuDivider]
[reactions/reactions-menu-list uid "Stuart"]])
filipesilva marked this conversation as resolved.
Show resolved Hide resolved

(when (and notifications-enabled? (actions/is-block-inbox? properties))
[:<>
Expand Down Expand Up @@ -379,9 +377,7 @@
uid-sanitized-block
state-hooks
opts
menu
show-emoji-picker?
hide-emoji-picker-fn]
menu]

(when (= @drag-target :first) [drop-area-indicator/drop-area-indicator {:placement "below" :child? true}])
(when (= @drag-target :after) [drop-area-indicator/drop-area-indicator {:placement "below"}])]))})))
Expand Down
3 changes: 1 addition & 2 deletions src/js/theme/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,8 @@ const components = {
},
groupTitle: {
color: "foreground.secondary",
textTransform: "uppercase",
fontSize: "0.75em",
fontWeight: "bold",
fontWeight: "700",
},
item: {
"&.isActive": {
Expand Down