From fb54633390e3457fda694968a2f687c2a88079f8 Mon Sep 17 00:00:00 2001 From: Tigor Hutasuhut Date: Sat, 4 May 2024 22:17:50 +0700 Subject: [PATCH] view: added barebone schedule history page --- server/routes/page_home.go | 12 ++++---- server/routes/page_schedule_history.go | 22 ++++++++++++++ server/routes/routes.go | 1 + views/components/navigation.templ | 30 +++++++++---------- .../schedulehistoriesview/schedulesview.templ | 26 ++++++++++++++++ 5 files changed, 69 insertions(+), 22 deletions(-) create mode 100644 server/routes/page_schedule_history.go create mode 100644 views/schedulehistoriesview/schedulesview.templ diff --git a/server/routes/page_home.go b/server/routes/page_home.go index 5bc1d27..4ccfe4d 100644 --- a/server/routes/page_home.go +++ b/server/routes/page_home.go @@ -16,6 +16,8 @@ func (routes *Routes) PageHome(rw http.ResponseWriter, r *http.Request) { ctx, span := tracer.Start(r.Context(), "routes.PageHome") defer span.End() + var data homeview.Data + vc := views.NewContext(routes.Config, r) listSubredditParams := parseSubredditListQuery(r) @@ -48,12 +50,10 @@ func (routes *Routes) PageHome(rw http.ResponseWriter, r *http.Request) { return } - data := homeview.Data{ - SubredditsList: list, - RecentlyAddedImages: homeview.NewRecentlyAddedImages(imageList.Images), - Now: time.Now(), - TotalImages: imageList.Total, - } + data.SubredditsList = list + data.RecentlyAddedImages = homeview.NewRecentlyAddedImages(imageList.Images) + data.Now = time.Now() + data.TotalImages = imageList.Total if err := homeview.Home(vc, data).Render(ctx, rw); err != nil { log.New(ctx).Err(err).Error("failed to render home view") diff --git a/server/routes/page_schedule_history.go b/server/routes/page_schedule_history.go new file mode 100644 index 0000000..4ea448e --- /dev/null +++ b/server/routes/page_schedule_history.go @@ -0,0 +1,22 @@ +package routes + +import ( + "net/http" + + "github.com/tigorlazuardi/redmage/pkg/log" + "github.com/tigorlazuardi/redmage/views" + scheduleshistoryview "github.com/tigorlazuardi/redmage/views/schedulehistoriesview" +) + +func (routes *Routes) PageScheduleHistory(rw http.ResponseWriter, req *http.Request) { + ctx, span := tracer.Start(req.Context(), "*Routes.PageScheduleHistory") + defer span.End() + + c := views.NewContext(routes.Config, req) + + var data scheduleshistoryview.Data + + if err := scheduleshistoryview.ScheduleHistoriesview(c, data).Render(ctx, rw); err != nil { + log.New(ctx).Err(err).Error("Failed to render schedule histories view") + } +} diff --git a/server/routes/routes.go b/server/routes/routes.go index 9d40ddb..598be04 100644 --- a/server/routes/routes.go +++ b/server/routes/routes.go @@ -81,5 +81,6 @@ func (routes *Routes) registerWWWRoutes(router chi.Router) { r.Get("/subreddits/details/{name}", routes.PageSubredditsDetails) r.Get("/subreddits/add", routes.PageSubredditsAdd) r.Get("/config", routes.PageConfig) + r.Get("/schedules", routes.PageScheduleHistory) }) } diff --git a/views/components/navigation.templ b/views/components/navigation.templ index 94c45d0..425b95e 100644 --- a/views/components/navigation.templ +++ b/views/components/navigation.templ @@ -3,7 +3,6 @@ package components import "github.com/tigorlazuardi/redmage/views" import "strings" import "github.com/tigorlazuardi/redmage/views/utils" -import "strconv" templ Navigation(c *views.Context) {
@@ -76,7 +75,7 @@ templ Navbar(c *views.Context) { Redmage
-