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
Images models.ImageSlice
TotalImages int64
Error string
Params api.SubredditGetByNameImageParams
}
templ Detailsview(c *views.Context, data Data) {
@components.Doctype() {
@components.Head(c, components.HeadTitle(fmt.Sprintf("Subreddit - %s", data.Subreddit.Name)))
@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)
@showingImageFromTo(data)
@paginationButtons(c, data)
for _, image := range data.Images {
@components.ImageCard(image, 0)
}
@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 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)
}