feat: other fields taken from template data
This commit is contained in:
parent
2769f5e8dc
commit
f4ab1ac7ec
|
@ -26,6 +26,12 @@ func iconPath(categoryName string) string {
|
||||||
return fmt.Sprintf("/static/public/images/icon-%s.svg", categoryName)
|
return fmt.Sprintf("/static/public/images/icon-%s.svg", categoryName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ResultsSummaryData struct {
|
||||||
|
Categories []Category
|
||||||
|
TotalScore int
|
||||||
|
UpperPercent int
|
||||||
|
}
|
||||||
|
|
||||||
// starts webserver that serves html page for exercise
|
// starts webserver that serves html page for exercise
|
||||||
func main() {
|
func main() {
|
||||||
// serves public static resources: bundled images, fonts, css
|
// serves public static resources: bundled images, fonts, css
|
||||||
|
@ -36,22 +42,26 @@ func main() {
|
||||||
io.WriteString(w, "This is temporary here, hello")
|
io.WriteString(w, "This is temporary here, hello")
|
||||||
})
|
})
|
||||||
|
|
||||||
mySummary := [...]Category{
|
resultsData := ResultsSummaryData{
|
||||||
{Name: "Reaction", ColorHsl: "0deg 100% 67%",
|
Categories: []Category{
|
||||||
Score: 80, IconPath: iconPath("reaction")},
|
{Name: "Reaction", ColorHsl: "0deg 100% 67%",
|
||||||
{Name: "Memory", ColorHsl: "39deg 100% 56%",
|
Score: 80, IconPath: iconPath("reaction")},
|
||||||
Score: 92, IconPath: iconPath("memory")},
|
{Name: "Memory", ColorHsl: "39deg 100% 56%",
|
||||||
{Name: "Verbal", ColorHsl: "166deg 100% 37%",
|
Score: 92, IconPath: iconPath("memory")},
|
||||||
Score: 61, IconPath: iconPath("verbal")},
|
{Name: "Verbal", ColorHsl: "166deg 100% 37%",
|
||||||
{Name: "Visual", ColorHsl: "234deg 85% 45%",
|
Score: 61, IconPath: iconPath("verbal")},
|
||||||
Score: 72, IconPath: iconPath("visual")},
|
{Name: "Visual", ColorHsl: "234deg 85% 45%",
|
||||||
|
Score: 72, IconPath: iconPath("visual")},
|
||||||
|
},
|
||||||
|
TotalScore: 76,
|
||||||
|
UpperPercent: 65,
|
||||||
}
|
}
|
||||||
|
|
||||||
// main page with results summary
|
// main page with results summary
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
||||||
templateName := "templates/summary-component.gohtml"
|
templateName := "templates/summary-component.gohtml"
|
||||||
tmpl := template.Must(template.ParseFS(templates, templateName))
|
tmpl := template.Must(template.ParseFS(templates, templateName))
|
||||||
if err := tmpl.Execute(w, mySummary); err != nil {
|
if err := tmpl.Execute(w, resultsData); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -646,6 +646,10 @@ video {
|
||||||
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to);
|
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.from-50\% {
|
||||||
|
--tw-gradient-from-position: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
.to-light-slate-blue {
|
.to-light-slate-blue {
|
||||||
--tw-gradient-to: hsl(252, 100%, 67%) var(--tw-gradient-to-position);
|
--tw-gradient-to: hsl(252, 100%, 67%) var(--tw-gradient-to-position);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
>
|
>
|
||||||
<section
|
<section
|
||||||
id="results-pane"
|
id="results-pane"
|
||||||
class="flex flex-col gap-y-4 items-center px-10 pt-4 pb-8 text-white bg-gradient-to-t rounded-b-3xl md:justify-around md:w-1/2 md:rounded-3xl from-light-royal-blue to-light-slate-blue"
|
class="flex flex-col gap-y-4 items-center px-10 pt-4 pb-8 text-white bg-gradient-to-t from-50% rounded-b-3xl md:justify-around md:w-1/2 md:rounded-3xl from-light-royal-blue to-light-slate-blue"
|
||||||
>
|
>
|
||||||
<h1 class="font-bold md:pt-2 md:text-xl text-pale-blue">
|
<h1 class="font-bold md:pt-2 md:text-xl text-pale-blue">
|
||||||
Your Result
|
Your Result
|
||||||
|
@ -46,13 +46,13 @@
|
||||||
<div
|
<div
|
||||||
class="flex flex-col justify-center items-center w-32 h-32 bg-gradient-to-t rounded-full md:w-44 md:h-44 from-violet-blue/60 to-persian-blue/75"
|
class="flex flex-col justify-center items-center w-32 h-32 bg-gradient-to-t rounded-full md:w-44 md:h-44 from-violet-blue/60 to-persian-blue/75"
|
||||||
>
|
>
|
||||||
<span class="text-5xl font-extrabold md:text-6xl">76</span>
|
<span class="text-5xl font-extrabold md:text-6xl">{{ .TotalScore }}</span>
|
||||||
<span class="text-pale-blue"> of 100 </span>
|
<span class="text-pale-blue"> of 100 </span>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col gap-y-3 items-center">
|
<div class="flex flex-col gap-y-3 items-center">
|
||||||
<h2 class="text-xl font-bold md:text-2xl">Great</h2>
|
<h2 class="text-xl font-bold md:text-2xl">Great</h2>
|
||||||
<p class="text-sm text-center md:text-base text-pale-blue">
|
<p class="text-sm text-center md:text-base text-pale-blue">
|
||||||
You scored higher than 65% of the people who have taken these
|
You scored higher than {{ .UpperPercent }}% of the people who have taken these
|
||||||
tests.
|
tests.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -64,7 +64,7 @@
|
||||||
>
|
>
|
||||||
<h2 class="font-bold md:text-xl">Summary</h2>
|
<h2 class="font-bold md:text-xl">Summary</h2>
|
||||||
<dl class="flex flex-col gap-y-4">
|
<dl class="flex flex-col gap-y-4">
|
||||||
{{ range . }}
|
{{ range .Categories }}
|
||||||
<div
|
<div
|
||||||
class="flex flex-row items-center px-5 h-12 text-sm rounded-lg bg-summary-item-color/5"
|
class="flex flex-row items-center px-5 h-12 text-sm rounded-lg bg-summary-item-color/5"
|
||||||
style="--summary-item-color-var: {{ .ColorHsl }}"
|
style="--summary-item-color-var: {{ .ColorHsl }}"
|
||||||
|
|
Loading…
Reference in New Issue