Skip to content

Commit 9607704

Browse files
committed
fix: Implement note category selector using NcActionInput
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent 3dd7abb commit 9607704

File tree

2 files changed

+62
-12
lines changed

2 files changed

+62
-12
lines changed

src/components/NoteItem.vue

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
:title="title"
44
:active="isSelected"
55
:to="{ name: 'note', params: { noteId: note.id.toString() } }"
6+
@update:menuOpen="onMenuChange"
67
@click="onNoteSelected(note.id)"
78
>
89
<template #subtitle>
@@ -30,6 +31,31 @@
3031
{{ actionFavoriteText }}
3132
</NcActionButton>
3233

34+
<NcActionButton v-if="!showCategorySelect" @click="showCategorySelect = true">
35+
<template #icon>
36+
<FolderIcon :size="20" />
37+
</template>
38+
{{ categoryTitle }}
39+
</NcActionButton>
40+
<NcActionInput
41+
v-else
42+
:value="note.category"
43+
type="multiselect"
44+
label="label"
45+
track-by="id"
46+
:multiple="false"
47+
:options="categories"
48+
:disabled="loading.category"
49+
:taggable="true"
50+
@input="onCategoryChange"
51+
@search-change="onCategoryChange"
52+
>
53+
<template #icon>
54+
<FolderIcon :size="20" />
55+
</template>
56+
{{ t('notes', 'Change category') }}
57+
</NcActionInput>
58+
3359
<NcActionButton v-if="!renaming" @click="startRenaming">
3460
<PencilIcon slot="icon" :size="20" />
3561
{{ t('notes', 'Rename') }}
@@ -45,14 +71,10 @@
4571
<PencilIcon slot="icon" :size="20" />
4672
</NcActionInput>
4773

48-
<NcActionButton v-if="!note.readonly" :icon="actionDeleteIcon" @click="onDeleteNote">
49-
{{ t('notes', 'Delete note') }}
50-
</NcActionButton>
51-
5274
<NcActionSeparator />
5375

54-
<NcActionButton icon="icon-files-dark" @click="onCategorySelected">
55-
{{ actionCategoryText }}
76+
<NcActionButton v-if="!note.readonly" :icon="actionDeleteIcon" @click="onDeleteNote">
77+
{{ t('notes', 'Delete note') }}
5678
</NcActionButton>
5779
</template>
5880
</NcListItem>
@@ -62,18 +84,20 @@
6284
import { NcListItem, NcActionButton, NcActionSeparator, NcActionInput } from '@nextcloud/vue'
6385
import AlertOctagonIcon from 'vue-material-design-icons/AlertOctagon.vue'
6486
import FileDocumentOutlineIcon from 'vue-material-design-icons/FileDocumentOutline.vue'
87+
import FolderIcon from 'vue-material-design-icons/Folder.vue'
6588
import PencilIcon from 'vue-material-design-icons/Pencil.vue'
6689
import StarIcon from 'vue-material-design-icons/Star.vue'
6790
import { categoryLabel, routeIsNewNote } from '../Util.js'
6891
import { showError } from '@nextcloud/dialogs'
69-
import { setFavorite, setTitle, fetchNote, deleteNote } from '../NotesService.js'
92+
import { setFavorite, setTitle, fetchNote, deleteNote, setCategory } from '../NotesService.js'
7093
7194
export default {
7295
name: 'NoteItem',
7396
7497
components: {
7598
AlertOctagonIcon,
7699
FileDocumentOutlineIcon,
100+
FolderIcon,
77101
NcActionButton,
78102
NcListItem,
79103
StarIcon,
@@ -93,9 +117,11 @@ export default {
93117
return {
94118
loading: {
95119
note: false,
120+
category: false,
96121
},
97122
newTitle: '',
98123
renaming: false,
124+
showCategorySelect: false,
99125
}
100126
},
101127
@@ -128,8 +154,24 @@ export default {
128154
actionDeleteIcon() {
129155
return 'icon-delete' + (this.loading.delete ? ' loading' : '')
130156
},
157+
categories() {
158+
return [
159+
{
160+
id: '',
161+
label: categoryLabel(''),
162+
},
163+
...this.$store.getters.getCategories(0, false).map((category) => ({
164+
id: category,
165+
label: categoryLabel(category),
166+
})),
167+
]
168+
},
131169
},
132170
methods: {
171+
onMenuChange(state) {
172+
this.actionsOpen = state
173+
this.showCategorySelect = false
174+
},
133175
onNoteSelected(noteId) {
134176
this.$emit('note-selected', noteId)
135177
},
@@ -155,6 +197,15 @@ export default {
155197
onInputChange(event) {
156198
this.newTitle = event.target.value.toString()
157199
},
200+
async onCategoryChange(result) {
201+
this.showCategorySelect = false
202+
const category = result?.id ?? result?.label ?? null
203+
if (category !== null && this.note.category !== category) {
204+
this.loading.category = true
205+
await setCategory(this.note.id, category)
206+
this.loading.category = false
207+
}
208+
},
158209
async onRename() {
159210
const newTitle = this.newTitle.toString()
160211
if (!newTitle) {
@@ -171,7 +222,6 @@ export default {
171222
})
172223
.finally(() => {
173224
this.loading.note = false
174-
this.renaming = false
175225
})
176226
177227
if (routeIsNewNote(this.$route)) {

src/components/NotesList.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<NoteItem v-for="note in notes"
44
:key="note.id"
55
:note="note"
6-
@note-selected="onNoteSelected"
76
:renaming="isRenaming(note.id)"
7+
@note-selected="onNoteSelected"
88
@start-renaming="onStartRenaming"
99
/>
1010
</ul>
@@ -29,17 +29,17 @@ export default {
2929
data() {
3030
return {
3131
renamingNotes: [],
32-
};
32+
}
3333
},
3434
methods: {
3535
onNoteSelected(noteId) {
3636
this.$emit('note-selected', noteId)
3737
},
3838
onStartRenaming(noteId) {
39-
this.renamingNotes.push(noteId);
39+
this.renamingNotes.push(noteId)
4040
},
4141
isRenaming(noteId) {
42-
return this.renamingNotes.includes(noteId);
42+
return this.renamingNotes.includes(noteId)
4343
},
4444
4545
},

0 commit comments

Comments
 (0)