view: added barebone schedule history page

This commit is contained in:
Tigor Hutasuhut 2024-05-04 22:17:50 +07:00
parent e7473563ac
commit fb54633390
5 changed files with 69 additions and 22 deletions

View file

@ -16,6 +16,8 @@ func (routes *Routes) PageHome(rw http.ResponseWriter, r *http.Request) {
ctx, span := tracer.Start(r.Context(), "routes.PageHome") ctx, span := tracer.Start(r.Context(), "routes.PageHome")
defer span.End() defer span.End()
var data homeview.Data
vc := views.NewContext(routes.Config, r) vc := views.NewContext(routes.Config, r)
listSubredditParams := parseSubredditListQuery(r) listSubredditParams := parseSubredditListQuery(r)
@ -48,12 +50,10 @@ func (routes *Routes) PageHome(rw http.ResponseWriter, r *http.Request) {
return return
} }
data := homeview.Data{ data.SubredditsList = list
SubredditsList: list, data.RecentlyAddedImages = homeview.NewRecentlyAddedImages(imageList.Images)
RecentlyAddedImages: homeview.NewRecentlyAddedImages(imageList.Images), data.Now = time.Now()
Now: time.Now(), data.TotalImages = imageList.Total
TotalImages: imageList.Total,
}
if err := homeview.Home(vc, data).Render(ctx, rw); err != nil { if err := homeview.Home(vc, data).Render(ctx, rw); err != nil {
log.New(ctx).Err(err).Error("failed to render home view") log.New(ctx).Err(err).Error("failed to render home view")

View file

@ -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")
}
}

View file

@ -81,5 +81,6 @@ func (routes *Routes) registerWWWRoutes(router chi.Router) {
r.Get("/subreddits/details/{name}", routes.PageSubredditsDetails) r.Get("/subreddits/details/{name}", routes.PageSubredditsDetails)
r.Get("/subreddits/add", routes.PageSubredditsAdd) r.Get("/subreddits/add", routes.PageSubredditsAdd)
r.Get("/config", routes.PageConfig) r.Get("/config", routes.PageConfig)
r.Get("/schedules", routes.PageScheduleHistory)
}) })
} }

View file

@ -3,7 +3,6 @@ package components
import "github.com/tigorlazuardi/redmage/views" import "github.com/tigorlazuardi/redmage/views"
import "strings" import "strings"
import "github.com/tigorlazuardi/redmage/views/utils" import "github.com/tigorlazuardi/redmage/views/utils"
import "strconv"
templ Navigation(c *views.Context) { templ Navigation(c *views.Context) {
<div class="drawer"> <div class="drawer">
@ -76,7 +75,7 @@ templ Navbar(c *views.Context) {
<span class="font-bold">Redmage</span> <span class="font-bold">Redmage</span>
</div> </div>
<div class="divider"></div> <div class="divider"></div>
<nav class="flex-grow pt-4 min-h-full flex flex-col transition-all"> <nav hx-boost="true" class="flex-grow pt-4 min-h-full flex flex-col transition-all">
@navList(c) @navList(c)
</nav> </nav>
</div> </div>
@ -84,18 +83,18 @@ templ Navbar(c *views.Context) {
} }
templ navList(c *views.Context) { templ navList(c *views.Context) {
@createLink(c, "/", "Home", true) @createLink(c, "/", "Home")
@createLink(c, "/config", "Config", false) @createLink(c, "/config", "Config")
@createLink(c, "/devices", "Devices", true) @createLink(c, "/devices", "Devices")
@createLink(c, "/subreddits", "Subreddits", true) @createLink(c, "/subreddits", "Subreddits")
@createLink(c, "/schedules", "Schedules", true) @createLink(c, "/schedules", "Schedules")
<div class="flex-1 flex-shrink-0"></div> <div class="flex-1 flex-shrink-0"></div>
<div class="divider"></div> <div class="divider"></div>
@createLink(c, "/about", "About", true) @createLink(c, "/about", "About")
<div class="mt-4"></div> <div class="mt-4"></div>
} }
templ createLink(c *views.Context, path string, text string, boost bool) { templ createLink(c *views.Context, path string, text string) {
<a <a
href={ templ.URL(path) } href={ templ.URL(path) }
class={ utils.CX(map[string]bool{ class={ utils.CX(map[string]bool{
@ -106,7 +105,6 @@ templ createLink(c *views.Context, path string, text string, boost bool) {
"font-bold": isCurrentPage(c, path), "font-bold": isCurrentPage(c, path),
"hover:font-bold": true, "hover:font-bold": true,
}) } }) }
hx-boost={ strconv.FormatBool(boost) }
>{ text }</a> >{ text }</a>
} }

View file

@ -0,0 +1,26 @@
package scheduleshistoryview
import "github.com/tigorlazuardi/redmage/views"
import "github.com/tigorlazuardi/redmage/views/components"
type Data struct{}
templ ScheduleHistoriesview(c *views.Context, data Data) {
@components.Doctype() {
@components.Head(c,
components.HeadTitle("Schedule History"),
)
@components.Body(c) {
@ScheduleHistoriesContent(c, data)
}
}
}
templ ScheduleHistoriesContent(c *views.Context, data Data) {
@components.Container() {
<main class="prose min-w-full">
<h1>Schedule History</h1>
<div class="divider"></div>
</main>
}
}