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-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-09 21:49:23 +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) {
|
|
|
|
<main id="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 21:45:18 +07:00
|
|
|
<div class="flex content-center gap-8">
|
|
|
|
<h1>
|
|
|
|
Recently Added -
|
|
|
|
{ strconv.FormatInt(data.TotalImages, 10) } Images
|
|
|
|
</h1>
|
|
|
|
<select
|
|
|
|
hx-trigger="change"
|
|
|
|
hx-get="/"
|
|
|
|
name="created_at"
|
|
|
|
hx-params="*"
|
|
|
|
class="select select-ghost"
|
|
|
|
hx-target="body"
|
|
|
|
hx-push-url="true"
|
|
|
|
>
|
|
|
|
@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>
|
|
|
|
</div>
|
2024-04-29 15:18:23 +07:00
|
|
|
for _, recently := range data.RecentlyAddedImages {
|
2024-04-29 21:45:18 +07:00
|
|
|
<div class="divider"></div>
|
|
|
|
<h2 class="mt-4">{ recently.Device.Name }</h2>
|
2024-04-29 15:18:23 +07:00
|
|
|
for _, subreddit := range recently.Subreddits {
|
2024-04-29 21:45:18 +07:00
|
|
|
<h4>{ subreddit.Subreddit.Name } - { strconv.Itoa(len(subreddit.Images)) } images</h4>
|
2024-04-29 15:18:23 +07:00
|
|
|
@RecentlyAddedImageList(subreddit.Images, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</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
|
|
|
|
|
|
|
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>
|
|
|
|
}
|
|
|
|
}
|