From 111cd2daab2d4eb9744e724706d3b2a7fdaa7e83 Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 25 Aug 2024 22:25:32 +0200 Subject: [PATCH] #73 copy sign in form from other branch and some renaming --- handler.go | 4 +- service/auth.go | 18 +++++++ service/static_ui.go | 6 +-- service/workout.go | 8 +-- tailwind.config.js | 2 +- {templates => template}/app.templ | 2 +- template/auth/sign_in.templ | 44 +++++++++++++++++ {templates => template}/index.templ | 2 +- {templates => template}/layout.templ | 15 ++++-- {templates => template}/not_found.templ | 2 +- template/workout/workout.templ | 65 +++++++++++++++++++++++++ templates/header.templ | 12 ----- utils/auth.go | 29 ----------- 13 files changed, 152 insertions(+), 57 deletions(-) create mode 100644 service/auth.go rename {templates => template}/app.templ (98%) create mode 100644 template/auth/sign_in.templ rename {templates => template}/index.templ (95%) rename {templates => template}/layout.templ (50%) rename {templates => template}/not_found.templ (95%) create mode 100644 template/workout/workout.templ delete mode 100644 templates/header.templ diff --git a/handler.go b/handler.go index 9b8de5d..827995b 100644 --- a/handler.go +++ b/handler.go @@ -16,7 +16,9 @@ func getHandler(db *sql.DB) http.Handler { // Serve static files (CSS, JS and images) router.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static/")))) - router.HandleFunc("/app", service.App) + router.HandleFunc("/app", service.WorkoutPage) + router.HandleFunc("/auth/signin", service.SignInPage) + // router.HandleFunc("/auth/signup", service.SignUpPage) router.HandleFunc("POST /api/workout", service.NewWorkout(db)) router.HandleFunc("GET /api/workout", service.GetWorkouts(db)) router.HandleFunc("DELETE /api/workout", service.DeleteWorkout(db)) diff --git a/service/auth.go b/service/auth.go new file mode 100644 index 0000000..6ce3437 --- /dev/null +++ b/service/auth.go @@ -0,0 +1,18 @@ +package service + +import ( + "net/http" + + "me-fit/template" + "me-fit/template/auth" +) + +func SignInPage(w http.ResponseWriter, r *http.Request) { + signIn := auth.SignIn() + template.Layout(signIn).Render(r.Context(), w) +} + +// func SignUpPage(w http.ResponseWriter, r *http.Request) { +// signIn := auth.SignUp() +// template.Layout(signIn).Render(r.Context(), w) +// } diff --git a/service/static_ui.go b/service/static_ui.go index 2822b68..f99720e 100644 --- a/service/static_ui.go +++ b/service/static_ui.go @@ -1,7 +1,7 @@ package service import ( - "me-fit/templates" + "me-fit/template" "net/http" "github.com/a-h/templ" @@ -10,10 +10,10 @@ import ( func HandleIndexAnd404(w http.ResponseWriter, r *http.Request) { var comp templ.Component = nil if r.URL.Path != "/" { - comp = templates.Layout(templates.NotFound()) + comp = template.Layout(template.NotFound()) w.WriteHeader(http.StatusNotFound) } else { - comp = templates.Layout(templates.Index()) + comp = template.Layout(template.Index()) } comp.Render(r.Context(), w) diff --git a/service/workout.go b/service/workout.go index 41b2dcf..3d7650f 100644 --- a/service/workout.go +++ b/service/workout.go @@ -1,7 +1,7 @@ package service import ( - "me-fit/templates" + "me-fit/template" "me-fit/utils" "database/sql" @@ -23,9 +23,9 @@ var ( ) ) -func App(w http.ResponseWriter, r *http.Request) { - comp := templates.App() - layout := templates.Layout(comp) +func WorkoutPage(w http.ResponseWriter, r *http.Request) { + comp := template.App() + layout := template.Layout(comp) layout.Render(r.Context(), w) } diff --git a/tailwind.config.js b/tailwind.config.js index cafdb9b..5ae080b 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -1,6 +1,6 @@ /** @type {import('tailwindcss').Config} */ module.exports = { - content: ["./templates/**/*.templ"], + content: ["./template/**/*.templ"], theme: { extend: {}, }, diff --git a/templates/app.templ b/template/app.templ similarity index 98% rename from templates/app.templ rename to template/app.templ index 2eed8e7..4aec164 100644 --- a/templates/app.templ +++ b/template/app.templ @@ -1,4 +1,4 @@ -package templates +package template templ App() {
diff --git a/template/auth/sign_in.templ b/template/auth/sign_in.templ new file mode 100644 index 0000000..1ec10e0 --- /dev/null +++ b/template/auth/sign_in.templ @@ -0,0 +1,44 @@ +package auth + +templ SignIn() { +
+

Sign In

+ + + +
+} diff --git a/templates/index.templ b/template/index.templ similarity index 95% rename from templates/index.templ rename to template/index.templ index 352c04c..51fd811 100644 --- a/templates/index.templ +++ b/template/index.templ @@ -1,4 +1,4 @@ -package templates +package template templ Index() {
diff --git a/templates/layout.templ b/template/layout.templ similarity index 50% rename from templates/layout.templ rename to template/layout.templ index 0a71e1d..4e5a53e 100644 --- a/templates/layout.templ +++ b/template/layout.templ @@ -1,4 +1,4 @@ -package templates +package template templ Layout(comp templ.Component) { @@ -6,14 +6,21 @@ templ Layout(comp templ.Component) { ME-FIT - - + +
- @header() +
if comp != nil { @comp diff --git a/templates/not_found.templ b/template/not_found.templ similarity index 95% rename from templates/not_found.templ rename to template/not_found.templ index 9ace173..89bb7d5 100644 --- a/templates/not_found.templ +++ b/template/not_found.templ @@ -1,4 +1,4 @@ -package templates +package template templ NotFound() {
diff --git a/template/workout/workout.templ b/template/workout/workout.templ new file mode 100644 index 0000000..c71abcd --- /dev/null +++ b/template/workout/workout.templ @@ -0,0 +1,65 @@ +package workout + +templ Workout() { +
+
+

Track your workout

+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+} diff --git a/templates/header.templ b/templates/header.templ deleted file mode 100644 index 66393fd..0000000 --- a/templates/header.templ +++ /dev/null @@ -1,12 +0,0 @@ -package templates - -templ header() { - -} diff --git a/utils/auth.go b/utils/auth.go index 108440c..d4b585b 100644 --- a/utils/auth.go +++ b/utils/auth.go @@ -1,30 +1 @@ package utils - -// import ( -// "context" -// "log" -// ) - -// func VerifyToken(token string) (*auth.Token, error) { -// if app == nil { -// setup() -// } -// -// client, err := app.Auth(context.Background()) -// if err != nil { -// log.Fatalf("error getting Auth client: %v\n", err) -// } -// return client.VerifyIDToken(context.Background(), token) -// } -// -// func setup() { -// opt := option.WithCredentialsFile("./secrets/firebase.json") -// -// firebaseApp, err := firebase.NewApp(context.Background(), nil, opt) -// -// if err != nil { -// log.Fatalf("error initializing app: %v", err) -// } -// -// app = firebaseApp -// }