-
Notifications
You must be signed in to change notification settings - Fork 18
Design preview for code example voting #2810
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<div class="flex flex-col items-center gap-2" ...attributes> | ||
<AnimatedContainer class="w-full"> | ||
<div class="text-sm text-gray-700 dark:text-gray-300 text-center w-full"> | ||
{{#animated-if this.tempHasVotedRecently use=this.transition duration=200}} | ||
<p class="text-teal-500 font-medium"> | ||
Thanks for your feedback! | ||
</p> | ||
{{else}} | ||
<p> | ||
Was this example helpful? | ||
</p> | ||
{{/animated-if}} | ||
</div> | ||
</AnimatedContainer> | ||
|
||
<div class="flex items-center gap-1.5 flex-wrap"> | ||
<TertiaryButton | ||
{{on "click" this.handleUpvoteButtonClick}} | ||
class={{if this.tempHasDownvoted "opacity-50 hover:opacity-100 transition-opacity duration-200"}} | ||
> | ||
<div class="flex items-center gap-1"> | ||
{{svg-jar "thumb-up" class=(concat "w-5 " (if this.tempHasUpvoted "text-teal-500" "text-gray-400 dark:text-gray-600"))}} | ||
|
||
<span class={{if this.tempHasUpvoted "text-teal-500" "text-gray-500"}}> | ||
Helpful | ||
</span> | ||
</div> | ||
|
||
<EmberTooltip @text="Your feedback helps us surface better examples." @side="bottom" @delay={{250}} /> | ||
</TertiaryButton> | ||
<TertiaryButton | ||
{{on "click" this.handleDownvoteButtonClick}} | ||
class={{if this.tempHasUpvoted "opacity-50 hover:opacity-100 transition-opacity duration-200"}} | ||
> | ||
<div class="flex items-center gap-1"> | ||
{{svg-jar "thumb-down" class=(concat "w-5 " (if this.tempHasDownvoted "text-red-600" "text-gray-400 dark:text-gray-600"))}} | ||
|
||
<span class={{if this.tempHasDownvoted "text-red-600" "text-gray-500"}}> | ||
Not helpful | ||
</span> | ||
</div> | ||
|
||
<EmberTooltip @text="Your feedback helps us identify examples that need review." @side="bottom" @delay={{250}} /> | ||
</TertiaryButton> | ||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Signature> { | ||
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; | ||
}); | ||
Comment on lines
+14
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainMissing test coverage for component logic The static analysis indicates that much of the component logic is not covered by tests. Consider adding tests for:
You can verify the current test coverage with: 🏁 Script executed: #!/bin/bash
# Check current test coverage for feedback-section component
find tests -type f -name "*feedback-section*" -o -name "*community-solution*" | xargs cat Length of output: 16787 Add targeted tests for flash message and rapid-click behavior While the existing acceptance tests cover the basic upvote/downvote toggling via UI, we still need to add focused tests for the component’s internal logic: • Test the You can place these in a new integration test under: 🧰 Tools🪛 GitHub Check: codecov/patch[warning] 23-24: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L23-L24 [warning] 26-26: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L26 [warning] 29-31: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L29-L31 [warning] 38-39: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L38-L39 [warning] 41-41: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L41 [warning] 44-46: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L44-L46 [warning] 50-52: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L50-L52 |
||
} | ||
|
||
declare module '@glint/environment-ember-loose/registry' { | ||
export default interface Registry { | ||
'CoursePage::CourseStageStep::CommunitySolutionCard::FeedbackSection': typeof CommunitySolutionCardFeedbackSectionComponent; | ||
} | ||
} | ||
Comment on lines
+11
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Missing actual vote persistence functionality The component currently only manages temporary visual state (note the
Here's a suggested enhancement to the component interface: interface Signature {
Element: HTMLDivElement;
+ Args: {
+ solution: SolutionModel;
+ metadata?: Record<string, unknown>;
+ };
} Additionally, implement actual API calls in the handlers: @action
async handleUpvoteButtonClick() {
// Existing logic for UI state...
try {
await this.args.solution.upvote(this.args.metadata);
// Success handling
} catch (error) {
// Error handling
this.tempHasUpvoted = false;
this.tempHasVotedRecently = false;
}
} 🧰 Tools🪛 GitHub Check: codecov/patch[warning] 23-24: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L23-L24 [warning] 26-26: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L26 [warning] 29-31: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L29-L31 [warning] 38-39: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L38-L39 [warning] 41-41: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L41 [warning] 44-46: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L44-L46 [warning] 50-52: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L50-L52 |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,11 +20,12 @@ | |||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
<div class="flex items-center shrink-0"> | ||||||||||||||||||||||||||||||
{{#unless (eq @solution.user this.authenticator.currentUser)}} | ||||||||||||||||||||||||||||||
{{! Remove, replace with buttons at the bottom of the card }} | ||||||||||||||||||||||||||||||
{{!-- {{#unless (eq @solution.user this.authenticator.currentUser)}} | ||||||||||||||||||||||||||||||
<CoursePage::CourseStageStep::CommunitySolutionCard::UpvoteButton @solution={{@solution}} @metadata={{@metadataForUpvote}} class="mr-2" /> | ||||||||||||||||||||||||||||||
<CoursePage::CourseStageStep::CommunitySolutionCard::DownvoteButton @solution={{@solution}} @metadata={{@metadataForDownvote}} /> | ||||||||||||||||||||||||||||||
<div class="w-px h-3 bg-gray-200 dark:bg-white/5 mx-2"></div> | ||||||||||||||||||||||||||||||
{{/unless}} | ||||||||||||||||||||||||||||||
{{/unless}} --}} | ||||||||||||||||||||||||||||||
Comment on lines
+23
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing user restriction in new feedback component The commented-out code shows the previous implementation had a condition to only show vote buttons if the solution wasn't created by the current user. This same logic should be applied to the new feedback section component to maintain consistent behavior. This restriction logic should either be:
// In content.hbs:
+{{#unless (eq @solution.user this.authenticator.currentUser)}}
<CoursePage::CourseStageStep::CommunitySolutionCard::FeedbackSection @solution={{@solution}} class="pt-6 pb-3" />
+{{/unless}} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
{{#if (gt @solution.approvedCommentsCount 0)}} | ||||||||||||||||||||||||||||||
<div class="flex items-center"> | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
The feedback section component is missing solution data
The feedback section component is added correctly, but it doesn't receive any data about the current solution. For the design preview this might be intentional, but for actual functionality, it should receive the solution data to record votes.
📝 Committable suggestion