wip: trying to update filter on recently added section

This commit is contained in:
Tigor Hutasuhut 2024-05-29 13:22:02 +07:00
parent 1287c511df
commit 66e397d745
2 changed files with 30 additions and 13 deletions

View file

@ -17,7 +17,7 @@ import (
type ImageListParams struct { type ImageListParams struct {
Q string Q string
SFW bool NSFW int32
OrderBy string OrderBy string
Sort string Sort string
Offset int64 Offset int64
@ -29,14 +29,15 @@ type ImageListParams struct {
func (ilp *ImageListParams) FillFromQuery(query Queryable) { func (ilp *ImageListParams) FillFromQuery(query Queryable) {
ilp.Q = query.Get("q") ilp.Q = query.Get("q")
ilp.SFW, _ = strconv.ParseBool(query.Get("sfw")) if nsfw, err := strconv.Atoi(query.Get("nsfw")); err == nil {
ilp.NSFW = int32(nsfw)
} else {
ilp.NSFW = -1
}
ilp.OrderBy = query.Get("order_by") ilp.OrderBy = query.Get("order_by")
ilp.Sort = strings.ToLower(query.Get("sort")) ilp.Sort = strings.ToLower(query.Get("sort"))
ilp.Offset, _ = strconv.ParseInt(query.Get("offset"), 10, 64) ilp.Offset, _ = strconv.ParseInt(query.Get("offset"), 10, 64)
ilp.Limit, _ = strconv.ParseInt(query.Get("limit"), 10, 64) ilp.Limit, _ = strconv.ParseInt(query.Get("limit"), 10, 64)
if ilp.Limit > 100 {
ilp.Limit = 100
}
if ilp.Limit < 1 { if ilp.Limit < 1 {
ilp.Limit = 25 ilp.Limit = 25
} }
@ -64,8 +65,8 @@ func (ilp ImageListParams) CountQuery() (expr []bob.Mod[*dialect.SelectQuery]) {
) )
} }
if ilp.SFW { if ilp.NSFW >= 0 {
expr = append(expr, models.SelectWhere.Images.NSFW.EQ(0)) expr = append(expr, models.SelectWhere.Images.NSFW.EQ(ilp.NSFW))
} }
if len(ilp.Device) > 0 { if len(ilp.Device) > 0 {

View file

@ -5,6 +5,7 @@ import "github.com/tigorlazuardi/redmage/views"
import "github.com/tigorlazuardi/redmage/views/utils" import "github.com/tigorlazuardi/redmage/views/utils"
import "strconv" import "strconv"
import "fmt" import "fmt"
import "github.com/tigorlazuardi/redmage/api"
templ Home(c *views.Context, data Data) { templ Home(c *views.Context, data Data) {
@components.Doctype() { @components.Doctype() {
@ -83,16 +84,30 @@ templ filterBar(c *views.Context, data Data) {
class="grid grid-cols-[1fr,4fr] sm:grid-cols-[1fr,4fr,1fr,4fr] items-center gap-4" class="grid grid-cols-[1fr,4fr] sm:grid-cols-[1fr,4fr,1fr,4fr] items-center gap-4"
> >
@nsfwToggle(data) @nsfwToggle(data)
@limitInput(data.ImageListParams)
@recentRangeInput(c.Query.Get("created_at")) @recentRangeInput(c.Query.Get("created_at"))
</div> </div>
} }
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>
}
templ recentRangeInput(current string) { templ recentRangeInput(current string) {
<label for="range" class="label">Range</label> <label for="range" class="label">Range</label>
<select <select
id="range" id="range"
name="created_at" name="created_at"
class="select select-ghost select-bordered" class="select select-ghost select-bordered w-full"
> >
@rangeOption("-10800", "3 Hours", current == "-10800") @rangeOption("-10800", "3 Hours", current == "-10800")
@rangeOption("-21600", "6 Hours", current == "-21600") @rangeOption("-21600", "6 Hours", current == "-21600")
@ -101,7 +116,7 @@ templ recentRangeInput(current string) {
@rangeOption("-172800", "2 Days", current == "-172800") @rangeOption("-172800", "2 Days", current == "-172800")
@rangeOption("-259200", "3 Days", current == "-259200") @rangeOption("-259200", "3 Days", current == "-259200")
@rangeOption("-604800", "7 Days", current == "-604800") @rangeOption("-604800", "7 Days", current == "-604800")
@rangeOption("-2592000", "7 Days", current == "-2592000") @rangeOption("-2592000", "30 Days", current == "-2592000")
</select> </select>
} }
@ -113,10 +128,11 @@ templ nsfwToggle(data Data) {
<label for="nsfw" class="label">NSFW</label> <label for="nsfw" class="label">NSFW</label>
<select <select
id="nsfw" id="nsfw"
name="sfw" name="nsfw"
class="select select-ghost select-bordered" class="select select-ghost select-bordered w-full"
> >
<option value="0">Show</option> <option value="-1" selected?={ data.ImageListParams.NSFW < 0 }>*No Filter</option>
<option selected?={ data.ImageListParams.SFW } value="1">Hide</option> <option value="0" selected?={ data.ImageListParams.NSFW == 0 }>Hide</option>
<option value="1" selected?={ data.ImageListParams.NSFW == 1 }>Show Only</option>
</select> </select>
} }