From db00bfb79ae468a46e604140713a41c6d29d4635 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Tue, 16 Apr 2024 23:45:34 +0200 Subject: idk random shit --- static/style.css | 3 --- timer.db | Bin 28672 -> 28672 bytes timer.go | 17 +++++++++++++---- view/timer.templ | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/static/style.css b/static/style.css index f153f6e..8ef32c6 100644 --- a/static/style.css +++ b/static/style.css @@ -1,8 +1,5 @@ body { font-size: 16px; -} - -* { font-family: sans-serif; } diff --git a/timer.db b/timer.db index c6be241..2b944ed 100644 Binary files a/timer.db and b/timer.db differ diff --git a/timer.go b/timer.go index f215377..610de82 100644 --- a/timer.go +++ b/timer.go @@ -438,7 +438,16 @@ func (server *MyServer) handleDeleteTimer(w http.ResponseWriter, r *http.Request } } -func (server *MyServer) handlePutTimer(w http.ResponseWriter, r *http.Request) { +func parseNumber(s string) (int64, error) { + s = strings.TrimSpace(s) + if len(s) == 0 { + s = "0" + } + + return strconv.ParseInt(s, 10, 64) +} + +func (server *MyServer) handleCreateTimer(w http.ResponseWriter, r *http.Request) { timerName := strings.TrimSpace(r.FormValue("timerName")) user := server.findCurrentUser(w, r) @@ -448,14 +457,14 @@ func (server *MyServer) handlePutTimer(w http.ResponseWriter, r *http.Request) { return } - days, err := strconv.ParseInt(strings.TrimSpace(r.FormValue("days")), 10, 32) + days, err := parseNumber(r.FormValue("days")) if err != nil { w.WriteHeader(http.StatusBadRequest) view.TimerCreateForm(timerName, "Error parsing days").Render(context.Background(), w) return } - hours, err := strconv.ParseInt(strings.TrimSpace(r.FormValue("hours")), 10, 32) + hours, err := parseNumber(r.FormValue("hours")) if err != nil { w.WriteHeader(http.StatusBadRequest) view.TimerCreateForm(timerName, "Error parsing hours").Render(context.Background(), w) @@ -563,7 +572,7 @@ func main() { http.HandleFunc("DELETE /timer/{timerId}", myServer.handleDeleteTimer) http.HandleFunc("POST /timer/{timerId}/resetToken", myServer.handleResetTimerToken) http.HandleFunc("GET /timer/{timerId}/token", myServer.handleGetTimerToken) - http.HandleFunc("PUT /timer", myServer.handlePutTimer) + http.HandleFunc("PUT /timer", myServer.handleCreateTimer) http.HandleFunc("GET /", myServer.handleMain) log.Println("Started!") diff --git a/view/timer.templ b/view/timer.templ index 45194c5..09b1345 100644 --- a/view/timer.templ +++ b/view/timer.templ @@ -38,7 +38,6 @@ templ timeButton(id model.UUID, value int, unit string) { templ TimerInfo(timer model.Timer) {

Timer "{ timer.Name }"

-

Back to list

Start time: { timer.StartTime.AsUTCString() }

End time: { timer.EndTime.AsUTCString() }

@@ -57,6 +56,7 @@ templ TimerInfo(timer model.Timer) { } templ TimerView(timer model.Timer) { +

Back to list

@TimerInfo(timer)
-- cgit