Wrap list chips, add list sharing and public/unlisted/private visibility
- Home page list chips wrap to new rows instead of scrolling off the edge - Lists are public, unlisted or private (migrated from the visible flag) - Unlisted lists are reachable only at /s/<token>; slug URLs are public-only - Share button on list pages and in the editor/dashboard; owners can reset an unlisted link Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
268af7b9ed
commit
87e3d1fb30
16 files changed
+292
-28
No files matched your search
@@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strconv"
|
||||
|
||||
"github.com/cdnutter/canon/internal/store"
|
||||
@@ -153,10 +154,22 @@ type listPage struct {
|
||||
PageNums []int
|
||||
}
|
||||
|
||||
// visibleList loads the list named in the URL, treating hidden lists as
|
||||
// missing for visitors. It writes the error response when ok is false.
|
||||
// visibleList loads the list named in the URL. Only public lists are
|
||||
// reachable by slug; unlisted ones go through their share link, and the
|
||||
// owner sees everything. It writes the error response when ok is false.
|
||||
func (s *Server) visibleList(w http.ResponseWriter, r *http.Request) (l store.List, ok bool) {
|
||||
l, err := s.store.ListBySlug(r.Context(), r.PathValue("slug"))
|
||||
return s.allowList(w, r, l, err, store.VisibilityPublic)
|
||||
}
|
||||
|
||||
// sharedList loads the list behind a share link, which works for public
|
||||
// and unlisted lists.
|
||||
func (s *Server) sharedList(w http.ResponseWriter, r *http.Request) (l store.List, ok bool) {
|
||||
l, err := s.store.ListByShareToken(r.Context(), r.PathValue("token"))
|
||||
return s.allowList(w, r, l, err, store.VisibilityPublic, store.VisibilityUnlisted)
|
||||
}
|
||||
|
||||
func (s *Server) allowList(w http.ResponseWriter, r *http.Request, l store.List, err error, allowed ...string) (store.List, bool) {
|
||||
if errors.Is(err, store.ErrNotFound) {
|
||||
s.notFound(w, r)
|
||||
return l, false
|
||||
@@ -165,7 +178,7 @@ func (s *Server) visibleList(w http.ResponseWriter, r *http.Request) (l store.Li
|
||||
s.serverError(w, r, err)
|
||||
return l, false
|
||||
}
|
||||
if !l.Visible {
|
||||
if !slices.Contains(allowed, l.Visibility) {
|
||||
if _, loggedIn := s.currentUser(r); !loggedIn {
|
||||
s.notFound(w, r)
|
||||
return l, false
|
||||
@@ -175,11 +188,19 @@ func (s *Server) visibleList(w http.ResponseWriter, r *http.Request) (l store.Li
|
||||
}
|
||||
|
||||
func (s *Server) handleList(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
l, ok := s.visibleList(w, r)
|
||||
if !ok {
|
||||
return
|
||||
if l, ok := s.visibleList(w, r); ok {
|
||||
s.renderList(w, r, l)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) handleSharedList(w http.ResponseWriter, r *http.Request) {
|
||||
if l, ok := s.sharedList(w, r); ok {
|
||||
s.renderList(w, r, l)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) renderList(w http.ResponseWriter, r *http.Request, l store.List) {
|
||||
ctx := r.Context()
|
||||
site := s.site(ctx)
|
||||
p := listPage{List: l, Page: 1}
|
||||
p.Category = listCategory(l)
|
||||
|
||||
Reference in new issue
Block a user