From 34be9ab16eaa1bd8cf72c5e3798e3a7a0ae2c2ee Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Fri, 20 Mar 2026 22:58:05 -0400 Subject: [PATCH] fix: remove duplicate bookshelf route and fix template script tags Remove duplicate /bookshelf route registration that was causing server panic. The route was registered twice in frontend.go (lines 257-307 removed). Fix bookshelf.templ script tags: - Remove malformed Alpine.js CDN path (/static/alpinejs@3.x.x/dist/cdn.min.js) - Remove standalone bookshelf.js script tag (not built separately) - Rely on header.templ to load main.js which includes all Alpine components This fixes the bookshelf page 404 errors and JavaScript errors: - bookshelf is not defined - initBookshelf is not defined - Loading failed for bookshelf.js The bookshelf page now uses the standard pattern like dashboard and collections: - Header provides main.js with all Alpine components - Bookshelf Alpine component registered via x-data="bookshelf" - All functionality works correctly --- internal/router/frontend.go | 52 ------------------------------------- templates/bookshelf.templ | 3 --- 2 files changed, 55 deletions(-) diff --git a/internal/router/frontend.go b/internal/router/frontend.go index f5e5529..e2f1046 100644 --- a/internal/router/frontend.go +++ b/internal/router/frontend.go @@ -254,58 +254,6 @@ func registerFrontendRoutes(cfg *Config) { return c.HTML(http.StatusOK, buf.String()) }) - // Bookshelf Page - 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()) - }) - // Collections page frontendProtected.GET("/collections", func(c *echo.Context) error { user, err := getTemplateUserWithTheme(c, cfg) diff --git a/templates/bookshelf.templ b/templates/bookshelf.templ index 7188352..2594c77 100644 --- a/templates/bookshelf.templ +++ b/templates/bookshelf.templ @@ -8,7 +8,6 @@ templ BookShelf(user User, libraries []LibraryData, currentLibraryID string, err Library - Bookhoard - - - }