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

fix: new comments end up in wrong thread #2307

Merged
merged 6 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
6 changes: 3 additions & 3 deletions src/cljs/athens/views/comments/inline.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@


(defn inline-comments
[_data _uid hide?]
[_data _comment-block-uid hide?]
(when (comments.core/enabled?)
(let [hide? (r/atom hide?)
block-uid (common.utils/gen-block-uid)
value-atom (r/atom "")
show-edit-atom? (r/atom true)]
(fn [data uid _hide?]
(fn [data comment-block-uid _hide?]
(let [num-comments (count data)
username (rf/subscribe [:username])
last-comment (last data)
Expand Down Expand Up @@ -243,7 +243,7 @@
[_uid _d-key-down]
(when (not (str/blank? @value-atom))
;; Passing username because we need the username for other ops before the block is created.
(rf/dispatch [:comment/write-comment uid @value-atom @username])
(rf/dispatch [:comment/write-comment comment-block-uid @value-atom @username])
(reset! value-atom "")
(rf/dispatch [:editing/uid block-uid])))
tab-handler (fn jetsam-tab-handler
Expand Down
29 changes: 17 additions & 12 deletions src/cljs/athens/views/pages/block_page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,31 @@


(defn block-page-el
[_block]
[block]
(let [state (r/atom {:string/local nil
:string/previous nil})
properties-enabled? (rf/subscribe [:feature-flags/enabled? :properties])]

(fn [block]
(let [{:block/keys [string children uid properties] :db/keys [id]} block
show-comments? (rf/subscribe [:comment/show-comments?])
show-textarea? (rf/subscribe [:comment/show-editor? uid])]
{:block/keys [string children uid properties] :db/keys [id]} block
show-comments? (rf/subscribe [:comment/show-comments?])
show-textarea? (rf/subscribe [:comment/show-editor? uid])
is-editing? (subscribe [:editing/is-editing uid])
sid597 marked this conversation as resolved.
Show resolved Hide resolved
right-sidebar-contains-items? (subscribe [:right-sidebar/contains-item? [:block/uid uid]])
properties-enabled? (rf/subscribe [:feature-flags/enabled? :properties])]

(fn [_block]
(let [thread-uid (comments/get-comment-thread-uid @db/dsdb uid)
comments-data (comments/get-comments-in-thread @db/dsdb thread-uid)]
(when (not= string (:string/previous @state))
(swap! state assoc :string/previous string :string/local string))

[:> Box

;; Header
[:> PageHeader {:onClickOpenInSidebar (when-not @(subscribe [:right-sidebar/contains-item? [:block/uid uid]])
[:> PageHeader {:onClickOpenInSidebar (when-not @right-sidebar-contains-items?
#(dispatch [:right-sidebar/open-item [:block/uid uid]]))}

;; Parent Context
[parents-el uid id]
[:> TitleContainer {:isEditing @(subscribe [:editing/is-editing uid])
[:> TitleContainer {:isEditing @is-editing?
:onClick (fn [e]
(.. e preventDefault)
(if (.. e -shiftKey)
Expand All @@ -127,7 +131,7 @@
(dispatch [:editing/uid uid])))}
[autosize/textarea
{:value (:string/local @state)
:class (when @(subscribe [:editing/is-editing uid]) "is-editing")
:class (when @is-editing? "is-editing")
:id (str "editable-uid-" uid)
;; :auto-focus true
:on-blur (fn [_]
Expand All @@ -145,8 +149,9 @@
:w "100%"}
(when (or @show-textarea?
(and @show-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])]
thread-uid))
^{:key uid}
[inline-comments/inline-comments comments-data uid false])]

;; Properties
(when (and @properties-enabled?
Expand Down