Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions lib/Service/NotesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,37 @@ public function deleteCategory(string $userId, string $category) : array {
];
}

$parent = $folder->getParent();
$folder->delete();
if ($parent instanceof Folder) {
$this->noteUtil->deleteEmptyFolder($parent, $notesFolder);
foreach ($this->getAll($userId)['notes'] as $note) {
$noteCategory = $note->getCategory();
if ($noteCategory === $category || str_starts_with($noteCategory, $category . '/')) {
$note->setCategory('');
}
}

if ($notesFolder->nodeExists($category)) {
$parent = $folder->getParent();
$this->deleteFoldersWithoutFiles($folder);
if ($parent instanceof Folder) {
$this->noteUtil->deleteEmptyFolder($parent, $notesFolder);
}
}

return [
'category' => $category,
];
}

private function deleteFoldersWithoutFiles(Folder $folder) : void {
foreach ($folder->getDirectoryListing() as $node) {
if ($node instanceof Folder) {
$this->deleteFoldersWithoutFiles($node);
}
}
if (count($folder->getDirectoryListing()) === 0) {
$folder->delete();
}
}

public function getTitleFromContent(string $content) : string {
$content = $this->noteUtil->stripMarkdown($content);
return $this->noteUtil->getSafeTitle($content);
Expand Down
44 changes: 8 additions & 36 deletions src/components/CategoriesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ export default {
}
},

removeNotesFromCategory(categoryName) {
moveNotesToUncategorized(categoryName) {
for (const note of this.getNotesInCategory(categoryName)) {
store.commit('removeNote', note.id)
store.commit('setNoteAttribute', { noteId: note.id, attribute: 'category', value: '' })
}
},

Expand Down Expand Up @@ -293,10 +293,10 @@ export default {
let confirmed = false
const message = this.n(
'notes',
'Delete category "{category}" and its {count} note?',
'Delete category "{category}" and its {count} notes?',
'Delete category "{category}"? Its {count} note will be kept and moved to "{target}".',
'Delete category "{category}"? Its {count} notes will be kept and moved to "{target}".',
notes.length,
{ category: this.categoryTitle(categoryName), count: notes.length },
{ category: this.categoryTitle(categoryName), count: notes.length, target: this.categoryTitle('') },
)
try {
confirmed = await showConfirmation({
Expand All @@ -316,11 +316,9 @@ export default {

try {
await deleteCategoryRequest(categoryName)
const deletedCategory = categoryName
await this.closeOpenNoteBeforeDelete(deletedCategory)
this.removeNotesFromCategory(deletedCategory)
store.commit('removeLocalCategory', deletedCategory)
this.clearSelectedCategoryForDelete(deletedCategory)
this.moveNotesToUncategorized(categoryName)
store.commit('removeLocalCategory', categoryName)
this.clearSelectedCategoryForDelete(categoryName)
} catch {
// NotesService already shows a toast on failure.
}
Expand Down Expand Up @@ -423,32 +421,6 @@ export default {
store.commit('setSelectedCategory', category)
},

async closeOpenNoteBeforeDelete(categoryName) {
const noteId = Number.parseInt(this.$route?.params?.noteId, 10)
if (!Number.isFinite(noteId)) {
return
}
const note = store.getters.getNote(noteId)
if (!note) {
return
}
if (note.category === categoryName || note.category.startsWith(categoryName + '/')) {
const remainingNote = store.state.notes.notes.find(other => (
other.id !== noteId
&& other.category !== categoryName
&& !other.category.startsWith(categoryName + '/')
))
if (remainingNote) {
await this.$router.push({
name: 'note',
params: { noteId: remainingNote.id.toString() },
}).catch(() => {})
} else {
await this.$router.push({ name: 'welcome' }).catch(() => {})
}
}
},

onCategoryDragStart(event) {
event.preventDefault()
event.stopPropagation()
Expand Down