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" 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 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() { if data.FlashMessageSuccess != "" { @components.SuccessNotification(data.FlashMessageSuccess) } } } } } 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)
@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 FilterBar(c *views.Context, data Data) {
} 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) }