2024-04-08 16:59:42 +07:00
|
|
|
package homeview
|
|
|
|
|
2024-04-08 21:50:52 +07:00
|
|
|
import "github.com/tigorlazuardi/redmage/views/components"
|
|
|
|
import "github.com/tigorlazuardi/redmage/views"
|
2024-04-28 22:00:56 +07:00
|
|
|
import "github.com/tigorlazuardi/redmage/views/utils"
|
2024-04-29 21:45:18 +07:00
|
|
|
import "strconv"
|
2024-04-30 12:54:16 +07:00
|
|
|
import "fmt"
|
2024-05-29 13:22:02 +07:00
|
|
|
import "github.com/tigorlazuardi/redmage/api"
|
2024-04-09 16:09:08 +07:00
|
|
|
|
|
|
|
templ Home(c *views.Context, data Data) {
|
2024-04-08 21:50:52 +07:00
|
|
|
@components.Doctype() {
|
2024-04-30 15:28:04 +07:00
|
|
|
@components.Head(c,
|
|
|
|
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 21:50:52 +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.
|
2024-04-29 21:45:18 +07:00
|
|
|
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-05-13 15:27:36 +07:00
|
|
|
<h1 class="mb-4">Recently Added</h1>
|
|
|
|
@filterBar(c, data)
|
2024-04-30 12:54:16 +07:00
|
|
|
<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>
|
2024-05-01 00:02:30 +07:00
|
|
|
} else {
|
|
|
|
<h2 class="mt-4">
|
2024-05-01 14:27:09 +07:00
|
|
|
{ strconv.FormatInt(data.TotalImages, 10) } Images
|
2024-05-01 00:02:30 +07:00
|
|
|
</h2>
|
2024-04-29 15:18:23 +07:00
|
|
|
}
|
2024-04-30 12:54:16 +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)) }>
|
2024-04-30 12:54:16 +07:00
|
|
|
{ subreddit.Subreddit.Name }
|
|
|
|
</a>
|
|
|
|
- { strconv.Itoa(len(subreddit.Images)) } images
|
|
|
|
</h4>
|
2024-05-13 15:27:36 +07:00
|
|
|
@components.HorizontalImageWell() {
|
|
|
|
for _, data := range subreddit.Images {
|
|
|
|
@components.ImageCard(data, components.HideDevice)
|
|
|
|
}
|
|
|
|
}
|
2024-04-30 12:54:16 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</div>
|
2024-04-29 15:18:23 +07:00
|
|
|
</section>
|
|
|
|
<section>
|
|
|
|
<h1>Subreddits</h1>
|
|
|
|
for _, subreddit := range data.SubredditsList.Data {
|
|
|
|
<h3>
|
|
|
|
{ subreddit.Name } -
|
2024-04-29 21:45:18 +07:00
|
|
|
@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 21:45:18 +07:00
|
|
|
|
2024-05-13 15:27:36 +07:00
|
|
|
templ filterBar(c *views.Context, data Data) {
|
|
|
|
<div
|
|
|
|
id="filter-bar"
|
|
|
|
hx-get="/"
|
|
|
|
hx-target="#recently-added-images"
|
|
|
|
hx-select="#recently-added-images"
|
|
|
|
hx-swap="outerHTML"
|
|
|
|
hx-trigger="change"
|
|
|
|
hx-include="this"
|
|
|
|
hx-push-url="true"
|
|
|
|
class="grid grid-cols-[1fr,4fr] sm:grid-cols-[1fr,4fr,1fr,4fr] items-center gap-4"
|
|
|
|
>
|
|
|
|
@nsfwToggle(data)
|
2024-05-29 13:22:02 +07:00
|
|
|
@limitInput(data.ImageListParams)
|
2024-05-13 15:27:36 +07:00
|
|
|
@recentRangeInput(c.Query.Get("created_at"))
|
2024-05-04 19:39:02 +07:00
|
|
|
</div>
|
2024-04-29 22:47:57 +07:00
|
|
|
}
|
|
|
|
|
2024-05-29 13:22:02 +07:00
|
|
|
templ limitInput(params api.ImageListParams) {
|
|
|
|
<label for="limit" class="label">Limit</label>
|
|
|
|
<select id="limit" name="limit" class="select select-bordered w-full">
|
|
|
|
<option value="0" selected?={ params.Limit ==0 }>*No Limit</option>
|
|
|
|
<option value="25" selected?={ params.Limit == 25 }>25</option>
|
|
|
|
<option value="50" selected?={ params.Limit == 50 }>50</option>
|
|
|
|
<option value="75" selected?={ params.Limit == 75 }>75</option>
|
|
|
|
<option value="100" selected?={ params.Limit == 100 }>100</option>
|
|
|
|
<option value="200" selected?={ params.Limit == 200 }>200</option>
|
|
|
|
<option value="300" selected?={ params.Limit == 300 }>300</option>
|
|
|
|
</select>
|
|
|
|
}
|
|
|
|
|
2024-05-13 15:27:36 +07:00
|
|
|
templ recentRangeInput(current string) {
|
|
|
|
<label for="range" class="label">Range</label>
|
|
|
|
<select
|
|
|
|
id="range"
|
|
|
|
name="created_at"
|
2024-05-29 13:22:02 +07:00
|
|
|
class="select select-ghost select-bordered w-full"
|
2024-05-13 15:27:36 +07:00
|
|
|
>
|
|
|
|
@rangeOption("-10800", "3 Hours", current == "-10800")
|
|
|
|
@rangeOption("-21600", "6 Hours", current == "-21600")
|
|
|
|
@rangeOption("-43200", "12 Hours", current == "-43200")
|
|
|
|
@rangeOption("-86400", "1 Day", current == "-86400" || current == "")
|
|
|
|
@rangeOption("-172800", "2 Days", current == "-172800")
|
|
|
|
@rangeOption("-259200", "3 Days", current == "-259200")
|
|
|
|
@rangeOption("-604800", "7 Days", current == "-604800")
|
2024-05-29 13:22:02 +07:00
|
|
|
@rangeOption("-2592000", "30 Days", current == "-2592000")
|
2024-05-13 15:27:36 +07:00
|
|
|
</select>
|
2024-04-29 21:45:18 +07:00
|
|
|
}
|
2024-04-29 22:47:57 +07:00
|
|
|
|
2024-05-13 15:27:36 +07:00
|
|
|
templ rangeOption(value, text string, selected bool) {
|
|
|
|
<option selected?={ selected } value={ value }>{ text }</option>
|
2024-04-29 22:47:57 +07:00
|
|
|
}
|
2024-05-02 15:42:10 +07:00
|
|
|
|
2024-05-13 15:27:36 +07:00
|
|
|
templ nsfwToggle(data Data) {
|
|
|
|
<label for="nsfw" class="label">NSFW</label>
|
|
|
|
<select
|
|
|
|
id="nsfw"
|
2024-05-29 13:22:02 +07:00
|
|
|
name="nsfw"
|
|
|
|
class="select select-ghost select-bordered w-full"
|
2024-05-13 15:27:36 +07:00
|
|
|
>
|
2024-05-29 13:22:02 +07:00
|
|
|
<option value="-1" selected?={ data.ImageListParams.NSFW < 0 }>*No Filter</option>
|
|
|
|
<option value="0" selected?={ data.ImageListParams.NSFW == 0 }>Hide</option>
|
|
|
|
<option value="1" selected?={ data.ImageListParams.NSFW == 1 }>Show Only</option>
|
2024-05-13 15:27:36 +07:00
|
|
|
</select>
|
2024-05-02 15:42:10 +07:00
|
|
|
}
|