package homeview import "github.com/tigorlazuardi/redmage/models" import "github.com/tigorlazuardi/redmage/api/reddit" import "fmt" import "github.com/tigorlazuardi/redmage/views/utils" type ImageCardOption uint func (o ImageCardOption) Has(opt ImageCardOption) bool { return o&opt != 0 } const ( HideTitle ImageCardOption = 1 << iota HideDescription HideSubreddit HidePoster ) templ RecentlyAddedImageCard(data *models.Image, opts ImageCardOption) {
{
if !opts.Has(HideTitle) { { truncateTitle(data.Title) } } { data.Poster }
@utils.RelativeTimeNode(fmt.Sprintf("relative-time-%s", data.PostName), data.CreatedAt)
if data.R.Subreddit != nil { if !opts.Has(HideSubreddit) { { data.R.Subreddit.Name } } }
} func truncateTitle(title string) string { if len(title) > 50 { return title[:50] + "..." } return title } templ RecentlyAddedImageList(images models.ImageSlice, opts ImageCardOption) {
for _, data := range images { @RecentlyAddedImageCard(data, opts) }
}