Skip to content

Commit eb19b4a

Browse files
committed
Add design preview
1 parent 0813f20 commit eb19b4a

File tree

6 files changed

+122
-4
lines changed

6 files changed

+122
-4
lines changed

app/components/course-admin/code-example-page/evaluation-card/prompt-tab.hbs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<TertiaryButton class="mb-4" {{on "click" this.handleCopyPromptButtonClick}}>
2+
Copy prompt
3+
</TertiaryButton>
4+
15
<div class="bg-gray-800 border border-gray-700 rounded overflow-y-auto relative flex-grow p-3">
26
{{#if @evaluation.promptFileContents}}
37
<pre class="font-mono text-xs text-white whitespace-pre-wrap"><code>{{ansi-to-html @evaluation.promptFileContents}}</code></pre>

app/components/course-admin/code-example-page/evaluation-card/prompt-tab.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { action } from '@ember/object';
12
import Component from '@glimmer/component';
23
import type CommunitySolutionEvaluationModel from 'codecrafters-frontend/models/community-solution-evaluation';
34

@@ -9,7 +10,16 @@ export interface Signature {
910
};
1011
}
1112

12-
export default class PromptTabComponent extends Component<Signature> {}
13+
export default class PromptTabComponent extends Component<Signature> {
14+
@action
15+
handleCopyPromptButtonClick() {
16+
if (this.args.evaluation.promptFileContents) {
17+
navigator.clipboard.writeText(this.args.evaluation.promptFileContents);
18+
} else {
19+
alert('Error, contact us at [email protected] if this keeps happening!');
20+
}
21+
}
22+
}
1323

1424
declare module '@glint/environment-ember-loose/registry' {
1525
export default interface Registry {

app/components/course-page/course-stage-step/community-solution-card/content.hbs

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,6 @@
8484
</div>
8585
</:header>
8686
</FileContentsCard>
87-
{{/each}}
87+
{{/each}}
88+
89+
<CoursePage::CourseStageStep::CommunitySolutionCard::FeedbackSection class="pt-6 pb-3" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<div class="flex flex-col items-center gap-2" ...attributes>
2+
<AnimatedContainer class="w-full">
3+
<div class="text-sm text-gray-700 dark:text-gray-300 text-center w-full">
4+
{{#animated-if this.tempHasVotedRecently use=this.transition duration=100}}
5+
<p class="text-teal-500 font-medium">
6+
Thanks for your feedback!
7+
</p>
8+
{{else}}
9+
<p>
10+
Was this helpful?
11+
</p>
12+
{{/animated-if}}
13+
</div>
14+
</AnimatedContainer>
15+
16+
<div class="flex items-center gap-1.5 flex-wrap">
17+
<TertiaryButton
18+
{{on "click" this.handleUpvoteButtonClick}}
19+
class={{if this.tempHasDownvoted "opacity-50 hover:opacity-100 transition-opacity duration-100"}}
20+
>
21+
<div class="flex items-center gap-1">
22+
{{svg-jar "thumb-up" class=(concat "w-5 " (if this.tempHasUpvoted "text-teal-500" "text-gray-400 dark:text-gray-600"))}}
23+
24+
<span class={{if this.tempHasUpvoted "text-teal-500" "text-gray-500"}}>
25+
Yes
26+
</span>
27+
</div>
28+
</TertiaryButton>
29+
<TertiaryButton
30+
{{on "click" this.handleDownvoteButtonClick}}
31+
class={{if this.tempHasUpvoted "opacity-50 hover:opacity-100 transition-opacity duration-100"}}
32+
>
33+
<div class="flex items-center gap-1">
34+
{{svg-jar "thumb-down" class=(concat "w-5 " (if this.tempHasDownvoted "text-red-600" "text-gray-400 dark:text-gray-600"))}}
35+
36+
<span class={{if this.tempHasDownvoted "text-red-600" "text-gray-500"}}>
37+
No
38+
</span>
39+
</div>
40+
</TertiaryButton>
41+
</div>
42+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import Component from '@glimmer/component';
2+
import { tracked } from '@glimmer/tracking';
3+
import { task, timeout } from 'ember-concurrency';
4+
import fade from 'ember-animated/transitions/fade';
5+
import { action } from '@ember/object';
6+
7+
interface Signature {
8+
Element: HTMLDivElement;
9+
}
10+
11+
export default class CommunitySolutionCardFeedbackSectionComponent extends Component<Signature> {
12+
transition = fade;
13+
14+
@tracked tempHasVotedRecently = false;
15+
@tracked tempHasUpvoted = false;
16+
@tracked tempHasDownvoted = false;
17+
18+
@action
19+
handleDownvoteButtonClick() {
20+
// No feedback if the user is "reversing" their vote
21+
if (this.tempHasDownvoted) {
22+
this.tempHasDownvoted = false;
23+
this.tempHasVotedRecently = false;
24+
25+
return;
26+
}
27+
28+
this.flashSuccessMessageTask.perform();
29+
this.tempHasUpvoted = false;
30+
this.tempHasDownvoted = true;
31+
}
32+
33+
@action
34+
handleUpvoteButtonClick() {
35+
// No feedback if the user is "reversing" their vote
36+
if (this.tempHasUpvoted) {
37+
this.tempHasUpvoted = false;
38+
this.tempHasVotedRecently = false;
39+
40+
return;
41+
}
42+
43+
this.flashSuccessMessageTask.perform();
44+
this.tempHasDownvoted = false;
45+
this.tempHasUpvoted = true;
46+
}
47+
48+
flashSuccessMessageTask = task({ keepLatest: true }, async () => {
49+
this.tempHasVotedRecently = true;
50+
await timeout(2000);
51+
this.tempHasVotedRecently = false;
52+
});
53+
}
54+
55+
declare module '@glint/environment-ember-loose/registry' {
56+
export default interface Registry {
57+
'CoursePage::CourseStageStep::CommunitySolutionCard::FeedbackSection': typeof CommunitySolutionCardFeedbackSectionComponent;
58+
}
59+
}

app/components/course-page/course-stage-step/community-solution-card/header.hbs

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
</div>
2121

2222
<div class="flex items-center shrink-0">
23-
{{#unless (eq @solution.user this.authenticator.currentUser)}}
23+
{{! Remove, replace with buttons at the bottom of the card }}
24+
{{!-- {{#unless (eq @solution.user this.authenticator.currentUser)}}
2425
<CoursePage::CourseStageStep::CommunitySolutionCard::UpvoteButton @solution={{@solution}} @metadata={{@metadataForUpvote}} class="mr-2" />
2526
<CoursePage::CourseStageStep::CommunitySolutionCard::DownvoteButton @solution={{@solution}} @metadata={{@metadataForDownvote}} />
2627
<div class="w-px h-3 bg-gray-200 dark:bg-white/5 mx-2"></div>
27-
{{/unless}}
28+
{{/unless}} --}}
2829

2930
{{#if (gt @solution.approvedCommentsCount 0)}}
3031
<div class="flex items-center">

0 commit comments

Comments
 (0)