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
This commit is contained in:
@@ -254,58 +254,6 @@ func registerFrontendRoutes(cfg *Config) {
|
|||||||
return c.HTML(http.StatusOK, buf.String())
|
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
|
// Collections page
|
||||||
frontendProtected.GET("/collections", func(c *echo.Context) error {
|
frontendProtected.GET("/collections", func(c *echo.Context) error {
|
||||||
user, err := getTemplateUserWithTheme(c, cfg)
|
user, err := getTemplateUserWithTheme(c, cfg)
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ templ BookShelf(user User, libraries []LibraryData, currentLibraryID string, err
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
<title>Library - Bookhoard</title>
|
<title>Library - Bookhoard</title>
|
||||||
<script src="/static/htmx.min.js"></script>
|
<script src="/static/htmx.min.js"></script>
|
||||||
<script src="/static/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
|
|
||||||
<link href="/static/style.css" rel="stylesheet"/>
|
<link href="/static/style.css" rel="stylesheet"/>
|
||||||
</head>
|
</head>
|
||||||
<body
|
<body
|
||||||
@@ -283,8 +282,6 @@ templ BookShelf(user User, libraries []LibraryData, currentLibraryID string, err
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- Load saved bookshelf script -->
|
|
||||||
<script src="/static/bookshelf.js" defer></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user