feat(workspace): deleted folders go to the trash as a whole, after a confirmation
A deleted personal folder is kept in trashed_folders with its subfolders; its notes are trashed and tied to it. The trash lists the folder as one entry with its note count; restoring brings back the folder tree (empty subfolders too) and all notes, deleting for good, emptying the trash and the notes trash delay remove it with its notes. Folders in shared folders keep the old way. Deleting a folder now asks first, in a small popover at the click (ConfirmPopover, documented in ui-patterns). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9dcfa6c27e
commit
b26b07cfea
18 files changed
+564
-25
No files matched your search
@@ -63,6 +63,38 @@ func (s *Server) handleDeleteFolder(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
// handleRestoreFolder brings a folder from the trash back with its subfolders and notes.
|
||||
func (s *Server) handleRestoreFolder(w http.ResponseWriter, r *http.Request) {
|
||||
userID := auth.GetUserID(r.Context())
|
||||
docIDs, err := s.store.RestoreFolder(userID, chi.URLParam(r, "id"))
|
||||
if err != nil {
|
||||
writeTrashError(w, err)
|
||||
return
|
||||
}
|
||||
// Everyone with access to one of the notes reloads their tree
|
||||
users := map[string]bool{userID: true}
|
||||
for _, docID := range docIDs {
|
||||
authorized, _ := s.store.GetAuthorizedDocUsers(docID)
|
||||
for _, uid := range authorized {
|
||||
users[uid] = true
|
||||
}
|
||||
}
|
||||
for uid := range users {
|
||||
s.wsHub.BroadcastToUser(uid, "WORKSPACE_FOLDERS_UPDATED", map[string]string{"restored": "folder"})
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]interface{}{"restored": true, "restoredDocIds": docIDs})
|
||||
}
|
||||
|
||||
// handlePurgeFolder deletes a folder in the trash with its notes for good.
|
||||
func (s *Server) handlePurgeFolder(w http.ResponseWriter, r *http.Request) {
|
||||
docIDs, err := s.store.PurgeFolder(auth.GetUserID(r.Context()), chi.URLParam(r, "id"))
|
||||
if err != nil {
|
||||
writeTrashError(w, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]interface{}{"deleted": true, "deletedDocIds": docIDs})
|
||||
}
|
||||
|
||||
func (s *Server) handleMoveFolder(w http.ResponseWriter, r *http.Request) {
|
||||
userID := auth.GetUserID(r.Context())
|
||||
var req struct {
|
||||
|
||||
@@ -238,6 +238,8 @@ func (s *Server) Router() http.Handler {
|
||||
r.Post("/api/v1/folders", s.handleCreateFolder)
|
||||
r.Post("/api/v1/folders/move", s.handleMoveFolder)
|
||||
r.Delete("/api/v1/folders", s.handleDeleteFolder)
|
||||
r.Post("/api/v1/folders/trash/{id}/restore", s.handleRestoreFolder)
|
||||
r.Delete("/api/v1/folders/trash/{id}", s.handlePurgeFolder)
|
||||
|
||||
r.Get("/api/v1/workspace/folders/shared", s.handleGetSharedFolders)
|
||||
r.Post("/api/v1/workspace/folders/shared", s.handleCreateSharedFolder)
|
||||
|
||||
Reference in new issue
Block a user