Skip to content

Commit ba219ed

Browse files
evukcevicjuliusknorr
authored andcommitted
-Adding MarkdownPencil component
-adding rename function for every note item in list -fix indentation -fix indentation -fix indentation
1 parent 91d0df1 commit ba219ed

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

src/components/NoteItem.vue

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,28 @@
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>
@@ -41,9 +59,10 @@
4159
</template>
4260

4361
<script>
44-
import { NcListItem, NcActionButton, NcActionSeparator } from '@nextcloud/vue'
62+
import { NcListItem, NcActionButton, NcActionSeparator, NcActionInput } from '@nextcloud/vue'
4563
import AlertOctagonIcon from 'vue-material-design-icons/AlertOctagon.vue'
4664
import FileDocumentOutlineIcon from 'vue-material-design-icons/FileDocumentOutline.vue'
65+
import PencilIcon from 'vue-material-design-icons/Pencil.vue'
4766
import StarIcon from 'vue-material-design-icons/Star.vue'
4867
import { categoryLabel, routeIsNewNote } from '../Util.js'
4968
import { 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

src/components/NotesList.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
:key="note.id"
55
:note="note"
66
@note-selected="onNoteSelected"
7+
:renaming="isRenaming(note.id)"
8+
@start-renaming="onStartRenaming"
79
/>
810
</ul>
911
</template>
@@ -24,11 +26,22 @@ export default {
2426
required: true,
2527
},
2628
},
27-
29+
data() {
30+
return {
31+
renamingNotes: [],
32+
};
33+
},
2834
methods: {
2935
onNoteSelected(noteId) {
3036
this.$emit('note-selected', noteId)
3137
},
38+
onStartRenaming(noteId) {
39+
this.renamingNotes.push(noteId);
40+
},
41+
isRenaming(noteId) {
42+
return this.renamingNotes.includes(noteId);
43+
},
44+
3245
},
3346
}
3447
</script>

0 commit comments

Comments
 (0)