Skip to content

Commit

Permalink
Prepare for the Stage 2 Solutions experiment [percy]
Browse files Browse the repository at this point in the history
  • Loading branch information
andy1li committed Nov 13, 2024
1 parent 748991a commit bb77881
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@courseStage={{@courseStage}}
@isComplete={{this.implementSolutionStepIsComplete}}
@shouldRecommendLanguageGuide={{@shouldRecommendLanguageGuide}}
@shouldShowSolution={{@shouldShowSolution}}
/>
{{else if (eq stepList.expandedStep.id "run-tests")}}
<CoursePage::CourseStageStep::SecondStageInstructionsCard::RunTestsStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface Signature {
repository: RepositoryModel;
courseStage: CourseStageModel;
shouldRecommendLanguageGuide: boolean;
shouldShowSolution: boolean;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<p>
Head over to your editor / IDE and implement your solution.
</p>

<p>
{{#if @shouldRecommendLanguageGuide}}
If you want a quick look at what functions to use or how to structure your code, we recommend looking at
Expand All @@ -15,4 +16,36 @@
tab.
{{/if}}
</p>
</div>
</div>

{{#if (and @shouldShowSolution this.solution)}}
<BlurredOverlay @isBlurred={{this.solutionIsBlurred}}>
<:content>
<div class="flex flex-col gap-4 my-3">
{{#each this.solution.changedFiles as |changedFile|}}
{{! Extra if condition convinces typescript that solution isn't null }}
{{#if this.solution}}
<FileDiffCard @filename={{changedFile.filename}} @code={{changedFile.diff}} @language={{this.solution.language.slug}} />
{{/if}}
{{/each}}
</div>

{{#if @shouldRecommendLanguageGuide}}
<p class="prose dark:prose-invert prose-compact">
For a more detailed explanation on how this solution works, view the
<a href="#language-guide-card">{{@repository.language.name}} Guide</a>
card.
</p>
{{/if}}
</:content>

<:overlay>
<PrimaryButton {{on "click" this.toggleSolution}} class="self-center">
<div class="flex items-center gap-2">
{{svg-jar "eye" class="size-6"}}
<span>Reveal Solution</span>
</div>
</PrimaryButton>
</:overlay>
</BlurredOverlay>
{{/if}}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Component from '@glimmer/component';
import type RepositoryModel from 'codecrafters-frontend/models/repository';
import type CourseStageModel from 'codecrafters-frontend/models/course-stage';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

interface Signature {
Element: HTMLDivElement;
Expand All @@ -10,10 +12,26 @@ interface Signature {
courseStage: CourseStageModel;
isComplete: boolean;
shouldRecommendLanguageGuide: boolean;
shouldShowSolution: boolean;
};
}

export default class ImplementSolutionStepComponent extends Component<Signature> {}
export default class ImplementSolutionStepComponent extends Component<Signature> {
@tracked solutionIsBlurred = true;

Check warning on line 21 in app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.ts

View check run for this annotation

Codecov / codecov/patch

app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.ts#L21

Added line #L21 was not covered by tests
get solution() {
return this.args.repository.secondStageSolution;
}

Check warning on line 24 in app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.ts

View check run for this annotation

Codecov / codecov/patch

app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.ts#L24

Added line #L24 was not covered by tests

@action
toggleSolution() {
if (this.solutionIsBlurred) {
this.solution?.createView();
}

Check warning on line 30 in app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.ts

View check run for this annotation

Codecov / codecov/patch

app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.ts#L30

Added line #L30 was not covered by tests

this.solutionIsBlurred = !this.solutionIsBlurred;
}

Check warning on line 33 in app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.ts

View check run for this annotation

Codecov / codecov/patch

app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.ts#L33

Added line #L33 was not covered by tests
}

declare module '@glint/environment-ember-loose/registry' {
export default interface Registry {
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/course/stage/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ export default class CourseStageInstructionsController extends Controller {
}

get shouldShowLanguageGuide() {
return !this.model.courseStage.isFirst && !!this.languageGuide && this.featureFlags.canSeeLanguageGuidesForStage2;
return !this.model.courseStage.isFirst && !!this.languageGuide;
}

get shouldShowPrerequisites() {
return !!this.prerequisiteInstructionsMarkdown;
}

get shouldShowSolution() {
return this.featureFlags.canSeeSolutionsForStage2;
}

get shouldShowTestRunnerCard() {
return this.isCurrentStage && this.currentStep.status !== 'complete';
}
Expand Down
7 changes: 6 additions & 1 deletion app/models/course-stage-solution.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import Model, { attr, belongsTo } from '@ember-data/model';
import { service } from '@ember/service';
import ViewableMixin from 'codecrafters-frontend/mixins/viewable'; // eslint-disable-line ember/no-mixins
import type AuthenticatorService from 'codecrafters-frontend/services/authenticator';
import type CourseStageModel from 'codecrafters-frontend/models/course-stage';
import type LanguageModel from 'codecrafters-frontend/models/language';

export default class CourseStageSolutionModel extends Model {
export default class CourseStageSolutionModel extends Model.extend(ViewableMixin) {
@service declare authenticator: AuthenticatorService;

@attr() declare authorDetails: { [key: string]: string }; // free-form JSON
@attr() declare changedFiles: { diff: string; filename: string }[]; // free-form JSON
@attr('string') declare explanationMarkdown: string;
Expand Down
8 changes: 8 additions & 0 deletions app/models/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ export default class RepositoryModel extends Model {
return buildPreChallengeAssessmentSectionList(this);
}

get secondStageSolution(): CourseStageSolutionModel | null {
if (!this.course.secondStage) {
return null;

Check warning on line 205 in app/models/repository.ts

View check run for this annotation

Codecov / codecov/patch

app/models/repository.ts#L205

Added line #L205 was not covered by tests
}

return this.course.secondStage.solutions.find((solution) => solution.language === this.language) || null;
}

courseStageCompletionFor(courseStage: CourseStageModel) {
return this.courseStageCompletions.filterBy('courseStage', courseStage).sortBy('completedAt')[0];
}
Expand Down
4 changes: 2 additions & 2 deletions app/services/feature-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default class FeatureFlagsService extends Service {
return this.currentUser && (this.currentUser.isStaff || this.currentUser.isConceptAuthor);
}

get canSeeLanguageGuidesForStage2() {
return this.getFeatureFlagValue('can-see-language-guides-for-stage-2') === 'test' || this.currentUser?.isStaff;
get canSeeSolutionsForStage2() {
return this.getFeatureFlagValue('can-see-solutions-for-stage-2') === 'test' || this.currentUser?.isStaff;
}

get currentUser() {
Expand Down
1 change: 1 addition & 0 deletions app/templates/course/stage/instructions.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
@repository={{@model.activeRepository}}
@courseStage={{@model.courseStage}}
@shouldRecommendLanguageGuide={{this.shouldShowLanguageGuide}}
@shouldShowSolution={{this.shouldShowSolution}}
class="mb-6"
/>
{{/if}}
Expand Down

0 comments on commit bb77881

Please sign in to comment.