From 0c5831f9c03ad017656187d4c533f78a3f7e169e Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Fri, 27 Mar 2026 14:50:47 -0400 Subject: [PATCH] refactor(bookshelf): use BooksGrid component for DRY principle Replace inline book grid and pagination HTML with reusable BooksGrid component. This eliminates 43 lines of duplicate code and follows DRY principle. - Replace inline books grid (lines 322-364) with @BooksGrid() call - Pagination now rendered by BooksGrid component - Maintains same functionality with cleaner code - Generated bookshelf_templ.go updated by templ compiler --- templates/bookshelf.templ | 43 +------------------- templates/bookshelf_templ.go | 76 ++++++------------------------------ 2 files changed, 13 insertions(+), 106 deletions(-) diff --git a/templates/bookshelf.templ b/templates/bookshelf.templ index 5cad5e4..9d004cc 100644 --- a/templates/bookshelf.templ +++ b/templates/bookshelf.templ @@ -320,48 +320,7 @@ templ BookShelf( -
- if len(books) > 0 { - for _, book := range books { - @BookCard(book) - } - } else { - -
-

📚 No books found

-

Try adjusting your filters or add some books to your library.

-
- } -
- - + @BooksGrid(books, limit, offset, count, currentLibraryID) if errorMessage != "" {
diff --git a/templates/bookshelf_templ.go b/templates/bookshelf_templ.go index 98f9a20..5456b97 100644 --- a/templates/bookshelf_templ.go +++ b/templates/bookshelf_templ.go @@ -174,90 +174,38 @@ func BookShelf( return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - if len(books) > 0 { - for _, book := range books { - templ_7745c5c3_Err = BookCard(book).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } - } else { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "

📚 No books found

Try adjusting your filters or add some books to your library.

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "
") + templ_7745c5c3_Err = BooksGrid(books, limit, offset, count, currentLibraryID).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - if count > 0 { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, " Page ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if errorMessage != "" { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var8 string - templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(offset/limit + 1) + templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(errorMessage) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/bookshelf.templ`, Line: 351, Col: 32} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/bookshelf.templ`, Line: 327, Col: 58} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, " ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - if errorMessage != "" { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var9 string - templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(errorMessage) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/bookshelf.templ`, Line: 368, Col: 58} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "

Save Filter

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "

Save Filter

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }