fix: replace revealed sentinel with intersect once for infinite scroll
This commit is contained in:
@@ -20,19 +20,11 @@
|
||||
</div>
|
||||
{{else}}
|
||||
<div id="anime-grid" class="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6">
|
||||
{{range $i, $anime := .Animes}}
|
||||
{{$isThreshold := eq (add $i 1) (sub (len $.Animes) 8)}}
|
||||
{{if and $isThreshold $.HasNextPage}}
|
||||
<div hx-get="/browse?q={{$.Query}}&type={{$.Type}}&status={{$.Status}}&order_by={{$.OrderBy}}&sort={{$.Sort}}&sfw={{$.SFW}}&{{genresParams $.Genres}}&page={{$.NextPage}}"
|
||||
hx-trigger="revealed"
|
||||
hx-swap="afterend"
|
||||
hx-target="this"
|
||||
class="contents">
|
||||
{{template "anime_card" dict "Anime" . "WithActions" true "IsWatchlist" (index $.WatchlistMap .MalID)}}
|
||||
</div>
|
||||
{{else}}
|
||||
{{range .Animes}}
|
||||
{{template "anime_card" dict "Anime" . "WithActions" true "IsWatchlist" (index $.WatchlistMap .MalID)}}
|
||||
{{end}}
|
||||
{{if .HasNextPage}}
|
||||
{{template "browse_sentinel" .}}
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
@@ -41,19 +33,18 @@
|
||||
{{end}}
|
||||
|
||||
{{define "anime_card_scroll"}}
|
||||
{{$count := len .Animes}}
|
||||
{{range $i, $anime := .Animes}}
|
||||
{{$isThreshold := eq (add $i 1) (sub $count 8)}}
|
||||
{{if and $isThreshold $.HasNextPage}}
|
||||
<div hx-get="/browse?q={{$.Query}}&type={{$.Type}}&status={{$.Status}}&order_by={{$.OrderBy}}&sort={{$.Sort}}&sfw={{$.SFW}}&{{genresParams $.Genres}}&page={{$.NextPage}}"
|
||||
hx-trigger="revealed"
|
||||
hx-swap="afterend"
|
||||
{{range .Animes}}
|
||||
{{template "anime_card" dict "Anime" . "WithActions" true "IsWatchlist" (index $.WatchlistMap .MalID)}}
|
||||
{{end}}
|
||||
{{if .HasNextPage}}
|
||||
{{template "browse_sentinel" .}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
{{define "browse_sentinel"}}
|
||||
<div hx-get="/browse?q={{.Query}}&type={{.Type}}&status={{.Status}}&order_by={{.OrderBy}}&sort={{.Sort}}&sfw={{.SFW}}&{{genresParams .Genres}}&page={{.NextPage}}"
|
||||
hx-trigger="intersect once"
|
||||
hx-swap="outerHTML"
|
||||
hx-target="this"
|
||||
class="contents">
|
||||
{{template "anime_card" dict "Anime" $anime "WithActions" true "IsWatchlist" (index $.WatchlistMap $anime.MalID)}}
|
||||
</div>
|
||||
{{else}}
|
||||
{{template "anime_card" dict "Anime" $anime "WithActions" true "IsWatchlist" (index $.WatchlistMap $anime.MalID)}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
class="col-span-full h-px"></div>
|
||||
{{end}}
|
||||
|
||||
Reference in New Issue
Block a user