From c4f2f9209a87f0fcf2ba12c4008a4575e02c01bc Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Tue, 22 Apr 2025 17:25:30 -0700 Subject: [PATCH] feat: add feedback section with upvote/downvote functionality refactor(feedback): increase animation duration for voting feedback fix: improve feedback section text clarity and consistency feat: add tooltips to feedback buttons for clarity feat(tooltip): add delay to tooltips for improved usability --- .../community-solution-card/content.hbs | 4 +- .../feedback-section.hbs | 46 +++++++++++++++ .../feedback-section.ts | 59 +++++++++++++++++++ .../community-solution-card/header.hbs | 5 +- 4 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 app/components/course-page/course-stage-step/community-solution-card/feedback-section.hbs create mode 100644 app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts diff --git a/app/components/course-page/course-stage-step/community-solution-card/content.hbs b/app/components/course-page/course-stage-step/community-solution-card/content.hbs index cb676ac9b2..8cc57ef80d 100644 --- a/app/components/course-page/course-stage-step/community-solution-card/content.hbs +++ b/app/components/course-page/course-stage-step/community-solution-card/content.hbs @@ -84,4 +84,6 @@ -{{/each}} \ No newline at end of file +{{/each}} + + \ No newline at end of file diff --git a/app/components/course-page/course-stage-step/community-solution-card/feedback-section.hbs b/app/components/course-page/course-stage-step/community-solution-card/feedback-section.hbs new file mode 100644 index 0000000000..5cbb61bdd8 --- /dev/null +++ b/app/components/course-page/course-stage-step/community-solution-card/feedback-section.hbs @@ -0,0 +1,46 @@ +
+ +
+ {{#animated-if this.tempHasVotedRecently use=this.transition duration=200}} +

+ Thanks for your feedback! +

+ {{else}} +

+ Was this example helpful? +

+ {{/animated-if}} +
+
+ +
+ +
+ {{svg-jar "thumb-up" class=(concat "w-5 " (if this.tempHasUpvoted "text-teal-500" "text-gray-400 dark:text-gray-600"))}} + + + Helpful + +
+ + +
+ +
+ {{svg-jar "thumb-down" class=(concat "w-5 " (if this.tempHasDownvoted "text-red-600" "text-gray-400 dark:text-gray-600"))}} + + + Not helpful + +
+ + +
+
+
\ No newline at end of file diff --git a/app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts b/app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts new file mode 100644 index 0000000000..d266c8bcf2 --- /dev/null +++ b/app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts @@ -0,0 +1,59 @@ +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import { task, timeout } from 'ember-concurrency'; +import fade from 'ember-animated/transitions/fade'; +import { action } from '@ember/object'; + +interface Signature { + Element: HTMLDivElement; +} + +export default class CommunitySolutionCardFeedbackSectionComponent extends Component { + transition = fade; + + @tracked tempHasVotedRecently = false; + @tracked tempHasUpvoted = false; + @tracked tempHasDownvoted = false; + + @action + handleDownvoteButtonClick() { + // No feedback if the user is "reversing" their vote + if (this.tempHasDownvoted) { + this.tempHasDownvoted = false; + this.tempHasVotedRecently = false; + + return; + } + + this.flashSuccessMessageTask.perform(); + this.tempHasUpvoted = false; + this.tempHasDownvoted = true; + } + + @action + handleUpvoteButtonClick() { + // No feedback if the user is "reversing" their vote + if (this.tempHasUpvoted) { + this.tempHasUpvoted = false; + this.tempHasVotedRecently = false; + + return; + } + + this.flashSuccessMessageTask.perform(); + this.tempHasDownvoted = false; + this.tempHasUpvoted = true; + } + + flashSuccessMessageTask = task({ keepLatest: true }, async () => { + this.tempHasVotedRecently = true; + await timeout(1500); + this.tempHasVotedRecently = false; + }); +} + +declare module '@glint/environment-ember-loose/registry' { + export default interface Registry { + 'CoursePage::CourseStageStep::CommunitySolutionCard::FeedbackSection': typeof CommunitySolutionCardFeedbackSectionComponent; + } +} diff --git a/app/components/course-page/course-stage-step/community-solution-card/header.hbs b/app/components/course-page/course-stage-step/community-solution-card/header.hbs index bda8b6756b..55633511ca 100644 --- a/app/components/course-page/course-stage-step/community-solution-card/header.hbs +++ b/app/components/course-page/course-stage-step/community-solution-card/header.hbs @@ -20,11 +20,12 @@
- {{#unless (eq @solution.user this.authenticator.currentUser)}} + {{! Remove, replace with buttons at the bottom of the card }} + {{!-- {{#unless (eq @solution.user this.authenticator.currentUser)}}
- {{/unless}} + {{/unless}} --}} {{#if (gt @solution.approvedCommentsCount 0)}}