Skip to content

Commit 1f9f30b

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 1f9f30b

File tree

3 files changed

+97
-9
lines changed

3 files changed

+97
-9
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
<span class="material-design-icon">
3+
<svg-icon type="mdi" :path="path" :width="size" :height="size"></svg-icon>
4+
</span>
5+
</template>
6+
7+
<script>
8+
import SvgIcon from '@jamescoyle/vue-icon';
9+
import { mdiPencil } from '@mdi/js';
10+
export default {
11+
name: "MarkdownPencil",
12+
components: {
13+
SvgIcon
14+
},
15+
props: {
16+
size: {
17+
type: Number,
18+
default: 24
19+
},
20+
},
21+
data() {
22+
return {
23+
path: mdiPencil,
24+
}
25+
}
26+
}
27+
</script>

src/components/NoteItem.vue

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,52 @@
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'
4565
import AlertOctagonIcon from 'vue-material-design-icons/AlertOctagon.vue'
4666
import FileDocumentOutlineIcon from 'vue-material-design-icons/FileDocumentOutline.vue'
4767
import StarIcon from 'vue-material-design-icons/Star.vue'
4868
import { categoryLabel, routeIsNewNote } from '../Util.js'
4969
import { showError } from '@nextcloud/dialogs'
5070
import { setFavorite, setTitle, fetchNote, deleteNote } from '../NotesService.js'
71+
import store from '../store.js'
72+
import MarkdownPencil from "./Icons/MarkdownPencil.vue";
5173
5274
export 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

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)