package homeview import "github.com/tigorlazuardi/redmage/views/components" import "github.com/tigorlazuardi/redmage/views" import "github.com/tigorlazuardi/redmage/views/utils" import "github.com/tigorlazuardi/redmage/models" import "strconv" import "fmt" templ Home(c *views.Context, data Data) { @components.Doctype() { @components.Head(c, components.HeadTitle("Redmage - Home"), ) @components.Body(c) { @HomeContent(c, data) } } } // HomeContent returns the main content of the home page. // // Use this template if request is HX-Boosted. templ HomeContent(c *views.Context, data Data) {
@components.Container() { if data.Error != "" { @components.ErrorToast(data.Error) } else {

Recently Added

@recentRangeInput(c) @nsfwToggle(c, data)
if data.TotalImages == 0 {

There are no recently added images in the current time range.

} else {

{ strconv.FormatInt(data.TotalImages, 10) } Images

} for _, recently := range data.RecentlyAddedImages {

{ recently.Device.Name }

for _, subreddit := range recently.Subreddits {

{ subreddit.Subreddit.Name } - { strconv.Itoa(len(subreddit.Images)) } images

@RecentlyAddedImageList(subreddit.Images, 0) } }

Subreddits

for _, subreddit := range data.SubredditsList.Data {

{ subreddit.Name } - @utils.RelativeTimeNode(subreddit.Name, utils.NextScheduleTime(subreddit.Schedule).Unix())

}
} }
} templ recentRangeInput(c *views.Context) { } templ recentlyRangeOption(c *views.Context, value, text string) { if c.Request.URL.Query().Get("created_at") == "" && value == "-86400" { } else if c.Request.URL.Query().Get("created_at") == value { } else { } } templ nsfwToggle(c *views.Context, data Data) { } templ RecentlyAddedImageList(images models.ImageSlice, opts components.ImageCardOption) {
for _, data := range images { @components.ImageCard(data, 0) }
}