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

Revert "Revert "Improve block performance"" #2271

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions src/cljs/athens/views/blocks/content.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
:on-mouse-enter (fn [e] (textarea-mouse-enter e uid))
:on-mouse-down (fn [e] (textarea-mouse-down e uid))}])
[parse-and-render @read-value (or original-uid uid)]]
[autocomplete-search/inline-search-el block state-hooks last-event]
[autocomplete-slash/slash-menu-el block last-event]]))))
(when editing?
[autocomplete-search/inline-search-el block state-hooks last-event]
[autocomplete-slash/slash-menu-el block last-event])]))))

46 changes: 26 additions & 20 deletions src/cljs/athens/views/blocks/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
["/components/EmojiPicker/EmojiPicker" :refer [EmojiPickerPopoverContent]]
["/components/References/InlineReferences" :refer [ReferenceGroup ReferenceBlock]]
["@chakra-ui/react" :refer [VStack PopoverAnchor Popover Button Breadcrumb BreadcrumbItem BreadcrumbLink HStack]]
["react-intersection-observer" :refer [useInView]]
[athens.common-db :as common-db]
[athens.db :as db]
[athens.events.inline-refs :as inline-refs.events]
Expand Down Expand Up @@ -171,6 +172,7 @@
key
properties
_refs]} (reactive/get-reactive-block-document [:block/uid uid])
[ref in-view?] (useInView {:delay 250})
reactions-enabled? (:reactions @feature-flags)
user-id (or (:username @(rf/subscribe [:presence/current-user]))
;; We use empty string for when there is no user information, like in PKM.
Expand All @@ -179,19 +181,19 @@
(props->reactions properties))]

[:<>
[:div.block-body
[:div.block-body {:ref ref}
(when (and children?
(or (seq children)
(seq properties)))
[:> Toggle {:isOpen (if (or (and (true? linked-ref) @linked-ref-open?)
(and (false? linked-ref) open))
true
false)
:onClick (fn [e]
(.. e stopPropagation)
(if (true? linked-ref)
(rf/dispatch [::linked-ref.events/toggle-open! uid])
(toggle uid (not open))))}])
(when in-view? [:> Toggle {:isOpen (if (or (and (true? linked-ref) @linked-ref-open?)
(and (false? linked-ref) open))
true
false)
:onClick (fn [e]
(.. e stopPropagation)
(if (true? linked-ref)
(rf/dispatch [::linked-ref.events/toggle-open! uid])
(toggle uid (not open))))}]))

(when key
[:> PropertyName {:name (:node/title key)
Expand All @@ -209,7 +211,7 @@

[:> Popover {:isOpen @show-emoji-picker?
:placement "bottom-end"
:onOpen #(js/console.log "tried to open")
:isLazy true
:onClose hide-emoji-picker-fn}

[:> PopoverAnchor
Expand All @@ -231,30 +233,32 @@
: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 reactions-enabled?
(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))}])]




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

(when reactions [:> Reactions {:reactions (clj->js reactions)
:currentUser user-id
:onToggleReaction (partial toggle-reaction [:block/uid uid])}])
(when (and
in-view?
reactions) [:> Reactions {:reactions (clj->js reactions)
:currentUser user-id
:onToggleReaction (partial toggle-reaction [:block/uid uid])}])

;; Show comments when the toggle is on
(when (and @show-comments?
in-view?
open
(or @show-textarea
(comments/get-comment-thread-uid @db/dsdb uid)))
[inline-comments/inline-comments (comments/get-comments-in-thread @db/dsdb (comments/get-comment-thread-uid @db/dsdb uid)) uid false])

[presence/inline-presence-el uid]
(when in-view? [presence/inline-presence-el uid])

(when (and (> (count _refs) 0) (not= :block-embed? opts))
(when (and
in-view?
(> (count _refs) 0) (not= :block-embed? opts))
[block-refs-count-el
(count _refs)
(fn [e]
Expand All @@ -265,12 +269,14 @@

;; Inline refs
(when (and (> (count _refs) 0)
in-view?
(not= :block-embed? opts)
@inline-refs-open?)
[inline-linked-refs-el block-el uid])

;; Properties
(when (and @enable-properties?
in-view?
(or (and (true? linked-ref) @linked-ref-open?)
(and (false? linked-ref) open)))
(for [prop (common-db/sort-block-properties properties)]
Expand Down
2 changes: 1 addition & 1 deletion src/cljs/athens/views/blocks/types/default.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@

(when (= @drag-target :before) [drop-area-indicator/drop-area-indicator {:placement "above"}])

[editor/editor-component
[:f> editor/editor-component
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to add this after merging master in. In master, editor/editor-component was rolled back into blocks.core/block-el.

block-el
block-o
true
Expand Down
5 changes: 2 additions & 3 deletions src/js/components/Block/Container.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { Box, useMergeRefs } from "@chakra-ui/react";
import { Box, AlertIcon, Alert, AlertTitle, useMergeRefs } from "@chakra-ui/react";
import { withErrorBoundary } from "react-error-boundary";
import { useContextMenu } from '@/utils/useContextMenu';

const ERROR_MESSAGE = "An error occurred while rendering this block.";
const ERROR_MESSAGE = <Alert ml={4} status='error'><AlertIcon /><AlertTitle>An error occurred while rendering this block.</AlertTitle></Alert>;

// Don't open the context menu on these elements
const CONTAINER_CONTEXT_MENU_FILTERED_TAGS = ["A", "BUTTON", "INPUT", "TEXTAREA", "LABEL", "VIDEO", "EMBED", "IFRAME", "IMG"];
Expand Down Expand Up @@ -52,7 +52,6 @@ const _Container = React.forwardRef(({ children, isDragging, isHidden, isSelecte
isHoveredNotChild && "is-hovered-not-child",
hasPresence ? "is-presence" : "",
].filter(Boolean).join(' ')}
display="flex"
lineHeight="2em"
position="relative"
borderRadius="0.125rem"
Expand Down
8 changes: 8 additions & 0 deletions src/js/theme/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ const components = {
color: "var(--toast-color)",
}
})
},
subtle: {
container: {
borderRadius: "md"
},
title: {
fontWeight: "normal"
},
}
}
},
Expand Down