Skip to content

Commit

Permalink
refactor: move layout to props interface
Browse files Browse the repository at this point in the history
  • Loading branch information
believer committed Sep 12, 2024
1 parent 308f5c7 commit f0c06cb
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 34 deletions.
2 changes: 1 addition & 1 deletion views/feed.templ
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

templ Feed(isAdmin bool, movies types.Movies, nextPage int, query string) {
@Layout("", "") {
@Layout(LayoutProps{}) {
<div class="mx-auto flex max-w-xl flex-col gap-12 px-5 pt-8">
<nav class="flex items-center gap-5">
<div class="left-8 top-10 md:absolute">
Expand Down
2 changes: 1 addition & 1 deletion views/feed_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion views/genre.templ
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type GenreProps struct {
}

templ Genre(props GenreProps) {
@Layout(props.Name, "") {
@Layout(LayoutProps{Title: props.Name}) {
<div
class="mx-auto flex max-w-xl flex-col gap-8 px-5 py-8"
>
Expand Down
2 changes: 1 addition & 1 deletion views/genre_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions views/layout.templ
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
package views

templ Layout(title string, description string) {
type LayoutProps struct {
Title string
Description string
}

templ Layout(props LayoutProps) {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
if title != "" {
<title>{ title }</title>
<meta property="og:title" content={ title }/>
if props.Title != "" {
<title>{ props.Title }</title>
<meta property="og:title" content={ props.Title }/>
} else {
<title>Movies</title>
<meta property="og:title" content="Movies"/>
}
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
if description != "" {
if props.Description != "" {
<meta
name="description"
content={ description }
content={ props.Description }
/>
<meta
property="og:description"
content={ description }
content={ props.Description }
/>
} else {
<meta
Expand Down
27 changes: 16 additions & 11 deletions views/layout_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion views/login.templ
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package views
import "believer/movies/components"

templ Login() {
@Layout("Login", "") {
@Layout(LayoutProps{Title: "Login"}) {
<form
class="mx-auto flex max-w-xl flex-col gap-6 px-4 py-8"
hx-post="/login"
Expand Down
2 changes: 1 addition & 1 deletion views/login_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion views/movie.templ
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// parameterized "style" attribute in the template. At least yet...
// https://github.com/a-h/templ/issues/88
templ Movie(movie types.Movie, back bool) {
@Layout(movie.Title, movie.Overview) {
@Layout(LayoutProps{Title: movie.Title, Description: movie.Overview}) {
<div class="mx-auto flex max-w-xl flex-col gap-8 px-5 py-8">
@components.H1(movie.Title, back)
if movie.Overview != "" {
Expand Down
2 changes: 1 addition & 1 deletion views/movie_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion views/moviesByYear.templ
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

templ MoviesByYear(year string, movies []types.Movie) {
@Layout("", "") {
@Layout(LayoutProps{Title: year}) {
<div
class="mx-auto flex max-w-xl flex-col gap-8 px-5 py-8"
>
Expand Down
2 changes: 1 addition & 1 deletion views/moviesByYear_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion views/newMovie.templ
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package views
import "believer/movies/components"

templ NewMovie() {
@Layout("Add movie", "") {
@Layout(LayoutProps{Title: "Add movie"}) {
<form
hx-post="/movie/new"
hx-indicator="#sending"
Expand Down
2 changes: 1 addition & 1 deletion views/newMovie_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion views/person.templ
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ templ Credit(title string, data types.PersonMovies, id string) {
}

templ Person(person types.Person, totalCredits int, id string) {
@Layout(person.Name, "") {
@Layout(LayoutProps{Title: person.Name}) {
<div
class="mx-auto flex max-w-xl flex-col gap-8 px-5 py-8"
>
Expand Down
2 changes: 1 addition & 1 deletion views/person_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion views/stats.templ
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type StatsProps struct {
}

templ Stats(props StatsProps) {
@Layout("Stats", "") {
@Layout(LayoutProps{Title: "Stats"}) {
<div class="mx-auto flex max-w-xl lg:max-w-5xl flex-col gap-y-8 px-5 pb-8 pt-8 lg:pt-24">
<nav class="flex items-center gap-5">
<div class="left-8 top-10 md:absolute">
Expand Down
2 changes: 1 addition & 1 deletion views/stats_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f0c06cb

Please sign in to comment.