Library sidebar: folders, pinned-top, per-page menus, and an all-pages view
- Page.isFolder (migration 027): folders are content-less pages reusing parentId; folder delete reparents children one level up - Sidebar: Pages group becomes Library; Pinned at top; folder tree; page menu (duplicate/pin/copy link/rename/move/trash); folder menu - /pages index: filterable Library table (all/recent/pinned/untagged) with folder path + last edit (components/library-index.tsx) - Docs: API.md isFolder + folder-delete semantics
This commit is contained in:
@@ -54,12 +54,12 @@ func HandlePagesList(w http.ResponseWriter, r *http.Request) {
|
||||
respond(w, 200, v, e)
|
||||
}
|
||||
func pageData(b object) (object, error) {
|
||||
d := fields(b, "title content icon pinned parentId")
|
||||
d := fields(b, "title content icon pinned parentId isFolder")
|
||||
// parentId is nullable: an explicit null promotes the page to the root.
|
||||
if e := stringFields(d, "icon parentId", "title content"); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
if e := boolFields(d, "pinned"); e != nil {
|
||||
if e := boolFields(d, "pinned isFolder"); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
if e := limitText(d, "content", maxPageContentLen); e != nil {
|
||||
@@ -313,7 +313,24 @@ func HandlePagesDelete(w http.ResponseWriter, r *http.Request) {
|
||||
if e := lockUser(r, tx); e != nil {
|
||||
return e
|
||||
}
|
||||
return trashPage(r, tx, r.PathValue("id"))
|
||||
id := r.PathValue("id")
|
||||
// Library folders (027): deleting a folder reparents its children
|
||||
// (pages AND subfolders) to the folder's own parent, keeping the tree
|
||||
// intact one level up — the mockup's "folder removed, pages kept".
|
||||
// Plain pages keep the SET NULL promote-to-top behavior.
|
||||
row, e := owned(r, tx, "Page", id, "ownerId")
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
if isFolder, _ := row["isFolder"].(bool); isFolder {
|
||||
parent := row["parentId"] // nil for a top-level folder
|
||||
if _, e := tx.ExecContext(r.Context(),
|
||||
`UPDATE "Page" SET "parentId"=$1 WHERE "parentId"=$2 AND "ownerId"=$3`,
|
||||
parent, id, user(r)); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
return trashPage(r, tx, id)
|
||||
})
|
||||
respond(w, 200, OK{true}, e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user