From 513ff7c82f2b44133f54d055742fcde8659808a6 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Fri, 20 Mar 2026 11:41:48 -0400 Subject: [PATCH] feat: restore bookshelf page route and add navigation link - Add /bookshelf route in frontend.go (was typo /booskshelf) - Route fetches libraries server-side and renders complete HTML - Supports library_id query param or defaults to user's first library - Add "All Books" link to header navigation - Follows SSR-first architecture principles Fixes route registration that prevented bookshelf page from loading. --- internal/router/frontend.go | 51 +++++++++++++++++++++++++++++++++++++ templates/header.templ | 7 +++++ templates/header_templ.go | 4 +-- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/internal/router/frontend.go b/internal/router/frontend.go index 1e8c979..f5e5529 100644 --- a/internal/router/frontend.go +++ b/internal/router/frontend.go @@ -117,6 +117,57 @@ func registerFrontendRoutes(cfg *Config) { return "" } + frontendProtected.GET("/bookshelf", func(c *echo.Context) error { + user, err := getTemplateUserWithTheme(c, cfg) + if err != nil { + return renderErrorPage(c, "Error loading user", "user_load_error") + } + + var errorMsg string + + // Get library_id from query param or user's first library + libraryID := c.QueryParam("library_id") + if libraryID == "" { + userUUID, _ := uuid.Parse(user.ID) + libraries, err := cfg.Queries.GetUserVisibleLibraries(c.Request().Context(), uuidToPGType(userUUID)) + if err == nil && len(libraries) > 0 { + libUUID, _ := uuid.FromBytes(libraries[0].ID.Bytes[0:16]) + libraryID = libUUID.String() + } else { + errorMsg = "No libraries available" + } + } + + // Get libraries for dropdown + userUUID, _ := uuid.Parse(user.ID) + libraries, err := cfg.Queries.GetUserVisibleLibraries(c.Request().Context(), uuidToPGType(userUUID)) + if err != nil { + log.Printf("GetUserVisibleLibraries failed: %v", err) + libraries = []database.GetUserVisibleLibrariesRow{} + if errorMsg == "" { + errorMsg = "Error loading libraries" + } + } + + libData := make([]templates.LibraryData, len(libraries)) + for i, lib := range libraries { + libUUID, _ := uuid.FromBytes(lib.ID.Bytes[0:16]) + libData[i] = templates.LibraryData{ + ID: libUUID.String(), + Name: lib.Name, + Description: getText(lib.Description), + TypeName: lib.TypeName, + } + } + + var buf bytes.Buffer + err = templates.BookShelf(user, libData, libraryID, errorMsg).Render(c.Request().Context(), &buf) + if err != nil { + return err + } + return c.HTML(http.StatusOK, buf.String()) + }) + // Dashboard page frontendProtected.GET("/dashboard", func(c *echo.Context) error { user, err := getTemplateUserWithTheme(c, cfg) diff --git a/templates/header.templ b/templates/header.templ index e048862..c46da94 100644 --- a/templates/header.templ +++ b/templates/header.templ @@ -14,6 +14,13 @@ templ Header(user User, currentPath string) { Library + + All Books + Collections diff --git a/templates/header_templ.go b/templates/header_templ.go index b3b2278..f9d50cc 100644 --- a/templates/header_templ.go +++ b/templates/header_templ.go @@ -29,7 +29,7 @@ func Header(user User, currentPath string) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "