Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions client/lessons.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,17 @@ type SubmissionDebugData struct {
ResponseBody string
}

type XPBreakdownItem struct {
Name string
Percent float64
XP int
}

type LessonSubmissionEvent struct {
ResultSlug VerificationResultSlug
StructuredErrCLI *StructuredErrCLI
XPReward int
XPBreakdown []XPBreakdownItem
}

type StructuredErrCLI struct {
Expand Down
6 changes: 4 additions & 2 deletions messages/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ type ResolveTestMsg struct {
}

type DoneStepMsg struct {
Result api.VerificationResultSlug
Failure *api.StructuredErrCLI
Result api.VerificationResultSlug
Failure *api.StructuredErrCLI
XPReward int
XPBreakdown []api.XPBreakdownItem
}

type ResolveStepMsg struct {
Expand Down
16 changes: 9 additions & 7 deletions render/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ type stepModel struct {
}

type rootModel struct {
steps []stepModel
spinner spinner.Model
result api.VerificationResultSlug
failure *api.StructuredErrCLI
isSubmit bool
finalized bool
clear bool
steps []stepModel
spinner spinner.Model
result api.VerificationResultSlug
failure *api.StructuredErrCLI
xpReward int
xpBreakdown []api.XPBreakdownItem
isSubmit bool
finalized bool
clear bool
}

func initModel(isSubmit bool) rootModel {
Expand Down
8 changes: 6 additions & 2 deletions render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func (m rootModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case messages.DoneStepMsg:
m.result = msg.Result
m.failure = msg.Failure
m.xpReward = msg.XPReward
m.xpBreakdown = msg.XPBreakdown
m.clear = true
return m, tea.Quit

Expand Down Expand Up @@ -121,8 +123,10 @@ func StartRenderer(data api.CLIData, isSubmit bool, ch chan tea.Msg) func(api.Le

return func(submissionEvent api.LessonSubmissionEvent) {
ch <- messages.DoneStepMsg{
Result: submissionEvent.ResultSlug,
Failure: submissionEvent.StructuredErrCLI,
Result: submissionEvent.ResultSlug,
Failure: submissionEvent.StructuredErrCLI,
XPReward: submissionEvent.XPReward,
XPBreakdown: submissionEvent.XPBreakdown,
}
wg.Wait()
}
Expand Down
26 changes: 24 additions & 2 deletions render/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,30 @@ func (m rootModel) View() string {
}

if m.result == api.VerificationResultSlugSuccess && m.isSubmit {
str.WriteString("\n\n" + green.Render("All tests passed! 🎉") + "\n\n")
str.WriteString(green.Render("Return to your browser to continue with the next lesson.") + "\n\n")
str.WriteString("\n\n" + green.Render("All tests passed! 🎉") + "\n")
if m.xpReward >= 0 {
str.WriteString("\n")
str.WriteString(green.Bold(true).Render(fmt.Sprintf("Gained +%d XP", m.xpReward)))
str.WriteByte('\n')
for _, item := range m.xpBreakdown {
if item.XP == 0 {
continue
}
sign := "+"
xp := item.XP
if xp < 0 {
sign = "-"
xp = -xp
}
if item.Percent > 0 {
str.WriteString(gray.Render(fmt.Sprintf("%s%3d XP (%-4s %s)", sign, xp, fmt.Sprintf("%.0f%%", item.Percent*100), item.Name)))
} else {
str.WriteString(gray.Render(fmt.Sprintf("%s%3d XP (%s)", sign, xp, item.Name)))
}
str.WriteByte('\n')
}
}
str.WriteString("\n" + green.Render("Return to your browser to continue with the next lesson.") + "\n\n")
} else if m.result == api.VerificationResultSlugNoop {
str.WriteString("\n\nTests failed! ❌")
fmt.Fprintf(&str, "\n\nFailed Step: %v", m.failure.FailedStepIndex+1)
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.29.5
v1.29.6