view(subreddits-details): update view to use new components

This commit is contained in:
Tigor Hutasuhut 2024-05-29 12:06:21 +07:00
parent d6e8cd96b0
commit 3ce9c2a327
4 changed files with 115 additions and 78 deletions

View file

@ -77,11 +77,11 @@ web-dependencies:
web-build: web-dependencies web-build: web-dependencies
mkdir -p public mkdir -p public
npx tailwindcss -i views/style.css -o public/style.css npx tailwindcss --minify -i views/style.css -o public/style.css
web-build-docker: web-build-docker:
mkdir -p public mkdir -p public
npx tailwindcss -i views/style.css -o public/style.css npx tailwindcss --minify -i views/style.css -o public/style.css
build: web-dependencies build-dependencies prepare build: web-dependencies build-dependencies prepare
go build -o redmage go build -o redmage

View file

@ -11,6 +11,7 @@ type Data struct {
Images models.ImageSlice Images models.ImageSlice
TotalImages int64 TotalImages int64
Params api.ImageListParams Params api.ImageListParams
FlashMessageSuccess string
} }
type splitBySubredditImages struct { type splitBySubredditImages struct {

View file

@ -2,6 +2,7 @@ package details
import "fmt" import "fmt"
import "github.com/tigorlazuardi/redmage/views" import "github.com/tigorlazuardi/redmage/views"
import "github.com/tigorlazuardi/redmage/api"
templ filter(c *views.Context, data Data) { templ filter(c *views.Context, data Data) {
<div <div
@ -9,38 +10,42 @@ templ filter(c *views.Context, data Data) {
hx-get={ fmt.Sprintf("/devices/details/%s", data.Device.Slug) } hx-get={ fmt.Sprintf("/devices/details/%s", data.Device.Slug) }
hx-include="this" hx-include="this"
hx-trigger="change, input delay:500ms" hx-trigger="change, input delay:500ms"
hx-target="main" hx-target="#image-content"
hx-select="main" hx-select="#image-content"
hx-swap="outerHTML" hx-swap="outerHTML"
hx-push-url="true" hx-push-url="true"
class="grid md:grid-cols-2 gap-4 items-center" class="grid grid-cols-[1fr,4fr] sm:grid-cols-[1fr,4fr,1fr,4fr] gap-4 items-center"
> >
<label class="input input-bordered flex items-center gap-2"> @searchInput(data.Params)
@limitInput(data.Params)
@rangeInput(c)
</div>
}
templ searchInput(params api.ImageListParams) {
<label for="search" class="label">Search</label>
<input <input
id="search" id="search"
type="text" type="text"
class="grow" class="input input-bordered w-full"
placeholder="Search" placeholder="Search"
name="q" name="q"
value={ data.Params.Q } value={ params.Q }
/> />
<svg }
onclick="htmx.trigger('#filter-bar', 'change')"
xmlns="http://www.w3.org/2000/svg" templ limitInput(params api.ImageListParams) {
viewBox="0 0 16 16" <label class="label" for="limit">Limit</label>
fill="currentColor"
class="w-4 h-4 opacity-70"
><path fill-rule="evenodd" d="M9.965 11.026a5 5 0 1 1 1.06-1.06l2.755 2.754a.75.75 0 1 1-1.06 1.06l-2.755-2.754ZM10.5 7a3.5 3.5 0 1 1-7 0 3.5 3.5 0 0 1 7 0Z" clip-rule="evenodd"></path></svg>
</label>
<div class="grid grid-cols-[1fr,3fr] sm:grid-cols-[1fr,3fr,1fr,3fr] gap-4 items-center">
<label for="limit">Limit</label>
<select id="limit" name="limit" class="select select-bordered w-full"> <select id="limit" name="limit" class="select select-bordered w-full">
<option value="25" selected?={ data.Params.Limit == 25 }>25</option> <option value="25" selected?={ params.Limit == 25 }>25</option>
<option value="50" selected?={ data.Params.Limit == 50 }>50</option> <option value="50" selected?={ params.Limit == 50 }>50</option>
<option value="75" selected?={ data.Params.Limit == 75 }>75</option> <option value="75" selected?={ params.Limit == 75 }>75</option>
<option value="100" selected?={ data.Params.Limit == 100 }>100</option> <option value="100" selected?={ params.Limit == 100 }>100</option>
</select> </select>
<label for="range">Range</label> }
templ rangeInput(c *views.Context) {
<label class="label" for="range">Range</label>
<select id="range" name="created_at" class="select select-bordered w-full"> <select id="range" name="created_at" class="select select-bordered w-full">
@rangeOption(c, "", "*No Filter") @rangeOption(c, "", "*No Filter")
@rangeOption(c, "-10800", "3 Hours") @rangeOption(c, "-10800", "3 Hours")
@ -52,8 +57,6 @@ templ filter(c *views.Context, data Data) {
@rangeOption(c, "-604800", "7 Days") @rangeOption(c, "-604800", "7 Days")
@rangeOption(c, "-2592000", "30 Days") @rangeOption(c, "-2592000", "30 Days")
</select> </select>
</div>
</div>
} }
templ rangeOption(c *views.Context, value, display string) { templ rangeOption(c *views.Context, value, display string) {

View file

@ -16,6 +16,11 @@ templ View(c *views.Context, data Data) {
} }
@components.Body(c) { @components.Body(c) {
@Content(c, data) @Content(c, data)
@components.NotificationContainer() {
if data.FlashMessageSuccess != "" {
@components.SuccessNotification(data.FlashMessageSuccess)
}
}
} }
} }
} }
@ -28,18 +33,12 @@ templ Content(c *views.Context, data Data) {
} else { } else {
<div class="flex justify-between items-center"> <div class="flex justify-between items-center">
<h1 class="my-auto">{ data.Device.Name }</h1> <h1 class="my-auto">{ data.Device.Name }</h1>
<div class="tooltip" data-tip="Edit"> @actionButton(data)
<a
href={ templ.SafeURL(fmt.Sprintf("/devices/edit/%s", data.Device.Slug)) }
class="btn btn-primary no-underline"
>
@icons.Gear("w-8 h-8 text-primary-content")
</a>
</div>
</div> </div>
<div class="divider"></div> <div class="divider"></div>
@filter(c, data) @filter(c, data)
<h2>{ strconv.FormatInt(data.TotalImages, 10) } Images</h2> <div id="image-content">
<h2 class="my-4">{ strconv.FormatInt(data.TotalImages, 10) } Images</h2>
if data.TotalImages > 0 { if data.TotalImages > 0 {
<div class="flex justify-center mt-4"> <div class="flex justify-center mt-4">
@components.Pagination(c, components.PaginationData{ @components.Pagination(c, components.PaginationData{
@ -57,7 +56,7 @@ templ Content(c *views.Context, data Data) {
</p> </p>
} }
for _, group := range data.splitImages() { for _, group := range data.splitImages() {
<h2>{ group.Subreddit }</h2> <h2 class="my-4">{ group.Subreddit }</h2>
@imageList(group.Images) @imageList(group.Images)
} }
<div class="flex justify-center mt-4"> <div class="flex justify-center mt-4">
@ -68,15 +67,49 @@ templ Content(c *views.Context, data Data) {
Total: data.TotalImages, Total: data.TotalImages,
}) })
</div> </div>
</div>
} }
} }
</main> </main>
} }
templ actionButton(data Data) {
<div class="max-xs:toast max-xs:z-40">
<div class="dropdown dropdown-hover dropdown-top xs:dropdown-bottom dropdown-end">
<div
tabindex="0"
role="button"
class="btn btn-primary max-xs:btn-circle max-lg:btn-square xs:btn-outline m-1 max-xs:border-none"
>
@icons.Kebab("h-8 w-8")
</div>
<ul
tabindex="0"
class="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52 m-0 border-primary border-2"
onclick="document.activeElement.blur()"
>
<li class="m-0 p-0 hover:bg-primary rounded-btn">
<a
href={ templ.SafeURL(fmt.Sprintf("/devices/edit/%s", data.Device.Slug)) }
class="btn btn-ghost btn-sm no-underline m-0"
>Edit</a>
</li>
<div class="xs:hidden divider m-0 p-0"></div>
<li class="xs:hidden m-0 p-0 hover:bg-primary rounded-btn">
<button
class="btn btn-ghost btn-sm m-0"
onclick="window.scrollTo({ top: 0, behavior: 'smooth' })"
>Scroll to Top</button>
</li>
</ul>
</div>
</div>
}
templ imageList(images models.ImageSlice) { templ imageList(images models.ImageSlice) {
<div class="overflow-x-auto flex gap-4 p-6 shadow-inner bg-base-300 rounded-2xl w-[85vw] md:w-full scrollbar-track-base-100 scrollbar-thumb-primary scrollbar-thin hover:scrollbar-thumb-base-300"> @components.HorizontalImageWell() {
for _, data := range images { for _, data := range images {
@components.ImageCard(data, 0) @components.ImageCard(data, 0)
} }
</div> }
} }