Now worky

This commit is contained in:
Henri Burau 2024-06-04 14:49:57 +02:00
parent e2b9b8f176
commit b6555a1cc8
11 changed files with 58 additions and 6 deletions

5
.gitignore vendored
View File

@ -1,6 +1,7 @@
./assets/index.js assets/index.js
./assets/styles.js assets/styles.css
cod4watcher
local.db local.db
# Created by https://www.toptal.com/developers/gitignore/api/go # Created by https://www.toptal.com/developers/gitignore/api/go
# Edit at https://www.toptal.com/developers/gitignore?templates=go # Edit at https://www.toptal.com/developers/gitignore?templates=go

View File

@ -15,7 +15,7 @@ live/server:
# run tailwindcss to generate the styles.css bundle in watch mode. # run tailwindcss to generate the styles.css bundle in watch mode.
live/tailwind: live/tailwind:
npx tailwindcss -i ./style/input.css -o ./assets/styles.css --minify --watch npx tailwindcss -i ./style/input.css -o ./assets/styles.css --minify --watch=forever
# run esbuild to generate the index.js bundle in watch mode. # run esbuild to generate the index.js bundle in watch mode.
live/esbuild: live/esbuild:

Binary file not shown.

View File

@ -38,6 +38,7 @@ func main() {
go scanner.Scan() go scanner.Scan()
router.Use(routes.PathMiddleware)
router.Handle("/*", public()) router.Handle("/*", public())
router.Get("/health", routes.Make(server.HandleHealth)) router.Get("/health", routes.Make(server.HandleHealth))
router.Get("/captures/{captureID}", routes.Make(server.HandleCapture)) router.Get("/captures/{captureID}", routes.Make(server.HandleCapture))

View File

@ -4,6 +4,7 @@ import (
"net/http" "net/http"
"gitea.henriburau.de/haw-lan/cod4watcher/views/home" "gitea.henriburau.de/haw-lan/cod4watcher/views/home"
"github.com/davecgh/go-spew/spew"
) )
func (s *Server) HandleHome(w http.ResponseWriter, r *http.Request) error { func (s *Server) HandleHome(w http.ResponseWriter, r *http.Request) error {
@ -12,5 +13,7 @@ func (s *Server) HandleHome(w http.ResponseWriter, r *http.Request) error {
return err return err
} }
spew.Dump(r.Context())
return Render(w, r, home.Index(captureList)) return Render(w, r, home.Index(captureList))
} }

15
routes/path_middleware.go Normal file
View File

@ -0,0 +1,15 @@
package routes
import (
"context"
"net/http"
"gitea.henriburau.de/haw-lan/cod4watcher/views"
)
func PathMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(r.Context(), views.PathContext, r.URL.Path)
next.ServeHTTP(w, r.WithContext(ctx))
})
}

Binary file not shown.

View File

