Discover books, shows, and movies at your level. Track your progress by filling your Shelf with what you find, and share with other language learners. *No dusting required. shlf.space
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(internal): rename my-books to shelf

This change makes each users shelf discoverable instead of being
personal

Signed-off-by: brookjeynes <me@brookjeynes.dev>

authored by

brookjeynes and committed by tangled.org 6962fa1f c26a2ac4

+53 -30
+1 -1
internal/server/middleware/middleware.go
··· 48 48 if err != nil { 49 49 slog.Error("failed to resolve did/handle", "err", err) 50 50 w.WriteHeader(http.StatusNotFound) 51 - notfound.NotFoundPage(notfound.NotFoundParams{}).Render(r.Context(), w) 51 + notfound.NotFoundPage(notfound.NotFoundPageParams{}).Render(r.Context(), w) 52 52 return 53 53 } 54 54
-15
internal/server/my-books.go
··· 1 - package server 2 - 3 - import ( 4 - "net/http" 5 - 6 - mybooks "shlf.space/internal/views/my-books" 7 - ) 8 - 9 - func (s *Server) MyBooks(w http.ResponseWriter, r *http.Request) { 10 - user := s.oauth.GetAccountUser(r) 11 - 12 - mybooks.MyBooksPage(mybooks.MyBooksParams{ 13 - User: user, 14 - }).Render(r.Context(), w) 15 - }
+2 -2
internal/server/router.go
··· 72 72 router := chi.NewRouter() 73 73 74 74 router.With(middleware.ResolveIdent()).Route("/{user}", func(r chi.Router) { 75 - r.Get("/books", s.MyBooks) 75 + r.Get("/shelf", s.Shelf) 76 76 }) 77 77 78 78 router.NotFound(func(w http.ResponseWriter, r *http.Request) { 79 79 w.WriteHeader(http.StatusNotFound) 80 - notfound.NotFoundPage(notfound.NotFoundParams{}).Render(r.Context(), w) 80 + notfound.NotFoundPage(notfound.NotFoundPageParams{}).Render(r.Context(), w) 81 81 }) 82 82 83 83 return router
+13
internal/server/server.go
··· 40 40 func (s *Server) Close() error { 41 41 return nil 42 42 } 43 + 44 + func (s *Server) resolveDidToHandle(did string) string { 45 + identity, err := s.idResolver.ResolveIdent(context.Background(), did) 46 + if err != nil { 47 + return did 48 + } 49 + 50 + if identity.Handle.IsInvalidHandle() { 51 + return "handle.invalid" 52 + } 53 + 54 + return identity.Handle.String() 55 + }
+24
internal/server/shelf.go
··· 1 + package server 2 + 3 + import ( 4 + "net/http" 5 + 6 + "github.com/go-chi/chi/v5" 7 + "shlf.space/internal/views/shelf" 8 + ) 9 + 10 + func (s *Server) Shelf(w http.ResponseWriter, r *http.Request) { 11 + user := s.oauth.GetAccountUser(r) 12 + 13 + didOrHandle := chi.URLParam(r, "user") 14 + if didOrHandle == "" { 15 + http.Error(w, "Bad request", http.StatusBadRequest) 16 + return 17 + } 18 + handle := s.resolveDidToHandle(didOrHandle) 19 + 20 + shelf.ShelfPage(shelf.ShelfPageParams{ 21 + User: user, 22 + ProfileHandle: handle, 23 + }).Render(r.Context(), w) 24 + }
-7
internal/views/my-books/my-books.go
··· 1 - package mybooks 2 - 3 - import "shlf.space/internal/server/oauth" 4 - 5 - type MyBooksParams struct { 6 - User *oauth.AccountUser 7 - }
+3 -3
internal/views/my-books/my-books.templ internal/views/shelf/shelf.templ
··· 1 - package mybooks 1 + package shelf 2 2 3 3 import ( 4 4 "fmt" ··· 7 7 "shlf.space/internal/layouts/base" 8 8 ) 9 9 10 - templ MyBooksPage(params MyBooksParams) { 10 + templ ShelfPage(params ShelfPageParams) { 11 11 <style> 12 12 .add-book { 13 13 writing-mode: vertical-rl; 14 14 text-orientation: upright; 15 15 } 16 16 </style> 17 - @layouts.Base(layouts.BaseParams{Title: fmt.Sprintf("%s's books", params.User.Account.Handle)}) { 17 + @layouts.Base(layouts.BaseParams{Title: fmt.Sprintf("%s's books", params.ProfileHandle)}) { 18 18 @header.Header(header.HeaderParams{User: params.User}) 19 19 <div class="container"> 20 20 <div id="book-row-1" class="flex items-end">
+1 -1
internal/views/not-found/not-found.go
··· 1 1 package notfound 2 2 3 - type NotFoundParams struct{} 3 + type NotFoundPageParams struct{}
+1 -1
internal/views/not-found/not-found.templ
··· 2 2 3 3 import "shlf.space/internal/layouts/base" 4 4 5 - templ NotFoundPage(params NotFoundParams) { 5 + templ NotFoundPage(params NotFoundPageParams) { 6 6 @layouts.Base(layouts.BaseParams{Title: "not found"}) { 7 7 <div class="container">not found...</div> 8 8 }
+8
internal/views/shelf/shelf.go
··· 1 + package shelf 2 + 3 + import "shlf.space/internal/server/oauth" 4 + 5 + type ShelfPageParams struct { 6 + User *oauth.AccountUser 7 + ProfileHandle string 8 + }