diff --git a/api/subreddits_get_by_name.go b/api/subreddits_get_by_name.go index 10d67ad..26e1123 100644 --- a/api/subreddits_get_by_name.go +++ b/api/subreddits_get_by_name.go @@ -112,10 +112,11 @@ func (sgb *SubredditGetByNameImageParams) CountQuery() (expr []bob.Mod[*dialect. expr = append(expr, sm.Where( models.ImageColumns.PostTitle.Like(arg). - Or(models.ImageColumns.PostURL.Like(arg). - Or(models.ImageColumns.ImageRelativePath.Like(arg)), - ), - )) + Or(models.ImageColumns.PostURL.Like(arg)). + Or(models.ImageColumns.ImageRelativePath.Like(arg)). + Or(models.ImageColumns.PostAuthor.Like(arg)), + ), + ) } if !sgb.After.IsZero() { diff --git a/views/components/body.templ b/views/components/body.templ index 3a4df3e..b73fcb3 100644 --- a/views/components/body.templ +++ b/views/components/body.templ @@ -3,7 +3,7 @@ package components import "github.com/tigorlazuardi/redmage/views" templ Body(c *views.Context) { - + @Navigation(c) {
@Navbar(c) diff --git a/views/subredditsview/detailsview/detailsview.templ b/views/subredditsview/detailsview/detailsview.templ index afae935..3ad05e8 100644 --- a/views/subredditsview/detailsview/detailsview.templ +++ b/views/subredditsview/detailsview/detailsview.templ @@ -36,31 +36,103 @@ templ DetailsContent(c *views.Context, data Data) { { strconv.FormatInt(data.TotalImages, 10) }
- @paginationButtons(c, data) -
+
+ @FilterBar(c, data) + @showingImageFromTo(data) + @paginationButtons(c, data) +
+
for _, image := range data.Images { @components.ImageCard(image, 0) }
+ @paginationButtons(c, data) } } } -templ paginationButtons(_ *views.Context, data Data) { -
- for i, count := 1, int64(0); count < data.TotalImages; i, count = i+1, count+data.Params.Limit { - if data.Params.Offset <= count && data.Params.Offset > count-data.Params.Limit { - { strconv.Itoa(i) } - } else { - { strconv.Itoa(i) } - } - } +templ FilterBar(c *views.Context, data Data) { +
+ +
} -func buildPaginationURL(subreddit string, params api.SubredditGetByNameImageParams, extraQueries ...string) templ.SafeURL { +templ paginationButtons(_ *views.Context, data Data) { + if data.TotalImages > data.Params.Limit { +
+ for i, count := 1, int64(0); count < data.TotalImages; i, count = i+1, count+data.Params.Limit { + if data.Params.Offset <= count && data.Params.Offset > count-data.Params.Limit { + { strconv.Itoa(i) } + } else { + { strconv.Itoa(i) } + } + } +
+ } +} + +func buildURL(subreddit string, params api.SubredditGetByNameImageParams, extraQueries ...string) templ.SafeURL { queries := params.IntoQueryWith(extraQueries...) return templ.SafeURL(fmt.Sprintf("/subreddits/details/%s?%s", subreddit, queries.Encode())) } + +templ limitOption(params api.SubredditGetByNameImageParams, value int) { + if int(params.Limit) == value { + + } else { + + } +} + +templ showingImageFromTo(data Data) { + if data.TotalImages > 1 { + { showingFromToImages(data) } + } +} + +func showingFromToImages(data Data) string { + params := data.Params + start := params.Offset + 1 + end := params.Limit + params.Offset + if end > data.TotalImages { + end = data.TotalImages + } + return fmt.Sprintf("Showing from %d to %d", start, end) +}