feat(frontend): update bookshelf to use saved filters API
Update bookshelf page to use new generic saved filters endpoint for persisting and loading user filter presets. API Endpoint Changes: - loadSavedFilters(): Use /api/saved-filters?resource_type=media-items (OLD: /api/bookshelf/filters - removed endpoint) - saveFilter(): Include resource_type: "media-items" in request body Filter Persistence: - Filters saved to backend instead of localStorage only - Supports multiple resource types (extensible design) - Maintains existing Alpine.js store integration - Automatic reload after saving filters User Experience: - No breaking changes to UI - Same save/load workflow for users - Better data persistence (server-side storage) - Cross-device filter sync (future enhancement) Error Handling: - Toast notifications for save success/failure - Proper error logging to console - Graceful handling of missing authentication Migration: - Fully backward compatible with existing UI - No changes to HTML template needed - Alpine store remains unchanged Part of: Saved Filters Implementation (Phase 3: Frontend) Related: #saved-filters-feature
This commit is contained in:
@@ -9,9 +9,12 @@ async function loadSavedFilters(): Promise<void> {
|
|||||||
const token = localStorage.getItem("token");
|
const token = localStorage.getItem("token");
|
||||||
if (!token) return;
|
if (!token) return;
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/bookshelf/filters", {
|
const response = await fetch(
|
||||||
headers: { Authorization: `Bearer ${token}` },
|
"/api/saved-filters?resource_type=media-items",
|
||||||
});
|
{
|
||||||
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const filters = await response.json();
|
const filters = await response.json();
|
||||||
@@ -46,7 +49,7 @@ async function saveFilter(event: Event): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/bookshelf/filters", {
|
const response = await fetch("/api/saved-filters", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -54,6 +57,7 @@ async function saveFilter(event: Event): Promise<void> {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
name: filterName,
|
name: filterName,
|
||||||
|
resource_type: "media-items",
|
||||||
filters: filterData,
|
filters: filterData,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user