feat(collections): Add library-aware filtering to collection detail pages
- Add library_id parameter to BuildSections and getViewAllURL functions - Update dashboard handler to pass libraryID when building sections - Add library_id query param support to collection detail page handler - When library_id is provided, filter collection items by that library - When no library_id, show all books (backward compatible) - Reuses GetCollectionItemsForDashboard query for filtered results - Preserves context when navigating from dashboard to collection detail
This commit is contained in:
@@ -61,7 +61,7 @@ func (h *DashboardHandler) GetSections(c echo.Context) error {
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to load dashboard sections"})
|
||||
}
|
||||
|
||||
sectionData := BuildSections(sections)
|
||||
sectionData := BuildSections(sections, libraryID)
|
||||
|
||||
return c.JSON(http.StatusOK, map[string]interface{}{"sections": sectionData})
|
||||
}
|
||||
@@ -154,7 +154,7 @@ func (h *DashboardHandler) RestoreSystemCollection(c echo.Context) error {
|
||||
return c.JSON(http.StatusOK, map[string]string{"message": "System collection restored to defaults"})
|
||||
}
|
||||
|
||||
func BuildSections(sections []services.DashboardSection) []SectionData {
|
||||
func BuildSections(sections []services.DashboardSection, currentLibraryID string) []SectionData {
|
||||
var result []SectionData
|
||||
|
||||
for _, ds := range sections {
|
||||
@@ -177,7 +177,7 @@ func BuildSections(sections []services.DashboardSection) []SectionData {
|
||||
Description: ds.Description,
|
||||
Icon: ds.Icon,
|
||||
Items: bookCards,
|
||||
ViewAllURL: getViewAllURL(ds.CollectionID.String()),
|
||||
ViewAllURL: getViewAllURL(ds.CollectionID.String(), currentLibraryID),
|
||||
Priority: ds.Priority,
|
||||
})
|
||||
}
|
||||
@@ -185,8 +185,11 @@ func BuildSections(sections []services.DashboardSection) []SectionData {
|
||||
return result
|
||||
}
|
||||
|
||||
func getViewAllURL(collectionID string) string {
|
||||
func getViewAllURL(collectionID string, libraryID string) string {
|
||||
if collectionID != "" {
|
||||
if libraryID != "" {
|
||||
return "/collections/" + collectionID + "?library_id=" + libraryID
|
||||
}
|
||||
return "/collections/" + collectionID
|
||||
}
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user