From 5e12dabced6ce55031f5c7f13afb15048d03edcd Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Thu, 11 Apr 2024 00:19:44 +0200 Subject: Timer create & delete --- view/main.templ | 3 +- view/main_templ.go | 2 +- view/timers_list.templ | 39 ++++++++++++++++--- view/timers_list_templ.go | 99 +++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 129 insertions(+), 14 deletions(-) (limited to 'view') diff --git a/view/main.templ b/view/main.templ index 1a4bf95..b6d94d8 100644 --- a/view/main.templ +++ b/view/main.templ @@ -7,8 +7,9 @@ templ Main(contents templ.Component) { Cool timer app + - + @contents diff --git a/view/main_templ.go b/view/main_templ.go index 363061e..109be9c 100644 --- a/view/main_templ.go +++ b/view/main_templ.go @@ -23,7 +23,7 @@ func Main(contents templ.Component) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Cool timer app") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Cool timer app") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/view/timers_list.templ b/view/timers_list.templ index e1731d4..2d71a52 100644 --- a/view/timers_list.templ +++ b/view/timers_list.templ @@ -6,12 +6,41 @@ import ( ) templ timer(t model.Timer) { -

{ t.Name }

+

+ { t.Name } + - + Delete +

+} + +templ TimerCreateForm(timerName string, err string) { +
+

+ + +

+ if err != "" { +

{ err }

+ } +
} templ TimersList(timers []model.Timer) { -

Timers

- for _, t := range timers { - @timer(t) - } +
+

Timers

+ for _, t := range timers { + @timer(t) + } +

Create timer

+ @TimerCreateForm("", "") +
} + diff --git a/view/timers_list_templ.go b/view/timers_list_templ.go index cbfe2eb..af4922d 100644 --- a/view/timers_list_templ.go +++ b/view/timers_list_templ.go @@ -28,7 +28,7 @@ func timer(t model.Timer) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" -\r Delete

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func TimerCreateForm(timerName string, err string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var5 := templ.GetChildren(ctx) + if templ_7745c5c3_Var5 == nil { + templ_7745c5c3_Var5 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if err != "" { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var7 string + templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(err) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\timers_list.templ`, Line: 31, Col: 34} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -69,12 +142,12 @@ func TimersList(timers []model.Timer) templ.Component { defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var4 := templ.GetChildren(ctx) - if templ_7745c5c3_Var4 == nil { - templ_7745c5c3_Var4 = templ.NopComponent + templ_7745c5c3_Var8 := templ.GetChildren(ctx) + if templ_7745c5c3_Var8 == nil { + templ_7745c5c3_Var8 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Timers

") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Timers

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -84,6 +157,18 @@ func TimersList(timers []model.Timer) templ.Component { return templ_7745c5c3_Err } } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Create timer

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = TimerCreateForm("", "").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } if !templ_7745c5c3_IsBuffer { _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) } -- cgit