Skip to content

Commit

Permalink
Merge pull request #2139 from shanberg/fix-issues-4
Browse files Browse the repository at this point in the history
- Fix more update issues
  • Loading branch information
shanberg authored Apr 14, 2022
2 parents f57a3c4 + 43b2b0b commit ffaa0a3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
21 changes: 10 additions & 11 deletions src/cljs/athens/components.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns athens.components
(:require
["/components/Icons/Icons" :refer [PencilIcon]]
["@chakra-ui/react" :refer [Checkbox Box IconButton Button]]
["@chakra-ui/react" :refer [Checkbox Box IconButton Button ButtonGroup]]
[athens.db :as db]
[athens.parse-renderer :refer [component]]
[athens.reactive :as reactive]
Expand Down Expand Up @@ -86,8 +86,12 @@
(r/with-let [embed-id (random-uuid)]
[:> Box {:class "block-embed"
:bg "background.basement"
:flex 1
:pr 1
:position "relative"
:display "flex"
:sx {"> .block-container" {:ml 0
:flex 1
:pr "1.3rem"
"textarea" {:background "transparent"}}}}
(let [block (reactive/get-reactive-block-document [:block/uid block-uid])]
Expand All @@ -97,16 +101,11 @@
{:linked-ref false}
{:block-embed? true}]
(when-not @(subscribe [:editing/is-editing uid])
[:> IconButton {:position "absolute"
:right 1
:top 1
:size "xs"
:fontSize "1rem"
:zIndex "5"
:on-click (fn [e]
(.. e stopPropagation)
(dispatch [:editing/uid uid]))}
[:> PencilIcon]])])])
[:> ButtonGroup {:height "2em" :size "xs" :flex "0 0 auto" :zIndex "5" :alignItems "center"}
[:> IconButton {:on-click (fn [e]
(.. e stopPropagation)
(dispatch [:editing/uid uid]))}
[:> PencilIcon]]])])])
;; roam actually hides the brackets around [[embed]]
[:span "{{" content "}}"])))

Expand Down
6 changes: 5 additions & 1 deletion src/cljs/athens/views/blocks/context_menu.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
(str "((" uid "))")
(->> (map (fn [uid] (str "((" uid "))\n")) selected-items)
(string/join "")))]
(println selected-items)
(println data)
(.. js/navigator -clipboard (writeText data))
(toast (clj->js {:title "Copied ref to clipboard"}))))
(toast (clj->js {:title (if (> (count selected-items) 1)
"Copied refs to clipboard"
"Copied ref to clipboard")}))))


(defn handle-copy-unformatted
Expand Down
13 changes: 10 additions & 3 deletions src/cljs/athens/views/blocks/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@
block)
{:keys [dragging]} @state
is-selected @(rf/subscribe [::select-subs/selected? uid])
selected-items @(rf/subscribe [::select-subs/items])
present-user @(rf/subscribe [:presence/has-presence uid])
is-presence (seq present-user)]

Expand All @@ -339,6 +340,8 @@
(when (not= string (:string/previous @state))
(swap! state assoc :string/previous string :string/local string))

(println selected-items)

[:> Container {:isDragging (and dragging (not is-selected))
:isSelected is-selected
:hasChildren (seq children)
Expand Down Expand Up @@ -375,11 +378,15 @@
(or (and (true? linked-ref) (not (:linked-ref/open @state)))
(and (false? linked-ref) (not open))))
"closed-with-children")
:block block
:uidSanitizedBlock uid-sanitized-block
:shouldShowDebugDetails (util/re-frame-10x-open?)
:onCopyRef #(handle-copy-refs nil uid)
:onCopyUnformatted #(handle-copy-unformatted uid)
:menuActions (clj->js [{:children
(if (> (count selected-items) 1)
"Copy selected block refs"
"Copy block ref")
:onClick #(handle-copy-refs nil uid)}
{:children "Copy unformatted text"
:onClick #(handle-copy-unformatted uid)}])
:onClick (fn [e]
(let [shift? (.-shiftKey e)]
(rf/dispatch [:reporting/navigation {:source :block-bullet
Expand Down
7 changes: 6 additions & 1 deletion src/cljs/athens/views/blocks/textarea_keydown.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[athens.events.selection :as select-events]
[athens.router :as router]
[athens.subs.selection :as select-subs]
[athens.util :as util :refer [scroll-if-needed shortcut-key? escape-str]]
[athens.util :as util :refer [scroll-if-needed get-caret-position shortcut-key? escape-str]]
[athens.views.blocks.internal-representation :as internal-representation]
[clojure.string :refer [replace-first blank? includes? lower-case]]
[goog.dom :refer [getElement]]
Expand Down Expand Up @@ -818,6 +818,11 @@
(swap! state assoc :last-keydown d-event)
(swap! state assoc :last-e e)

;; update caret position for search dropdowns and for up/down
(when (nil? (:search/type @state))
(let [caret-position (get-caret-position (.. e -target))]
(swap! state assoc :caret-position caret-position)))

;; dispatch center
;; only when nothing is selected or duplicate/events dispatched
;; after some ops(like delete) can cause errors
Expand Down
19 changes: 11 additions & 8 deletions src/js/components/Block/components/Anchor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface AnchorProps {
onDragStart: () => void;
onDragEnd: () => void;
onClick: () => void;
menuActions: any;
}

const anchorButtonStyleProps = (isClosedWithChildren) => {
Expand Down Expand Up @@ -138,13 +139,11 @@ export const Anchor = (props: AnchorProps) => {
const { isClosedWithChildren,
anchorElement,
shouldShowDebugDetails,
onCopyRef,
onCopyUnformatted,
onDragStart,
onDragEnd,
onClick,
block,
uidSanitizedBlock,
menuActions,
} = props;

// Early return with just the button, to avoid rendering the menu
Expand Down Expand Up @@ -189,12 +188,16 @@ export const Anchor = (props: AnchorProps) => {
</IconButton>
<Portal
>
<MenuList>
<MenuItem onClick={onCopyRef}>Copy block refs</MenuItem>
<MenuItem onClick={onCopyUnformatted}>Copy unformatted</MenuItem>
<MenuList
// prevent changing selection when clicking on the menu
onMouseDown={(e) => e.stopPropagation()}
>
{menuActions.map((action) => {
return <MenuItem {...action} />
})}
{shouldShowDebugDetails && (
<>
<MenuDivider />
{menuActions && <MenuDivider />}
<MenuGroup title="Debug details">
<Box px={4} pb={3}>
{propertiesList(uidSanitizedBlock)}
Expand All @@ -203,6 +206,6 @@ export const Anchor = (props: AnchorProps) => {
</>)}
</MenuList>
</Portal>
</Menu>
</Menu >
)
};

0 comments on commit ffaa0a3

Please sign in to comment.