From 5a0c875885be899bf949b7eb152242cb59918123 Mon Sep 17 00:00:00 2001 From: Natalie Tay Date: Tue, 25 Mar 2025 17:14:02 +0800 Subject: [PATCH] FEATURE: Show 'marked solved by' in OP when topic is solved (#343) Depends on: https://github.com/discourse/discourse-solved/pull/342 This feature adds the "Marked solved as" information to the solved post appended to OP. Originally, I had moved the widget usage to a [component](https://github.com/discourse/discourse-solved/blob/39baa0be4a889fdbff108e887a677d9a298d27d4/assets/javascripts/discourse/components/solved-post.gjs), but due to "cooking quotes", after some internal discussion (t/95318/25) we will stick to widgets for now as the post-stream gets modernized. --- .../solved-accept-answer-button.gjs | 10 ++-- .../initializers/extend-for-solved-button.js | 52 +++++++++++-------- assets/stylesheets/solutions.scss | 33 +++++++++++- config/locales/client.en.yml | 1 + .../topic_view_serializer_extension.rb | 47 +++++++++-------- spec/requests/topics_controller_spec.rb | 7 ++- spec/system/solved_spec.rb | 35 +++++++++++++ .../helpers/discourse-solved-helpers.js | 8 ++- 8 files changed, 139 insertions(+), 54 deletions(-) create mode 100644 spec/system/solved_spec.rb diff --git a/assets/javascripts/discourse/components/solved-accept-answer-button.gjs b/assets/javascripts/discourse/components/solved-accept-answer-button.gjs index aa885ba..6141336 100644 --- a/assets/javascripts/discourse/components/solved-accept-answer-button.gjs +++ b/assets/javascripts/discourse/components/solved-accept-answer-button.gjs @@ -19,7 +19,7 @@ export default class SolvedAcceptAnswerButton extends Component { @action acceptAnswer() { - acceptAnswer(this.args.post, this.appEvents); + acceptAnswer(this.args.post, this.appEvents, this.currentUser); } } -export function acceptAnswer(post, appEvents) { +export function acceptAnswer(post, appEvents, acceptingUser) { // TODO (glimmer-post-menu): Remove this exported function and move the code into the button action after the widget code is removed - acceptPost(post); + acceptPost(post, acceptingUser); appEvents.trigger("discourse-solved:solution-toggled", post); @@ -46,7 +46,7 @@ export function acceptAnswer(post, appEvents) { }); } -function acceptPost(post) { +function acceptPost(post, acceptingUser) { const topic = post.topic; clearAccepted(topic); @@ -62,6 +62,8 @@ function acceptPost(post) { name: post.name, post_number: post.post_number, excerpt: post.cooked, + accepter_username: acceptingUser.username, + accepter_name: acceptingUser.name, }); ajax("/solution/accept", { diff --git a/assets/javascripts/discourse/initializers/extend-for-solved-button.js b/assets/javascripts/discourse/initializers/extend-for-solved-button.js index 3130262..bb5eead 100644 --- a/assets/javascripts/discourse/initializers/extend-for-solved-button.js +++ b/assets/javascripts/discourse/initializers/extend-for-solved-button.js @@ -36,30 +36,24 @@ function initializeWithApi(api) { const topic = postModel.topic; if (topic.accepted_answer) { const hasExcerpt = !!topic.accepted_answer.excerpt; - - const withExcerpt = ` -