Skip to content

Commit 1b0d7c4

Browse files
committed
fixup! -Adding MarkdownPencil component -adding rename function for every note item in list
1 parent 1f9f30b commit 1b0d7c4

File tree

2 files changed

+26
-58
lines changed

2 files changed

+26
-58
lines changed

src/components/Icons/MarkdownPencil.vue

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/components/NoteItem.vue

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,36 @@
2424
:size="20"
2525
fill-color="var(--color-text-lighter)"
2626
/>
27-
2827
</template>
2928
<template #actions>
3029
<NcActionButton :icon="actionFavoriteIcon" @click="onToggleFavorite">
3130
{{ actionFavoriteText }}
3231
</NcActionButton>
3332

3433
<NcActionButton v-if="!renaming" @click="startRenaming">
35-
<MarkdownPencil slot="icon" :size="20"/>
34+
<PencilIcon slot="icon" :size="20" />
3635
{{ t('notes', 'Rename') }}
3736
</NcActionButton>
3837
<NcActionInput v-else
3938
v-model.trim="newTitle"
40-
@input="onInputChange($event)"
41-
@submit="onRename"
4239
:disabled="!renaming"
4340
:placeholder="t('notes', 'Rename note')"
4441
:show-trailing-button="true"
42+
@input="onInputChange($event)"
43+
@submit="onRename"
4544
>
46-
<MarkdownPencil slot="icon" :size="20"/>
45+
<PencilIcon slot="icon" :size="20" />
4746
</NcActionInput>
4847

4948
<NcActionButton v-if="!note.readonly" :icon="actionDeleteIcon" @click="onDeleteNote">
5049
{{ t('notes', 'Delete note') }}
5150
</NcActionButton>
5251

53-
<NcActionSeparator/>
52+
<NcActionSeparator />
5453

5554
<NcActionButton icon="icon-files-dark" @click="onCategorySelected">
5655
{{ actionCategoryText }}
5756
</NcActionButton>
58-
5957
</template>
6058
</NcListItem>
6159
</template>
@@ -64,12 +62,11 @@
6462
import { NcListItem, NcActionButton, NcActionSeparator, NcActionInput } from '@nextcloud/vue'
6563
import AlertOctagonIcon from 'vue-material-design-icons/AlertOctagon.vue'
6664
import FileDocumentOutlineIcon from 'vue-material-design-icons/FileDocumentOutline.vue'
65+
import PencilIcon from 'vue-material-design-icons/Pencil.vue'
6766
import StarIcon from 'vue-material-design-icons/Star.vue'
6867
import { categoryLabel, routeIsNewNote } from '../Util.js'
6968
import { showError } from '@nextcloud/dialogs'
7069
import { setFavorite, setTitle, fetchNote, deleteNote } from '../NotesService.js'
71-
import store from '../store.js'
72-
import MarkdownPencil from "./Icons/MarkdownPencil.vue";
7370
7471
export default {
7572
name: 'NoteItem',
@@ -82,24 +79,22 @@ export default {
8279
StarIcon,
8380
NcActionSeparator,
8481
NcActionInput,
85-
MarkdownPencil,
86-
82+
PencilIcon,
8783
},
8884
8985
props: {
9086
note: {
9187
type: Object,
9288
required: true,
9389
},
94-
9590
},
9691
9792
data() {
9893
return {
9994
loading: {
10095
note: false,
10196
},
102-
newTitle: "",
97+
newTitle: '',
10398
renaming: false,
10499
}
105100
},
@@ -153,39 +148,39 @@ export default {
153148
this.$emit('category-selected', this.note.category)
154149
},
155150
startRenaming() {
156-
this.renaming = true;
157-
this.$emit('start-renaming', this.note.id);
151+
this.renaming = true
152+
this.newTitle = this.note.title
153+
this.$emit('start-renaming', this.note.id)
158154
},
159155
onInputChange(event) {
160-
this.newTitle = event.target.value.toString();
156+
this.newTitle = event.target.value.toString()
161157
},
162-
onRename(newTitle) {
163-
newTitle = this.newTitle.toString();
158+
async onRename() {
159+
const newTitle = this.newTitle.toString()
164160
if (!newTitle) {
165-
return;
161+
return
166162
}
167-
this.loading.note = true;
163+
this.loading.note = true
168164
setTitle(this.note.id, newTitle)
169165
.then(() => {
170-
this.note.title = newTitle;
171-
this.newTitle = "";
166+
this.newTitle = ''
172167
})
173-
.catch(() => {
174-
console.log('error')
175-
showError(this.t('notes', 'Error while renaming note.'));
168+
.catch((e) => {
169+
console.error('Failed to rename note', e)
170+
showError(this.t('notes', 'Error while renaming note.'))
176171
})
177172
.finally(() => {
178-
this.loading.note = false;
179-
this.renaming = false;
180-
});
173+
this.loading.note = false
174+
this.renaming = false
175+
})
181176
182177
if (routeIsNewNote(this.$route)) {
183178
this.$router.replace({
184179
name: 'note',
185-
params: {noteId: this.note.id.toString()},
186-
});
180+
params: { noteId: this.note.id.toString() },
181+
})
187182
}
188-
this.renaming = false;
183+
this.renaming = false
189184
190185
},
191186
async onDeleteNote() {

0 commit comments

Comments
 (0)