Add pagination to feed with Load more button using HTMX

This commit is contained in:
2026-07-06 11:51:46 +02:00
parent 969fc673bc
commit bef4f7ba1d
5 changed files with 62 additions and 38 deletions
@@ -1,6 +1,7 @@
package com.discdrop.service;
import com.discdrop.db.DatabaseService;
import com.discdrop.db.DatabaseService.FeedResult;
import com.discdrop.db.Record.ReleaseGroup;
import com.discdrop.db.Record.TrackedArtist;
import jakarta.enterprise.context.ApplicationScoped;
@@ -23,9 +24,15 @@ public class FeedService {
@Inject
DatabaseService db;
public static final int PAGE_SIZE = 20;
public List<ReleaseGroup> getFeedEntries() {
return getFeedEntries(1).entries();
}
public FeedResult getFeedEntries(int page) {
var artists = artistService.findAll();
if (artists.isEmpty()) return List.of();
if (artists.isEmpty()) return new FeedResult(List.of(), false);
var artistMbids = new ArrayList<String>();
for (var a : artists) {
@@ -42,7 +49,7 @@ public class FeedService {
monitoredTypes.addAll(getMonitoredTypes(a));
}
return db.getFeed(artistMbids, monitoredTypes.isEmpty() ? allTypes : monitoredTypes);
return db.getFeed(artistMbids, monitoredTypes.isEmpty() ? allTypes : monitoredTypes, PAGE_SIZE, (page - 1) * PAGE_SIZE);
}
private List<String> getMonitoredTypes(TrackedArtist a) {