Skip to content

Commit

Permalink
Merge pull request #2260 from tangjeff0/comments/edit-delete
Browse files Browse the repository at this point in the history
feat: enable edit and delete of comments
  • Loading branch information
tangjeff0 authored Jul 29, 2022
2 parents d50ba6b + 5ba03a0 commit 17f7bd3
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 111 deletions.
2 changes: 1 addition & 1 deletion src/cljs/athens/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
:fs/watcher nil
:presence {}
:connection-status :disconnected
:comment/show-inline-comments true})
:comment/show-comments? true})


(defn init-app-db
Expand Down
7 changes: 7 additions & 0 deletions src/cljs/athens/self_hosted/presence/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
second)))


(rf/reg-sub
:presence/current-username
:<- [:presence/current-user]
(fn [current-user _]
(:username current-user)))


(defn on-page-uid?
[page-uid [_username user]]
(= page-uid (:page/uid user)))
Expand Down
6 changes: 3 additions & 3 deletions src/cljs/athens/views/app_toolbar.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
right-open? (rf/subscribe [:right-sidebar/open])
help-open? (rf/subscribe [:help/open?])
athena-open? (rf/subscribe [:athena/open])
inline-comments (rf/subscribe [:comment/show-inline-comments?])
show-comments? (rf/subscribe [:comment/show-comments?])
route-name (rf/subscribe [:current-route/name])
theme-dark (rf/subscribe [:theme/dark])
selected-db (rf/subscribe [:db-picker/selected-db])
Expand Down Expand Up @@ -109,5 +109,5 @@
{:notificationPopover (r/as-element [notifications-popover])
:isNotificationsPopoverOpen @notificationsPopoverOpen?})
(when (comments/enabled?)
{:isShowInlineComments @inline-comments
:onClickInlineComments #(rf/dispatch [:comment/toggle-inline-comments])}))]))
{:isShowComments @show-comments?
:onClickComments #(rf/dispatch [:comment/toggle-comments])}))]))
2 changes: 1 addition & 1 deletion src/cljs/athens/views/blocks/context_menu.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

(defn handle-click-comment
[e uid]
(rf/dispatch [:comment/show-comment-textarea uid])
(rf/dispatch [:comment/show-editor uid])
(.. e preventDefault))


8 changes: 4 additions & 4 deletions src/cljs/athens/views/blocks/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@
linked-ref-open? (rf/subscribe [::linked-ref.subs/open? uid])
inline-refs-open? (rf/subscribe [::inline-refs.subs/open? uid])
feature-flags (rf/subscribe [:feature-flags])
show-inline-comments (rf/subscribe [:comment/show-inline-comments?])
show-textarea (rf/subscribe [:comment/show-comment-textarea? uid])
enable-properties? (rf/subscribe [:feature-flags/enabled? :properties])]
enable-properties? (rf/subscribe [:feature-flags/enabled? :properties])
show-comments? (rf/subscribe [:comment/show-comments?])
show-textarea (rf/subscribe [:comment/show-editor? uid])]
(fn editor-component-render
[_block-el _block-o _children? _block _linked-ref-data _uid-sanitized-block _state-hooks _opts]
(let [{:block/keys [;; uid
Expand Down Expand Up @@ -244,7 +244,7 @@
:onToggleReaction (partial toggle-reaction [:block/uid uid])}])

;; Show comments when the toggle is on
(when (and @show-inline-comments
(when (and @show-comments?
open
(or @show-textarea
(comments/get-comment-thread-uid @db/dsdb uid)))
Expand Down
37 changes: 18 additions & 19 deletions src/cljs/athens/views/comments/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,43 @@


(rf/reg-sub
:comment/show-comment-textarea?
:comment/show-editor?
(fn [db [_ uid]]
(= uid (:comment/show-comment-textarea db))))
(= uid (:comment/show-editor db))))


(rf/reg-event-fx
:comment/show-comment-textarea
:comment/show-editor
(fn [{:keys [db]} [_ uid]]
{:db (assoc db :comment/show-comment-textarea uid)}))
{:db (assoc db :comment/show-editor uid)}))


(rf/reg-event-fx
:comment/hide-comment-textarea
:comment/hide-editor
(fn [{:keys [db]} [_]]
{:db (assoc db :comment/show-comment-textarea nil)}))
{:db (assoc db :comment/show-editor nil)}))


(rf/reg-sub
:comment/show-inline-comments?
:comment/show-comments?
(fn [db [_]]
(= true (:comment/show-inline-comments db))))
(= true (:comment/show-comments? db))))


(rf/reg-event-fx
:comment/toggle-inline-comments
(fn [{:keys [db]} [_]]
(let [current-state (:comment/show-inline-comments db)]
(println "toggle inline comments" current-state)
{:db (assoc db :comment/show-inline-comments (not current-state))})))
(rf/reg-event-db
:comment/toggle-comments
(fn [db [_]]
(update db :comment/show-comments? not)))


(defn thread-child->comment
[comment-block]
(let [comment-uid (:block/uid comment-block)]
{:block/uid comment-uid
:string (:block/string comment-block)
:author (-> comment-block :block/create :event/auth :presence/id)
:time (-> comment-block :block/create :event/time :time/ts)}))
(let [{:block/keys [uid string create properties]} comment-block]
{:block/uid uid
:string string
:author (-> create :event/auth :presence/id)
:time (-> create :event/time :time/ts)
:edited? (boolean (get properties "athens/comment/edited"))}))


(defn add-is-follow-up?
Expand Down
Loading

0 comments on commit 17f7bd3

Please sign in to comment.