2424 :size =" 20"
2525 fill-color =" var(--color-text-lighter)"
2626 />
27+
2728 </template >
2829 <template #actions >
2930 <NcActionButton :icon =" actionFavoriteIcon" @click =" onToggleFavorite" >
3031 {{ actionFavoriteText }}
3132 </NcActionButton >
33+
34+ <NcActionButton v-if =" !renaming" @click =" startRenaming" >
35+ <MarkdownPencil slot =" icon" :size =" 20" />
36+ {{ t('notes', 'Rename') }}
37+ </NcActionButton >
38+ <NcActionInput v-else
39+ v-model.trim =" newTitle"
40+ @input =" onInputChange($event)"
41+ @submit =" onRename"
42+ :disabled =" !renaming"
43+ :placeholder =" t('notes', 'Rename note')"
44+ :show-trailing-button =" true"
45+ >
46+ <MarkdownPencil slot =" icon" :size =" 20" />
47+ </NcActionInput >
48+
3249 <NcActionButton v-if =" !note.readonly" :icon =" actionDeleteIcon" @click =" onDeleteNote" >
3350 {{ t('notes', 'Delete note') }}
3451 </NcActionButton >
35- <NcActionSeparator />
52+
53+ <NcActionSeparator />
54+
3655 <NcActionButton icon =" icon-files-dark" @click =" onCategorySelected" >
3756 {{ actionCategoryText }}
3857 </NcActionButton >
58+
3959 </template >
4060 </NcListItem >
4161</template >
4262
4363<script >
44- import { NcListItem , NcActionButton , NcActionSeparator } from ' @nextcloud/vue'
64+ import { NcListItem , NcActionButton , NcActionSeparator , NcActionInput } from ' @nextcloud/vue'
4565import AlertOctagonIcon from ' vue-material-design-icons/AlertOctagon.vue'
4666import FileDocumentOutlineIcon from ' vue-material-design-icons/FileDocumentOutline.vue'
4767import StarIcon from ' vue-material-design-icons/Star.vue'
4868import { categoryLabel , routeIsNewNote } from ' ../Util.js'
4969import { showError } from ' @nextcloud/dialogs'
5070import { setFavorite , setTitle , fetchNote , deleteNote } from ' ../NotesService.js'
71+ import store from ' ../store.js'
72+ import MarkdownPencil from " ./Icons/MarkdownPencil.vue" ;
5173
5274export default {
5375 name: ' NoteItem' ,
@@ -59,20 +81,26 @@ export default {
5981 NcListItem,
6082 StarIcon,
6183 NcActionSeparator,
84+ NcActionInput,
85+ MarkdownPencil,
86+
6287 },
6388
6489 props: {
6590 note: {
6691 type: Object ,
6792 required: true ,
6893 },
94+
6995 },
7096
7197 data () {
7298 return {
7399 loading: {
74100 note: false ,
75101 },
102+ newTitle: " " ,
103+ renaming: false ,
76104 }
77105 },
78106
@@ -106,7 +134,6 @@ export default {
106134 return ' icon-delete' + (this .loading .delete ? ' loading' : ' ' )
107135 },
108136 },
109-
110137 methods: {
111138 onNoteSelected (noteId ) {
112139 this .$emit (' note-selected' , noteId)
@@ -125,20 +152,41 @@ export default {
125152 this .actionsOpen = false
126153 this .$emit (' category-selected' , this .note .category )
127154 },
155+ startRenaming () {
156+ this .renaming = true ;
157+ this .$emit (' start-renaming' , this .note .id );
158+ },
159+ onInputChange (event ) {
160+ this .newTitle = event .target .value .toString ();
161+ },
128162 onRename (newTitle ) {
129- this .loading .note = true
163+ newTitle = this .newTitle .toString ();
164+ if (! newTitle) {
165+ return ;
166+ }
167+ this .loading .note = true ;
130168 setTitle (this .note .id , newTitle)
169+ .then (() => {
170+ this .note .title = newTitle;
171+ this .newTitle = " " ;
172+ })
131173 .catch (() => {
174+ console .log (' error' )
175+ showError (this .t (' notes' , ' Error while renaming note.' ));
132176 })
133177 .finally (() => {
134- this .loading .note = false
135- })
178+ this .loading .note = false ;
179+ this .renaming = false ;
180+ });
181+
136182 if (routeIsNewNote (this .$route )) {
137183 this .$router .replace ({
138184 name: ' note' ,
139- params: { noteId: this .note .id .toString () },
140- })
185+ params: {noteId: this .note .id .toString ()},
186+ });
141187 }
188+ this .renaming = false ;
189+
142190 },
143191 async onDeleteNote () {
144192 this .loading .delete = true
0 commit comments