@ -1,5 +1,7 @@
package components package components
import "gitea.henriburau.de/haw-lan/cod4watcher/views"
templ Nagivation() { templ Nagivation() {
<nav class="bg-gray-800"> <nav class="bg-gray-800">
<div class="mx-auto max-w-7xl"> <div class="mx-auto max-w-7xl">
@ -12,8 +14,13 @@ templ Nagivation() {
<div class="hidden sm:ml-6 sm:block"> <div class="hidden sm:ml-6 sm:block">
<div class="flex space-x-4"> <div class="flex space-x-4">
<!-- Current: "bg-gray-900 text-white", Default: "text-gray-300 hover:bg-gray-700 hover:text-white" --> <!-- Current: "bg-gray-900 text-white", Default: "text-gray-300 hover:bg-gray-700 hover:text-white" -->
if ctx.Value(views.PathContext) == "" || ctx.Value(views.PathContext) == "/" {
<a href="/" class="bg-gray-900 text-white rounded-md px-3 py-2 text-sm font-medium" aria-current="page">Dashboard</a> <a href="/" class="bg-gray-900 text-white rounded-md px-3 py-2 text-sm font-medium" aria-current="page">Dashboard</a>
<a href="/about" class="text-gray-300 hover:bg-gray-700 hover:text-white rounded-md px-3 py-2 text-sm font-medium">About</a> <a href="/about" class="text-gray-300 hover:bg-gray-700 hover:text-white rounded-md px-3 py-2 text-sm font-medium">About</a>
} else {
<a href="/" class="text-gray-300 hover:bg-gray-700 hover:text-white rounded-md px-3 py-2 text-sm font-medium">Dashboard</a>
<a href="/about" class="text-gray-300 hover:bg-gray-700 hover:text-white rounded-md px-3 py-2 text-sm font-medium">About</a>
}
</div> </div>
</div> </div>
</div> </div>

View File

@ -10,6 +10,8 @@ import "context"
import "io" import "io"
import "bytes" import "bytes"
import "gitea.henriburau.de/haw-lan/cod4watcher/views"
func Nagivation() templ.Component { func Nagivation() templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { 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) templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
@ -27,6 +29,21 @@ func Nagivation() templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if ctx.Value(views.PathContext) == "" || ctx.Value(views.PathContext) == "/" {
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
} }

View File

@ -1 +1,4 @@
<nav class=\"bg-gray-800\"><div class=\"mx-auto max-w-7xl\"><div class=\"relative flex h-16 items-center justify-between\"><div class=\"flex flex-1 items-center justify-center sm:items-stretch sm:justify-start\"><div class=\"flex flex-shrink-0 items-center\"><span class=\"text-white pr-2 font-bold\">Turnier-Tracker</span> <img class=\"h-8 w-auto\" src=\"/assets/logo.svg\" alt=\"Your Company\"></div><div class=\"hidden sm:ml-6 sm:block\"><div class=\"flex space-x-4\"><!-- Current: \"bg-gray-900 text-white\", Default: \"text-gray-300 hover:bg-gray-700 hover:text-white\" --><a href=\"/\" class=\"bg-gray-900 text-white rounded-md px-3 py-2 text-sm font-medium\" aria-current=\"page\">Dashboard</a> <a href=\"/about\" class=\"text-gray-300 hover:bg-gray-700 hover:text-white rounded-md px-3 py-2 text-sm font-medium\">About</a></div></div></div><div class=\"absolute inset-y-0 right-0 flex items-center pr-2 sm:static sm:inset-auto sm:ml-6 sm:pr-0\"></div></div></div></nav> <nav class=\"bg-gray-800\"><div class=\"mx-auto max-w-7xl\"><div class=\"relative flex h-16 items-center justify-between\"><div class=\"flex flex-1 items-center justify-center sm:items-stretch sm:justify-start\"><div class=\"flex flex-shrink-0 items-center\"><span class=\"text-white pr-2 font-bold\">Turnier-Tracker</span> <img class=\"h-8 w-auto\" src=\"/assets/logo.svg\" alt=\"Your Company\"></div><div class=\"hidden sm:ml-6 sm:block\"><div class=\"flex space-x-4\"><!-- Current: \"bg-gray-900 text-white\", Default: \"text-gray-300 hover:bg-gray-700 hover:text-white\" -->
<a href=\"/\" class=\"bg-gray-900 text-white rounded-md px-3 py-2 text-sm font-medium\" aria-current=\"page\">Dashboard</a> <a href=\"/about\" class=\"text-gray-300 hover:bg-gray-700 hover:text-white rounded-md px-3 py-2 text-sm font-medium\">About</a>
<a href=\"/\" class=\"text-gray-300 hover:bg-gray-700 hover:text-white rounded-md px-3 py-2 text-sm font-medium\">Dashboard</a> <a href=\"/about\" class=\"text-gray-300 hover:bg-gray-700 hover:text-white rounded-md px-3 py-2 text-sm font-medium\">About</a>
</div></div></div><div class=\"absolute inset-y-0 right-0 flex items-center pr-2 sm:static sm:inset-auto sm:ml-6 sm:pr-0\"></div></div></div></nav>

5
views/context.go Normal file
View File

@ -0,0 +1,5 @@
package views
type contextKey string
var PathContext = contextKey("path")