package homeview import "github.com/tigorlazuardi/redmage/views/components" import "github.com/tigorlazuardi/redmage/views" import "github.com/tigorlazuardi/redmage/views/utils" import "strconv" import "fmt" import "github.com/tigorlazuardi/redmage/api" 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

@filterBar(c, data)
if data.TotalImages <= 0 {

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

} else {

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

@showingImageFromTo(data) }
@components.Pagination(c, components.PaginationData{ Limit: data.ImageListParams.Limit, Total: data.TotalImages, Offset: data.ImageListParams.Offset, BaseURL: "/", })
for _, recently := range data.RecentlyAddedImages {

{ recently.Device.Name }

for _, subreddit := range recently.Subreddits {

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

@components.HorizontalImageWell() { for _, data := range subreddit.Images { @components.ImageCard(data, components.HideDevice) } } } }

Subreddits

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

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

}
} }
} templ showingImageFromTo(data Data) { if data.TotalImages > 1 {

{ showingFromToImages(data) }

} } func showingFromToImages(data Data) string { params := data.ImageListParams start := params.Offset + 1 end := params.Limit + params.Offset if end > data.TotalImages { end = data.TotalImages } return fmt.Sprintf("Showing from %d to %d", start, end) } templ filterBar(c *views.Context, data Data) {
@nsfwToggle(data) @deviceFilterInput(data) @limitInput(data.ImageListParams) @recentRangeInput(c.Query.Get("created_at"))
} templ limitInput(params api.ImageListParams) { } templ recentRangeInput(current string) { } templ rangeOption(value, text string, selected bool) { } templ nsfwToggle(data Data) { } templ deviceFilterInput(data Data) { }