Redmage/views/subredditsview/subredditsview.templ

73 lines
2.3 KiB
Plaintext
Raw Normal View History

2024-04-30 15:28:04 +07:00
package subredditsview
import "github.com/tigorlazuardi/redmage/views"
import "github.com/tigorlazuardi/redmage/views/components"
2024-05-01 18:16:54 +07:00
import "github.com/tigorlazuardi/redmage/models"
import "strconv"
import "fmt"
2024-04-30 15:28:04 +07:00
templ Subreddit(c *views.Context, data Data) {
@components.Doctype() {
@components.Head(c, components.HeadTitle("Redmage - Subreddits"))
@components.Body(c) {
@SubredditContent(c, data)
}
}
}
templ SubredditContent(c *views.Context, data Data) {
<main class="prose min-w-full">
@components.Container() {
<h1>Subreddits</h1>
2024-05-01 18:16:54 +07:00
if data.Subreddits.Total == 0 {
<div class="divider"></div>
2024-05-01 18:16:54 +07:00
<h3>No Subreddits Found</h3>
2024-04-30 15:28:04 +07:00
<p>Click <a class="text-primary" href="/subreddits/add">here</a> to add a new subreddit.</p>
2024-05-01 18:16:54 +07:00
} else {
2024-05-13 13:38:13 +07:00
<div class="flex justify-center sm:justify-between flex-wrap gap-4">
<h2 class="my-auto">{ strconv.FormatInt(data.Subreddits.Total, 10) } Subreddits Registered</h2>
<a class="btn btn-primary text-base-100 no-underline" href="/subreddits/add">Add Subreddit</a>
</div>
<div class="divider"></div>
2024-04-30 15:28:04 +07:00
}
<div class="flex flex-wrap gap-1 justify-around" hx-boost="true">
2024-05-01 18:16:54 +07:00
for _, subreddit := range data.Subreddits.Data {
@SubredditCard(c, subreddit)
}
</div>
2024-04-30 15:28:04 +07:00
}
</main>
}
2024-05-01 18:16:54 +07:00
templ SubredditCard(c *views.Context, data *models.Subreddit) {
2024-05-13 13:38:13 +07:00
<a
href={ templ.URL(fmt.Sprintf("/subreddits/details/%s", data.Name)) }
class="not-prose card card-bordered bg-base-100 hover:bg-base-200 shadow-xl xs:w-80 w-full max-w-full top-0 hover:-top-1 transition-all rounded-none"
>
2024-05-01 18:16:54 +07:00
if len(data.R.Images) > 0 {
<figure class="p-8">
2024-05-13 13:38:13 +07:00
<img
class="object-contain xs:max-w-[16rem] max-h-[16rem]"
src={ fmt.Sprintf("/img/%s", data.R.Images[0].ThumbnailRelativePath) }
alt={ data.Name }
/>
2024-05-01 18:16:54 +07:00
</figure>
} else {
<figure class="p-8">
2024-05-13 13:38:13 +07:00
@imagePlaceholder()
2024-05-01 18:16:54 +07:00
</figure>
}
<div class="card-body">
<div class="flex-1"></div>
2024-05-13 13:38:13 +07:00
<p class="text-center my-4 underline text-primary">{ data.Name }</p>
2024-05-01 18:16:54 +07:00
</div>
2024-05-13 13:38:13 +07:00
</a>
2024-05-01 18:16:54 +07:00
}
templ imagePlaceholder() {
<svg width="256" height="256" xmlns="http://www.w3.org/2000/svg">
<rect x="2" y="2" width="252" height="252" style="fill:#DEDEDE;stroke:#555555;stroke-width:2"></rect>
<text x="50%" y="50%" font-size="18" text-anchor="middle" alignment-baseline="middle" font-family="monospace, sans-serif" fill="#555555">256×256</text>
</svg>
}