added form and db support
This commit is contained in:
parent
5e4bc3ada7
commit
ddb4469501
9 changed files with 504 additions and 48 deletions
50
form.go
Normal file
50
form.go
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/charmbracelet/huh"
|
||||
)
|
||||
|
||||
func showEventForm(ctx context.Context, onSubmit func(EventInput)) error {
|
||||
var title, description, year, month, day, startHour, endHour, color string
|
||||
|
||||
form := huh.NewForm(
|
||||
huh.NewGroup(
|
||||
huh.NewInput().Title("Title").Value(&title),
|
||||
huh.NewInput().Title("Description").Value(&description),
|
||||
huh.NewInput().Title("Year").Value(&year),
|
||||
huh.NewInput().Title("Month").Value(&month),
|
||||
huh.NewInput().Title("Day").Value(&day),
|
||||
huh.NewInput().Title("Start Hour (0–23)").Value(&startHour),
|
||||
huh.NewInput().Title("End Hour (0–23)").Value(&endHour),
|
||||
huh.NewInput().Title("Color (e.g. 99 or #ff5733)").Value(&color),
|
||||
),
|
||||
)
|
||||
|
||||
if err := form.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
yr, _ := strconv.Atoi(year)
|
||||
mo, _ := strconv.Atoi(month)
|
||||
da, _ := strconv.Atoi(day)
|
||||
sh, _ := strconv.Atoi(startHour)
|
||||
eh, _ := strconv.Atoi(endHour)
|
||||
|
||||
onSubmit(EventInput{
|
||||
Title: title,
|
||||
Description: description,
|
||||
Year: int32(yr),
|
||||
Month: int32(mo),
|
||||
Day: int32(da),
|
||||
StartHour: int32(sh),
|
||||
EndHour: int32(eh),
|
||||
Color: color,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue