diff --git a/components/input.templ b/components/input.templ index b8766e6..3514885 100644 --- a/components/input.templ +++ b/components/input.templ @@ -35,11 +35,13 @@ templ TextInput(name string, labelText string, helpText string) { } -templ NumberInput(name string, labelText string, helpText string, min int, max int) { +templ NumberInput(name string, labelText string, helpText string, min int, max int, required bool) {
@Label(name, labelText) } + +type DataListItem struct { + Value string `db:"series"` +} + +templ DataList(options []DataListItem, id string) { + + for _, option := range options { + + } + +} diff --git a/components/list_templ.go b/components/list_templ.go index c0bae93..916e125 100644 --- a/components/list_templ.go +++ b/components/list_templ.go @@ -177,4 +177,73 @@ func OrderedList(data []ListItem, listType string) templ.Component { }) } +type DataListItem struct { + Value string `db:"series"` +} + +func DataList(options []DataListItem, id string) 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_Var10 := templ.GetChildren(ctx) + if templ_7745c5c3_Var10 == nil { + templ_7745c5c3_Var10 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, option := range options { + _, 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 + } + return templ_7745c5c3_Err + }) +} + var _ = templruntime.GeneratedTemplate diff --git a/handlers/movies.go b/handlers/movies.go index 3cf18c0..03284f5 100644 --- a/handlers/movies.go +++ b/handlers/movies.go @@ -166,6 +166,18 @@ func HandleGetMovieNew(c *fiber.Ctx) error { })) } +func HandleGetMovieNewSeries(c *fiber.Ctx) error { + var options []components.DataListItem + + err := db.Client.Select(&options, `SELECT DISTINCT series FROM movie WHERE series IS NOT NULL ORDER BY series ASC`) + + if err != nil { + return err + } + + return utils.TemplRender(c, components.DataList(options, "series_list")) +} + func tmdbFetchMovie(id string) types.MovieDetailsResponse { tmdbKey := os.Getenv("TMDB_API_KEY") @@ -283,16 +295,30 @@ func HandlePostMovieNew(c *fiber.Ctx) error { } data := new(struct { - ImdbID string `form:"imdb_id"` - Rating int `form:"rating"` - IsWatchlist bool `form:"watchlist"` - WatchedAt string `form:"watched_at"` + ImdbID string `form:"imdb_id"` + Rating int `form:"rating"` + IsWatchlist bool `form:"watchlist"` + HasWilhelmScream bool `form:"wilhelm_scream"` + Series string `form:"series"` + NumberInSeries int `form:"number_in_series"` + WatchedAt string `form:"watched_at"` }) if err := c.BodyParser(data); err != nil { return err } + series := sql.NullString{String: "", Valid: false} + number_in_series := sql.NullInt64{Int64: 0, Valid: false} + + if data.Series != "" { + series = sql.NullString{String: data.Series, Valid: true} + } + + if data.NumberInSeries != 0 { + number_in_series = sql.NullInt64{Int64: int64(data.NumberInSeries), Valid: false} + } + imdbId, err := utils.ParseImdbId(data.ImdbID) if err != nil { @@ -320,7 +346,7 @@ func HandlePostMovieNew(c *fiber.Ctx) error { tx := db.Client.MustBegin() // Insert movie information - err = tx.Get(&movieId, `INSERT INTO movie (title, runtime, release_date, imdb_id, overview, poster, tagline) VALUES ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT (imdb_id) DO UPDATE SET title = $1 RETURNING id`, movie.Title, movie.Runtime, movie.ReleaseDate, movie.ImdbId, movie.Overview, movie.Poster, movie.Tagline) + err = tx.Get(&movieId, `INSERT INTO movie (title, runtime, release_date, imdb_id, overview, poster, tagline, series, number_in_series, wilhelm) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) ON CONFLICT (imdb_id) DO UPDATE SET title = $1 RETURNING id`, movie.Title, movie.Runtime, movie.ReleaseDate, movie.ImdbId, movie.Overview, movie.Poster, movie.Tagline, series, number_in_series, data.HasWilhelmScream) if err != nil { return err diff --git a/public/styles.css b/public/styles.css index 32d1976..3c614c0 100644 --- a/public/styles.css +++ b/public/styles.css @@ -615,6 +615,10 @@ video { margin-left: 1.25rem; } +.mt-4 { + margin-top: 1rem; +} + .line-clamp-3 { overflow: hidden; display: -webkit-box; @@ -693,6 +697,10 @@ video { transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y)); } +.cursor-pointer { + cursor: pointer; +} + .list-disc { list-style-type: disc; } diff --git a/router/router.go b/router/router.go index 6e03536..beda187 100644 --- a/router/router.go +++ b/router/router.go @@ -26,6 +26,7 @@ func SetupRoutes(app *fiber.App) { movieGroup.Get("/imdb", handlers.HandleGetByImdbId) movieGroup.Get("/search", handlers.HandleSearchNew) movieGroup.Get("/new", handlers.HandleGetMovieNew) + movieGroup.Get("/new/series", handlers.HandleGetMovieNewSeries) movieGroup.Post("/new", handlers.HandlePostMovieNew) movieGroup.Get("/:id", handlers.HandleGetMovieByID) diff --git a/views/layout.templ b/views/layout.templ index 1072d9f..6f91835 100644 --- a/views/layout.templ +++ b/views/layout.templ @@ -43,7 +43,7 @@ templ Layout(props LayoutProps) { - + diff --git a/views/layout_templ.go b/views/layout_templ.go index 70fc5aa..3c416f5 100644 --- a/views/layout_templ.go +++ b/views/layout_templ.go @@ -116,7 +116,7 @@ func Layout(props LayoutProps) templ.Component { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/newMovie.templ b/views/newMovie.templ index 6a717de..7368a7a 100644 --- a/views/newMovie.templ +++ b/views/newMovie.templ @@ -16,7 +16,7 @@ templ NewMovie(props NewMovieProps) {
@components.Link(components.LinkProps{Href: "/"}) { @@ -77,14 +77,36 @@ templ NewMovie(props NewMovieProps) { >
@components.Help("For example, https://www.imdb.com/title/tt0111161/, or just tt0111161.")
- @components.NumberInput("rating", "Rating", "A value between 0 and 10", 0, 10) - @components.DateTimeInput("watched_at", "Watched at", "Defaults to current time if left empty.") + @components.NumberInput("rating", "Rating", "A value between 0 and 10", 0, 10, true) if !props.InWatchlist {
@components.Label("watchlist", "Add to watchlist")
} +
+ Additional fields +
+ @components.DateTimeInput("watched_at", "Watched at", "Defaults to current time if left empty.") +
+ @components.Label("series", "Series") + +
+
+ @components.NumberInput("number_in_series", "Number in series", "", 0, 1000, false) +
+ + @components.Label("wilhelm_scream", "Wilhelm scream") +
+
+
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Additional fields
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = components.DateTimeInput("watched_at", "Watched at", "Defaults to current time if left empty.").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 + } + templ_7745c5c3_Err = components.Label("series", "Series").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 + } + templ_7745c5c3_Err = components.NumberInput("number_in_series", "Number in series", "", 0, 1000, false).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 + } + templ_7745c5c3_Err = components.Label("wilhelm_scream", "Wilhelm scream").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 }