Skip to content

Commit

Permalink
Merge pull request #1662 from filipesilva/block-presence
Browse files Browse the repository at this point in the history
block presence rework
  • Loading branch information
filipesilva authored Sep 21, 2021
2 parents b020676 + cf28c9f commit 4e1e6a0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 42 deletions.
26 changes: 2 additions & 24 deletions src/cljs/athens/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -743,39 +743,17 @@
{:fx [[:dispatch [:alert/js "Redo not supported in Lan-Party, yet."]]]}))))


(defn prev-block-uid-without-presence-recursively
"base case: prev block
recursive case: keep going until no longer present"
[uid]
(let [prev-block-uid (db/prev-block-uid uid)
has-presence? @(subscribe [:presence/has-presence prev-block-uid])]
(if (and prev-block-uid
has-presence?)
(prev-block-uid-without-presence-recursively prev-block-uid)
prev-block-uid)))


(reg-event-fx
:up
(fn [_ [_ uid]]
(let [prev-block-uid (prev-block-uid-without-presence-recursively uid)]
(let [prev-block-uid (db/prev-block-uid uid)]
{:dispatch [:editing/uid (or prev-block-uid uid)]})))


(defn next-block-uid-without-presence-recursively
[uid]
(let [next-block-uid (db/next-block-uid uid)
has-presence? @(subscribe [:presence/has-presence next-block-uid])]
(if (and next-block-uid
has-presence?)
(next-block-uid-without-presence-recursively next-block-uid)
next-block-uid)))


(reg-event-fx
:down
(fn [_ [_ uid]]
(let [next-block-uid (next-block-uid-without-presence-recursively uid)]
(let [next-block-uid (db/next-block-uid uid)]
{:dispatch [:editing/uid (or next-block-uid uid)]})))


Expand Down
9 changes: 4 additions & 5 deletions src/cljs/athens/self_hosted/presence/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@
:presence/has-presence
:<- [:presence/users-with-page-data]
(fn [users [_ uid]]
(-> (filter (fn [[_username user]]
(= uid (:block/uid user)))
users)
first
second)))
(keep (fn [[_username user]]
(when (= uid (:block/uid user))
user))
users)))
23 changes: 12 additions & 11 deletions src/cljs/athens/self_hosted/presence/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,16 @@

(defn inline-presence-el
[uid]
(let [inline-present? (rf/subscribe [:presence/has-presence uid])]
(when @inline-present?
[:> (.-Stack Avatar)
{:size "1.25rem"
:maskSize "1px"
:stackOrder "from-left"
:limit 3
:style {:transform "translateX(calc(-100% + 1rem)) translateY(0.35rem)"
:padding "0.125rem"
:background "var(--background-color)"}}
[:> Avatar (merge {:showTooltip false} @inline-present?)]])))
(let [users (rf/subscribe [:presence/has-presence uid])]
(when (seq @users)
(into
[:> (.-Stack Avatar)
{:size "1.25rem"
:maskSize "1px"
:stackOrder "from-left"
:limit 3
:style {:transform "translateX(calc(-100% + 1rem)) translateY(0.35rem)"
:padding "0.125rem"
:background "var(--background-color)"}}]
(map (fn [x] [:> Avatar (merge {:showTooltip false :key (:username x)} x)]) @users)))))

4 changes: 2 additions & 2 deletions src/cljs/athens/views/blocks/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@
is-editing @(rf/subscribe [:editing/is-editing uid])
is-selected @(rf/subscribe [::select-subs/selected? uid])
present-user @(rf/subscribe [:presence/has-presence uid])
is-presence (not (nil? present-user))]
is-presence (seq present-user)]

;; (prn uid is-selected)

Expand Down Expand Up @@ -369,7 +369,7 @@
[context-menu/context-menu-el uid-sanitized-block state])
[bullet/bullet-el block state linked-ref]
[tooltip/tooltip-el uid-sanitized-block state]
[content/block-content-el block state is-presence]
[content/block-content-el block state]

[presence/inline-presence-el uid]

Expand Down

1 comment on commit 4e1e6a0

@vercel
Copy link

@vercel vercel bot commented on 4e1e6a0 Sep 21, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.