Redmage/views/homeview/homeview.templ

124 lines
3.6 KiB
Plaintext
Raw Normal View History

2024-04-08 16:59:42 +07:00
package homeview
import "github.com/tigorlazuardi/redmage/views/components"
import "github.com/tigorlazuardi/redmage/views"
import "github.com/tigorlazuardi/redmage/views/utils"
import "strconv"
import "fmt"
2024-04-09 16:09:08 +07:00
templ Home(c *views.Context, data Data) {
@components.Doctype() {
2024-04-30 15:28:04 +07:00
@components.Head(c,
components.Dayjs(),
components.HeadTitle("Redmage - Home"),
)
2024-04-09 16:09:08 +07:00
@components.Body(c) {
2024-04-29 15:18:23 +07:00
@HomeContent(c, data)
2024-04-09 16:09:08 +07:00
}
}
2024-04-08 16:59:42 +07:00
}
2024-04-09 16:09:08 +07:00
2024-04-29 15:18:23 +07:00
// HomeContent returns the main content of the home page.
//
// Use this template if request is HX-Boosted.
templ HomeContent(c *views.Context, data Data) {
2024-04-30 15:28:04 +07:00
<main class="prose min-w-full">
2024-04-29 15:18:23 +07:00
@components.Container() {
if data.Error != "" {
@components.ErrorToast(data.Error)
} else {
<section class="mb-4 mx-auto">
2024-04-29 22:47:57 +07:00
<div
2024-04-30 14:12:33 +07:00
class="flex flex-wrap content-center gap-x-8"
2024-04-29 22:47:57 +07:00
hx-get="/"
hx-target="#recently-added-images"
hx-select="#recently-added-images"
2024-04-29 22:47:57 +07:00
hx-swap="outerHTML"
hx-trigger="change"
hx-include="this"
hx-push-url="true"
>
2024-04-30 14:12:33 +07:00
<h1 class="mb-4">
Recently Added
</h1>
2024-04-29 22:47:57 +07:00
@recentRangeInput(c)
@nsfwToggle(c, data)
</div>
<div id="recently-added-images">
if data.TotalImages == 0 {
<h2 class="mt-4">There are no recently added images in the current time range.</h2>
} else {
<h2 class="mt-4">
2024-05-01 14:27:09 +07:00
{ strconv.FormatInt(data.TotalImages, 10) } Images
</h2>
2024-04-29 15:18:23 +07:00
}
for _, recently := range data.RecentlyAddedImages {
<div class="divider"></div>
<h2 class="mt-4">{ recently.Device.Name }</h2>
for _, subreddit := range recently.Subreddits {
<h4>
2024-04-30 15:28:04 +07:00
<a class="text-primary" href={ templ.SafeURL(fmt.Sprintf("/subreddits/details/%s?device=%s", subreddit.Subreddit.Name, recently.Device.Slug)) }>
{ subreddit.Subreddit.Name }
</a>
- { strconv.Itoa(len(subreddit.Images)) } images
</h4>
@RecentlyAddedImageList(subreddit.Images, 0)
}
}
</div>
2024-04-29 15:18:23 +07:00
</section>
<section>
<h1>Subreddits</h1>
for _, subreddit := range data.SubredditsList.Data {
<h3>
{ subreddit.Name } -
@utils.RelativeTimeNode(subreddit.Name, utils.NextScheduleTime(subreddit.Schedule).Unix())
2024-04-29 15:18:23 +07:00
</h3>
}
</section>
2024-04-09 21:49:23 +07:00
}
2024-04-29 15:18:23 +07:00
}
</main>
2024-04-09 16:09:08 +07:00
}
2024-04-29 22:47:57 +07:00
templ recentRangeInput(c *views.Context) {
<select
name="created_at"
class="select select-ghost select-bordered"
>
@recentlyRangeOption(c, "-10800", "3 Hours")
@recentlyRangeOption(c, "-21600", "6 Hours")
@recentlyRangeOption(c, "-43200", "12 Hours")
@recentlyRangeOption(c, "-86400", "1 Day")
@recentlyRangeOption(c, "-172800", "2 Days")
@recentlyRangeOption(c, "-259200", "3 Days")
@recentlyRangeOption(c, "-604800", "7 Days")
@recentlyRangeOption(c, "-2592000", "30 Days")
</select>
}
templ recentlyRangeOption(c *views.Context, value, text string) {
if c.Request.URL.Query().Get("created_at") == "" && value == "-86400" {
<option selected="selected" value={ value }>{ text }</option>
} else if c.Request.URL.Query().Get("created_at") == value {
<option selected="selected" value={ value }>{ text }</option>
} else {
<option value={ value }>{ text }</option>
}
}
2024-04-29 22:47:57 +07:00
templ nsfwToggle(c *views.Context, data Data) {
<select
name="sfw"
class="select select-ghost select-bordered"
>
if (c.Request.URL.Query().Get("sfw") == "1") || data.SFW {
<option value="0">NSFW - Show</option>
<option selected="selected" value="1">NSFW - Hide</option>
2024-04-29 22:47:57 +07:00
} else {
<option selected="selected" value="0">NSFW - Show</option>
<option value="1">NSFW - Hide</option>
2024-04-29 22:47:57 +07:00
}
</select>
}