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) {
Error: { data.Error }
} else {
Subreddit { data.Subreddit.Name }
Total Images:
{ strconv.FormatInt(data.TotalImages, 10) }
@FilterBar(c, data)
{ 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) }