package detailsview import "github.com/tigorlazuardi/redmage/views" import "github.com/tigorlazuardi/redmage/models" import "github.com/tigorlazuardi/redmage/views/components" import "strconv" import "github.com/tigorlazuardi/redmage/api" import "fmt" type Data struct { Subreddit *models.Subreddit Devices models.DeviceSlice Images models.ImageSlice TotalImages int64 Error string Params api.SubredditGetByNameImageParams } templ Detailsview(c *views.Context, data Data) { @components.Doctype() { if data.Subreddit != nil { @components.Head(c, components.HeadTitle(fmt.Sprintf("Subreddit - %s", data.Subreddit.Name))) } else { @components.Head(c, components.HeadTitle("Subreddit - 404 NOT FOUND")) } @components.Body(c) { @DetailsContent(c, data) @components.NotificationContainer() } } } templ DetailsContent(c *views.Context, data Data) {
@components.Container() { if data.Error != "" {

Error: { data.Error }

} else {

Subreddit { data.Subreddit.Name }

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

@FilterBar(c, data) @paginationButtons(c, data) @showingImageFromTo(data)
for _, image := range data.Images { @components.ImageCard(image, components.HideNothing.SetCond(components.HideDevice, data.Params.Device != "")) }
@paginationButtons(c, data)
} }
} templ FilterBar(c *views.Context, data Data) {
} templ paginationButtons(_ *views.Context, data Data) { if data.TotalImages > data.Params.Limit {
for i, count := 1, int64(0); count < data.TotalImages; i, count = i+1, count+data.Params.Limit { if data.Params.Offset <= count && data.Params.Offset > count-data.Params.Limit { { strconv.Itoa(i) } } else { { strconv.Itoa(i) } } }
} } func buildURL(subreddit string, params api.SubredditGetByNameImageParams, extraQueries ...string) templ.SafeURL { queries := params.IntoQueryWith(extraQueries...) return templ.SafeURL(fmt.Sprintf("/subreddits/details/%s?%s", subreddit, queries.Encode())) } templ limitOption(params api.SubredditGetByNameImageParams, value int) { if int(params.Limit) == value { } else { } } templ deviceOption(params api.SubredditGetByNameImageParams, device *models.Device) { if params.Device == device.Slug { } else { } } templ showingImageFromTo(data Data) { if data.TotalImages > 1 {

{ showingFromToImages(data) }

} } func showingFromToImages(data Data) string { params := data.Params 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) }