2929 <NcActionButton :icon =" actionFavoriteIcon" @click =" onToggleFavorite" >
3030 {{ actionFavoriteText }}
3131 </NcActionButton >
32+
33+ <NcActionButton v-if =" !renaming" @click =" startRenaming" >
34+ <PencilIcon slot =" icon" :size =" 20" />
35+ {{ t('notes', 'Rename') }}
36+ </NcActionButton >
37+ <NcActionInput v-else
38+ v-model.trim =" newTitle"
39+ :disabled =" !renaming"
40+ :placeholder =" t('notes', 'Rename note')"
41+ :show-trailing-button =" true"
42+ @input =" onInputChange($event)"
43+ @submit =" onRename"
44+ >
45+ <PencilIcon slot =" icon" :size =" 20" />
46+ </NcActionInput >
47+
3248 <NcActionButton v-if =" !note.readonly" :icon =" actionDeleteIcon" @click =" onDeleteNote" >
3349 {{ t('notes', 'Delete note') }}
3450 </NcActionButton >
51+
3552 <NcActionSeparator />
53+
3654 <NcActionButton icon =" icon-files-dark" @click =" onCategorySelected" >
3755 {{ actionCategoryText }}
3856 </NcActionButton >
4159</template >
4260
4361<script >
44- import { NcListItem , NcActionButton , NcActionSeparator } from ' @nextcloud/vue'
62+ import { NcListItem , NcActionButton , NcActionSeparator , NcActionInput } from ' @nextcloud/vue'
4563import AlertOctagonIcon from ' vue-material-design-icons/AlertOctagon.vue'
4664import FileDocumentOutlineIcon from ' vue-material-design-icons/FileDocumentOutline.vue'
65+ import PencilIcon from ' vue-material-design-icons/Pencil.vue'
4766import StarIcon from ' vue-material-design-icons/Star.vue'
4867import { categoryLabel , routeIsNewNote } from ' ../Util.js'
4968import { showError } from ' @nextcloud/dialogs'
@@ -59,6 +78,8 @@ export default {
5978 NcListItem,
6079 StarIcon,
6180 NcActionSeparator,
81+ NcActionInput,
82+ PencilIcon,
6283 },
6384
6485 props: {
@@ -73,6 +94,8 @@ export default {
7394 loading: {
7495 note: false ,
7596 },
97+ newTitle: ' ' ,
98+ renaming: false ,
7699 }
77100 },
78101
@@ -106,7 +129,6 @@ export default {
106129 return ' icon-delete' + (this .loading .delete ? ' loading' : ' ' )
107130 },
108131 },
109-
110132 methods: {
111133 onNoteSelected (noteId ) {
112134 this .$emit (' note-selected' , noteId)
@@ -125,20 +147,41 @@ export default {
125147 this .actionsOpen = false
126148 this .$emit (' category-selected' , this .note .category )
127149 },
128- onRename (newTitle ) {
150+ startRenaming () {
151+ this .renaming = true
152+ this .newTitle = this .note .title
153+ this .$emit (' start-renaming' , this .note .id )
154+ },
155+ onInputChange (event ) {
156+ this .newTitle = event .target .value .toString ()
157+ },
158+ async onRename () {
159+ const newTitle = this .newTitle .toString ()
160+ if (! newTitle) {
161+ return
162+ }
129163 this .loading .note = true
130164 setTitle (this .note .id , newTitle)
131- .catch (() => {
165+ .then (() => {
166+ this .newTitle = ' '
167+ })
168+ .catch ((e ) => {
169+ console .error (' Failed to rename note' , e)
170+ showError (this .t (' notes' , ' Error while renaming note.' ))
132171 })
133172 .finally (() => {
134173 this .loading .note = false
174+ this .renaming = false
135175 })
176+
136177 if (routeIsNewNote (this .$route )) {
137178 this .$router .replace ({
138179 name: ' note' ,
139180 params: { noteId: this .note .id .toString () },
140181 })
141182 }
183+ this .renaming = false
184+
142185 },
143186 async onDeleteNote () {
144187 this .loading .delete = true
0 commit comments