From 648d3dff80209a54c189a196a7e890389cf933f4 Mon Sep 17 00:00:00 2001 From: efim Date: Sun, 5 Nov 2023 05:00:01 +0000 Subject: [PATCH] refactor: index page route separated --- routes/index_page.go | 37 +++++++++++++++++++++++++++++++++++ routes/routes.go | 13 +----------- routes/static/out.css | 9 +++++++++ routes/templates/index.gohtml | 6 +++++- 4 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 routes/index_page.go diff --git a/routes/index_page.go b/routes/index_page.go new file mode 100644 index 0000000..ce6eff0 --- /dev/null +++ b/routes/index_page.go @@ -0,0 +1,37 @@ +package routes + +import ( + "embed" + "fmt" + "html/template" + "log" + "net/http" + + "sunshine.industries/some-automoderation/rooms" + "sunshine.industries/some-automoderation/sessions" +) + +func indexPageRoute( + templateFs *embed.FS, + sessionSM sessions.SessionManagement, + roomsM rooms.RoomManager, +) http.HandlerFunc { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + var templFile = "templates/index.gohtml" + session := getContextSession(r.Context()) + data := struct { + SessionStringToken string + SomeString string + SessionToken sessions.SessionData + }{ + fmt.Sprintf("%+v", session), + "hello!", + session, + } + tmpl := template.Must(template.ParseFS(templateFs, templFile)) + err := tmpl.Execute(w, data) + if err != nil { + log.Printf("my error in executing template, huh\n %s", err) + } + }) +} diff --git a/routes/routes.go b/routes/routes.go index 74f913a..49da562 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -2,9 +2,6 @@ package routes import ( "embed" - "fmt" - "html/template" - "log" "net/http" "sunshine.industries/some-automoderation/rooms" @@ -24,15 +21,7 @@ func RegisterRoutes(sessionsM sessions.SessionManagement, rooms rooms.RoomManage // main page template http.Handle("/", authedPageMiddleware( sessionsM, - http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - var templFile = "templates/index.gohtml" - session := getContextSession(r.Context()) - tmpl := template.Must(template.ParseFS(templateFs, templFile)) - err := tmpl.Execute(w, fmt.Sprintf("%+v", session)) - if err != nil { - log.Printf("my error in executing template, huh\n %s", err) - } - }))) + indexPageRoute(&templateFs, sessionsM, rooms))) // static resources route http.Handle("/static/", diff --git a/routes/static/out.css b/routes/static/out.css index 3f5d1b9..ac08999 100644 --- a/routes/static/out.css +++ b/routes/static/out.css @@ -613,6 +613,15 @@ video { line-height: 1.75rem; } +.text-blue-700 { + --tw-text-opacity: 1; + color: rgb(29 78 216 / var(--tw-text-opacity)); +} + +.underline { + text-decoration-line: underline; +} + .invalid\:bg-red-700:invalid { --tw-bg-opacity: 1; background-color: rgb(185 28 28 / var(--tw-bg-opacity)); diff --git a/routes/templates/index.gohtml b/routes/templates/index.gohtml index 553d718..6419d11 100644 --- a/routes/templates/index.gohtml +++ b/routes/templates/index.gohtml @@ -31,6 +31,10 @@

Hello

This is index

-

Your session is {{ . }}

+

Your session is {{ .SessionStringToken }}

+

Some string is {{ .SomeString }}

+ You've logged into a room {{ .SessionToken.RoomId }}