You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
9.2 KiB
135 lines
9.2 KiB
// Code generated by templ - DO NOT EDIT.
|
|
|
|
// templ: version: v0.3.833
|
|
package templates
|
|
|
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
|
|
|
import "github.com/a-h/templ"
|
|
import templruntime "github.com/a-h/templ/runtime"
|
|
|
|
func Index() templ.Component {
|
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
|
return templ_7745c5c3_CtxErr
|
|
}
|
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
|
if !templ_7745c5c3_IsBuffer {
|
|
defer func() {
|
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err == nil {
|
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
|
}
|
|
}()
|
|
}
|
|
ctx = templ.InitializeContext(ctx)
|
|
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
|
if templ_7745c5c3_Var1 == nil {
|
|
templ_7745c5c3_Var1 = templ.NopComponent
|
|
}
|
|
ctx = templ.ClearChildren(ctx)
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<!doctype html><html lang=\"en\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>Derby Race Timer</title><link href=\"/static/css/tailwind.css\" rel=\"stylesheet\"><script src=\"/static/js/htmx.min.js\"></script></head><body class=\"bg-gray-100 min-h-screen\"><div class=\"container mx-auto px-4 py-8\"><header class=\"mb-8\"><h1 class=\"text-3xl font-bold text-center\">Derby Race Timer</h1></header><div class=\"mb-6 flex justify-center\"><div id=\"race-status\" class=\"px-4 py-2 rounded-full text-white bg-blue-600\">Ready</div></div><div class=\"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-8\">")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = laneComponents().Render(ctx, templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "</div><div class=\"flex justify-center space-x-4\"><button hx-post=\"/api/reset\" hx-swap=\"none\" class=\"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded\">Reset Race</button> <button hx-post=\"/api/force-end\" hx-swap=\"none\" class=\"bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded\">Force End Race</button></div></div><script>\r\n\t\t\tconsole.log(\"Setting up SSE connection...\");\r\n\t\t\t\r\n\t\t\t// Set up SSE connection\r\n\t\t\tconst eventSource = new EventSource('/api/events');\r\n\t\t\t\r\n\t\t\teventSource.onopen = function() {\r\n\t\t\t\tconsole.log(\"SSE connection opened\");\r\n\t\t\t};\r\n\t\t\t\r\n\t\t\teventSource.onerror = function(error) {\r\n\t\t\t\tconsole.error(\"SSE connection error:\", error);\r\n\t\t\t};\r\n\t\t\t\r\n\t\t\teventSource.addEventListener('debug', function(event) {\r\n\t\t\t\tconsole.log(\"Debug event received:\", event.data);\r\n\t\t\t});\r\n\t\t\t\r\n\t\t\teventSource.addEventListener('lane-finish', function(event) {\r\n\t\t\t\tconsole.log(\"Lane finish event received:\", event.data);\r\n\t\t\t\ttry {\r\n\t\t\t\t\tconst laneFinishData = JSON.parse(event.data);\r\n\t\t\t\t\tconst lane = document.getElementById(`lane-${laneFinishData.lane}`);\r\n\t\t\t\t\tif (lane) {\r\n\t\t\t\t\t\tconsole.log(`Updating lane ${laneFinishData.lane} with time ${laneFinishData.time}`);\r\n\t\t\t\t\t\tlane.classList.add('finished');\r\n\t\t\t\t\t\tlane.querySelector('.time').textContent = laneFinishData.time.toFixed(4);\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\tconst placeEl = lane.querySelector('.place');\r\n\t\t\t\t\t\tplaceEl.textContent = `${getOrdinal(laneFinishData.place)} Place`;\r\n\t\t\t\t\t\tplaceEl.classList.remove('hidden');\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tconsole.error(`Lane element not found for lane ${laneFinishData.lane}`);\r\n\t\t\t\t\t}\r\n\t\t\t\t} catch (error) {\r\n\t\t\t\t\tconsole.error(\"Error processing lane finish event:\", error);\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t\t\r\n\t\t\teventSource.addEventListener('status', function(event) {\r\n\t\t\t\tconsole.log(\"Status event received:\", event.data);\r\n\t\t\t\ttry {\r\n\t\t\t\t\tconst statusData = JSON.parse(event.data);\r\n\t\t\t\t\tlet statusText = 'Unknown';\r\n\t\t\t\t\tlet statusClass = 'bg-gray-500';\r\n\t\t\t\t\t\r\n\t\t\t\t\tif (statusData.status === 'idle') {\r\n\t\t\t\t\t\tstatusText = 'Ready';\r\n\t\t\t\t\t\tstatusClass = 'bg-blue-600';\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\t// Reset all lanes\r\n\t\t\t\t\t\tdocument.querySelectorAll('.lane').forEach(lane => {\r\n\t\t\t\t\t\t\tlane.classList.remove('finished');\r\n\t\t\t\t\t\t\tlane.querySelector('.time').textContent = '--.--.---';\r\n\t\t\t\t\t\t\tlane.querySelector('.place').classList.add('hidden');\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t} else if (statusData.status === 'running') {\r\n\t\t\t\t\t\tstatusText = 'Race Running';\r\n\t\t\t\t\t\tstatusClass = 'bg-green-600';\r\n\t\t\t\t\t} else if (statusData.status === 'finished') {\r\n\t\t\t\t\t\tstatusText = 'Race Complete';\r\n\t\t\t\t\t\tstatusClass = 'bg-purple-600';\r\n\t\t\t\t\t}\r\n\t\t\t\t\t\r\n\t\t\t\t\tdocument.getElementById('race-status').textContent = statusText;\r\n\t\t\t\t\tdocument.getElementById('race-status').className = `px-4 py-2 rounded-full text-white ${statusClass}`;\r\n\t\t\t\t} catch (error) {\r\n\t\t\t\t\tconsole.error(\"Error processing status event:\", error);\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t\t\r\n\t\t\tfunction getOrdinal(n) {\r\n\t\t\t\tconst s = [\"th\", \"st\", \"nd\", \"rd\"];\r\n\t\t\t\tconst v = n % 100;\r\n\t\t\t\treturn n + (s[(v-20)%10] || s[v] || s[0]);\r\n\t\t\t}\r\n\t\t</script></body></html>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func laneComponents() templ.Component {
|
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
|
return templ_7745c5c3_CtxErr
|
|
}
|
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
|
if !templ_7745c5c3_IsBuffer {
|
|
defer func() {
|
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err == nil {
|
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
|
}
|
|
}()
|
|
}
|
|
ctx = templ.InitializeContext(ctx)
|
|
templ_7745c5c3_Var2 := templ.GetChildren(ctx)
|
|
if templ_7745c5c3_Var2 == nil {
|
|
templ_7745c5c3_Var2 = templ.NopComponent
|
|
}
|
|
ctx = templ.ClearChildren(ctx)
|
|
for i := 1; i <= 4; i++ {
|
|
templ_7745c5c3_Err = laneComponent(i).Render(ctx, templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func laneComponent(lane int) templ.Component {
|
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
|
return templ_7745c5c3_CtxErr
|
|
}
|
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
|
if !templ_7745c5c3_IsBuffer {
|
|
defer func() {
|
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err == nil {
|
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
|
}
|
|
}()
|
|
}
|
|
ctx = templ.InitializeContext(ctx)
|
|
templ_7745c5c3_Var3 := templ.GetChildren(ctx)
|
|
if templ_7745c5c3_Var3 == nil {
|
|
templ_7745c5c3_Var3 = templ.NopComponent
|
|
}
|
|
ctx = templ.ClearChildren(ctx)
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<div id=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var4 string
|
|
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs("lane-" + string(rune('0'+lane)))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/index.templ`, Line: 131, Col: 45}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "\" class=\"lane bg-white p-4 rounded shadow\"><h2 class=\"text-xl font-semibold mb-2\">Lane ")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var5 string
|
|
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(string(rune('0' + lane)))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/index.templ`, Line: 132, Col: 72}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</h2><div class=\"text-3xl font-mono mb-2 time\">--.--.---</div><div class=\"place text-lg font-bold text-green-600 hidden\"></div></div>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
var _ = templruntime.GeneratedTemplate
|