package details 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" import "github.com/tigorlazuardi/redmage/views/icons" type Data struct { Subreddit *models.Subreddit Devices models.DeviceSlice Images models.ImageSlice TotalImages int64 Error string Params api.SubredditGetByNameImageParams FlashMessageSuccess string } templ View(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) { @Content(c, data) @components.NotificationContainer() { if data.FlashMessageSuccess != "" { @components.SuccessNotification(data.FlashMessageSuccess) } } } } } templ Content(c *views.Context, data Data) {
@components.Container() { if data.Error != "" {

Error: { data.Error }

} else {

Subreddit { data.Subreddit.Name }

@actionButton(data)
@FilterBar(c, data)

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

@components.Pagination(c, components.PaginationData{ Offset: data.Params.Offset, Limit: data.Params.Limit, BaseURL: fmt.Sprintf("/subreddits/details/%s", data.Subreddit.Name), Total: data.TotalImages, })
@showingImageFromTo(data)
for _, image := range data.Images { @components.ImageCard(image, components.HideNothing.SetCond(components.HideDevice, data.Params.Device != "")) }
@components.Pagination(c, components.PaginationData{ Offset: data.Params.Offset, Limit: data.Params.Limit, BaseURL: fmt.Sprintf("/subreddits/details/%s", data.Subreddit.Name), Total: data.TotalImages, })
} }
} templ actionButton(data Data) {
} 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) }