2024-04-27 22:07:20 +07:00
|
|
|
package homeview
|
|
|
|
|
|
|
|
import "github.com/tigorlazuardi/redmage/models"
|
|
|
|
import "github.com/tigorlazuardi/redmage/api/reddit"
|
|
|
|
import "fmt"
|
2024-04-28 22:00:56 +07:00
|
|
|
import "github.com/tigorlazuardi/redmage/views/utils"
|
2024-04-27 22:07:20 +07:00
|
|
|
|
|
|
|
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) {
|
2024-04-29 14:39:39 +07:00
|
|
|
<div class="not-prose card card-bordered bg-base-100 hover:bg-base-200 shadow-xl w-[256px] min-w-[256px] rounded-xl top-0 hover:-top-1 hover:drop-shadow-2xl transition-all">
|
2024-04-27 22:07:20 +07:00
|
|
|
<figure>
|
|
|
|
<a
|
|
|
|
href={ templ.URL(fmt.Sprintf("/img/%s", data.ImageRelativePath)) }
|
|
|
|
>
|
|
|
|
<img
|
2024-04-28 10:25:09 +07:00
|
|
|
class="object-contain w-[256px] h-[256px]"
|
2024-04-27 22:07:20 +07:00
|
|
|
src={ fmt.Sprintf("/img/%s", data.ThumbnailRelativePath) }
|
|
|
|
alt={ data.Title }
|
|
|
|
/>
|
|
|
|
</a>
|
|
|
|
</figure>
|
|
|
|
<div class="card-body">
|
|
|
|
if !opts.Has(HideTitle) {
|
|
|
|
<a
|
|
|
|
href={ templ.URL(data.PostURL) }
|
2024-04-29 13:31:09 +07:00
|
|
|
class="card-title font-bold underline text-base text-primary"
|
2024-04-27 22:07:20 +07:00
|
|
|
>{ data.Title }</a>
|
|
|
|
}
|
2024-04-29 13:31:09 +07:00
|
|
|
<a class="text-primary underline" href={ templ.URL(data.PosterURL) }>{ data.Poster }</a>
|
2024-04-28 22:00:56 +07:00
|
|
|
<div>
|
|
|
|
@utils.RelativeTimeNode(fmt.Sprintf("relative-time-%s", data.PostName), data.CreatedAt)
|
|
|
|
</div>
|
2024-04-28 10:25:09 +07:00
|
|
|
<div class="card-actions justify-between">
|
|
|
|
if data.R.Subreddit != nil {
|
|
|
|
if !opts.Has(HideSubreddit) {
|
|
|
|
<a
|
2024-04-29 13:31:09 +07:00
|
|
|
class="badge badge-outline badge-primary"
|
2024-04-28 10:25:09 +07:00
|
|
|
href={ templ.URL(fmt.Sprintf("https://reddit.com/%s/%s", reddit.SubredditType(data.R.Subreddit.Subtype), data.R.Subreddit.Name)) }
|
|
|
|
>{ data.R.Subreddit.Name } </a>
|
|
|
|
}
|
2024-04-27 22:07:20 +07:00
|
|
|
}
|
2024-04-28 10:25:09 +07:00
|
|
|
</div>
|
2024-04-27 22:07:20 +07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
2024-04-28 10:25:09 +07:00
|
|
|
|
|
|
|
templ RecentlyAddedImageList(images models.ImageSlice, opts ImageCardOption) {
|
|
|
|
<div class="w-[100vw] lg:w-[80vw] overflow-x-scroll flex gap-4 p-8 shadow-inner bg-base-300">
|
|
|
|
for _, data := range images {
|
|
|
|
@RecentlyAddedImageCard(data, opts)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
}
|