Skip to content

Commit

Permalink
Merge pull request #2248 from sid597/comments-bug-fix
Browse files Browse the repository at this point in the history
fix: bug in comments
  • Loading branch information
neotyk authored Jul 14, 2022
2 parents 381ffe2 + 5a22d1a commit f2ee1b3
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 82 deletions.
11 changes: 7 additions & 4 deletions src/cljs/athens/views/blocks/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@
uid (:block/uid block-o)
linked-ref-open? (rf/subscribe [::linked-ref.subs/open? uid])
inline-refs-open? (rf/subscribe [::inline-refs.subs/open? uid])
selected-items (rf/subscribe [::select-subs/items])]
selected-items (rf/subscribe [::select-subs/items])
show-inline-comments (rf/subscribe [:comment/show-inline-comments?])
show-textarea (rf/subscribe [:comment/show-comment-textarea? 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 @@ -224,9 +226,10 @@
[content/block-content-el block-o state-hooks]

;; Show comments when the toggle is on
(when (or @(rf/subscribe [:comment/show-comment-textarea? uid])
(and @(rf/subscribe [:comment/show-inline-comments?])
(comments/get-comment-thread-uid @db/dsdb uid)))
(when (and open
(or @show-textarea
(and @show-inline-comments
(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]
Expand Down
156 changes: 78 additions & 78 deletions src/cljs/athens/views/comments/inline.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -85,89 +85,89 @@


(defn inline-comments
[data _uid hide?]
[_data _uid hide?]
;; TODO : Remove this state
(when (comments.core/enabled?)
(let [state (reagent.core/atom {:hide? hide?})
num-comments (count data)
block-uid (common.utils/gen-block-uid)
value-atom (r/atom "")
show-edit-atom? (r/atom false)]
(fn [data uid]
[:> VStack (merge
(when-not (:hide? @state)
{:bg "background.upper"})
{:gridArea "comments"
:color "foreground.secondary"
:flex "1 0 auto"
:spacing 0
:borderRadius "md"
:align "stretch"})
;; add time, author, and preview
[:> Button (merge
(when-not (:hide? @state)
{:bg "background.upper"
:borderColor "transparent"
:borderBottomRadius 0})
{:justifyContent "flex-start"
:color "foreground.secondary"
:variant "outline"
:size "sm"
:gap 2
:flex "1 0 auto"
:onClick #(swap! state update :hide? not)})
(if (:hide? @state)
[:<>
[:> ChevronRightIcon]
[:> CommentCounter {:count num-comments}]
[:> Text "Comments"]]
[:<>
[:> ChevronDownIcon]
[:> CommentCounter {:count num-comments}]
[:> Text "Comments"]])]
(fn [data uid _hide?]
(let [num-comments (count data)]
[:> VStack (merge
(when-not (:hide? @state)
{:bg "background.upper"})
{:gridArea "comments"
:color "foreground.secondary"
:flex "1 0 auto"
:spacing 0
:borderRadius "md"
:align "stretch"})
;; add time, author, and preview
[:> Button (merge
(when-not (:hide? @state)
{:bg "background.upper"
:borderColor "transparent"
:borderBottomRadius 0})
{:justifyContent "flex-start"
:color "foreground.secondary"
:variant "outline"
:size "sm"
:gap 2
:flex "1 0 auto"
:onClick #(swap! state update :hide? not)})
(if (:hide? @state)
[:<>
[:> ChevronRightIcon]
[:> CommentCounter {:count num-comments}]
[:> Text "Comments"]]
[:<>
[:> ChevronDownIcon]
[:> CommentCounter {:count num-comments}]
[:> Text "Comments"]])]

(when-not (:hide? @state)
[:> Box {:pl 8
:pr 4
:pb 4}
(for [item data]
^{:key item}
[comment-el item])
(when-not (:hide? @state)
[:> Box {:pl 8
:pr 4
:pb 4}
(for [item data]
^{:key item}
[comment-el item])

(let [block-o {:block/uid block-uid
;; :block/string @value-atom
:block/children []}
save-fn #(reset! value-atom %)
enter-handler (fn jetsam-enter-handler
[_uid _d-key-down]
(when (not (str/blank? @value-atom))
(re-frame.core/dispatch [:comment/write-comment uid @value-atom])
(reset! value-atom "")
(rf/dispatch [:editing/uid block-uid])))
tab-handler (fn jetsam-tab-handler
[_uid _embed-id _d-key-down])
backspace-handler (fn jetsam-backspace-handler
[_uid _value])
delete-handler (fn jetsam-delete-handler
[_uid _d-key-down])
state-hooks {:save-fn #(println "save-fn" (pr-str %))
:update-fn #(save-fn %)
:idle-fn #(println "idle-fn" (pr-str %))
:read-value value-atom
:show-edit? show-edit-atom?
:enter-handler enter-handler
:tab-handler tab-handler
:backspace-handler backspace-handler
:delete-handler delete-handler
:default-verbatim-paste? true
:keyboard-navigation? false
:placeholder "Write your comment here"}]
(rf/dispatch [:editing/uid block-uid])
[:> Box {:px 2
:mt 2
:minHeight "2.125em"
:borderRadius "sm"
:bg "background.attic"
:cursor "text"
:_focusWithin {:shadow "focus"}}
[b-content/block-content-el block-o state-hooks]])])]))))
(let [block-o {:block/uid block-uid
;; :block/string @value-atom
:block/children []}
save-fn #(reset! value-atom %)
enter-handler (fn jetsam-enter-handler
[_uid _d-key-down]
(when (not (str/blank? @value-atom))
(re-frame.core/dispatch [:comment/write-comment uid @value-atom])
(reset! value-atom "")
(rf/dispatch [:editing/uid block-uid])))
tab-handler (fn jetsam-tab-handler
[_uid _embed-id _d-key-down])
backspace-handler (fn jetsam-backspace-handler
[_uid _value])
delete-handler (fn jetsam-delete-handler
[_uid _d-key-down])
state-hooks {:save-fn #(println "save-fn" (pr-str %))
:update-fn #(save-fn %)
:idle-fn #(println "idle-fn" (pr-str %))
:read-value value-atom
:show-edit? show-edit-atom?
:enter-handler enter-handler
:tab-handler tab-handler
:backspace-handler backspace-handler
:delete-handler delete-handler
:default-verbatim-paste? true
:keyboard-navigation? false
:placeholder "Write your comment here"}]
(rf/dispatch [:editing/uid block-uid])
[:> Box {:px 2
:mt 2
:minHeight "2.125em"
:borderRadius "sm"
:bg "background.attic"
:cursor "text"
:_focusWithin {:shadow "focus"}}
[b-content/block-content-el block-o state-hooks]])])])))))

0 comments on commit f2ee1b3

Please sign in to comment.