Skip to content

Commit b5dcbc1

Browse files
committed
changes
1 parent fd5a168 commit b5dcbc1

4 files changed

Lines changed: 105 additions & 6 deletions

File tree

app/components/DeleteComponent.vue

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<script setup>
2+
const showPopup = ref(false);
3+
4+
onMounted(() => {
5+
setTimeout(() => {
6+
showPopup.value = true;
7+
}, 100);
8+
});
9+
10+
const props = defineProps({
11+
id: {
12+
type: String,
13+
required: true,
14+
},
15+
});
16+
17+
const emit = defineEmits(["closeDelete", "deleteNote"]);
18+
const close = () => {
19+
emit("closeDelete");
20+
};
21+
22+
const deleteNote = () => {
23+
emit("deleteNote", props.id);
24+
close();
25+
};
26+
27+
onBeforeMount(() => {
28+
showPopup.value = false;
29+
});
30+
</script>
31+
32+
<template>
33+
<div
34+
class="fixed inset-0 z-50 bg-vue-green/7 flex items-center justify-center"
35+
@keydown.esc="close"
36+
>
37+
<div
38+
class="w-[80vw] md:w-[50vw] lg:w-[40vw] bg-background rounded-xl p-6 shadow-lg transition-opacity duration-300 ease-in-out overflow-y-auto max-h-[95vh] scroll-container"
39+
>
40+
<div class="flex flex-col space-y-4">
41+
<div class="flex items-center justify-between">
42+
<h2 class="text-lg font-semibold text-background-dark">
43+
Confirm Delete Note
44+
</h2>
45+
46+
<button
47+
@click="close"
48+
type="button"
49+
class="text-black hover:text-gray-500 transition-colors duration-75 cursor-pointer"
50+
>
51+
<Icon name="mdi:close" size="20" />
52+
</button>
53+
</div>
54+
<p class="text-gray-500">
55+
Are you sure you want to delete this note? This action cannot be
56+
undone.
57+
</p>
58+
<div class="flex justify-end space-x-2">
59+
<button
60+
@click="close"
61+
class="cursor-pointer px-4 py-2 bg-gray-300 text-gray-800 rounded hover:bg-gray-400 transition-colors"
62+
>
63+
Cancel
64+
</button>
65+
<button
66+
type="button"
67+
@click="deleteNote"
68+
class="cursor-pointer px-4 py-2 bg-red-600 text-white rounded hover:bg-red-700 transition-colors"
69+
>
70+
Delete
71+
</button>
72+
</div>
73+
</div>
74+
</div>
75+
</div>
76+
</template>

app/components/NoteCard.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ const deleteNote = () => {
3434
emit("delete");
3535
};
3636
37+
const handleCopy = () => {
38+
copyToClipboard(props.note.content || props.note.title);
39+
};
40+
3741
const limitText = (text: string, limit: number) => {
3842
return text.length > limit ? text.slice(0, limit) + "..." : text;
3943
};
@@ -52,7 +56,7 @@ const limitText = (text: string, limit: number) => {
5256

5357
<div
5458
class="text-background/95 text-sm font-semibold"
55-
@click="editNote()"
59+
@click="editNote"
5660
>
5761
{{ limitText(props.note?.title, 25) || "Untitled" }}
5862
</div>
@@ -61,21 +65,21 @@ const limitText = (text: string, limit: number) => {
6165
<!-- actions -->
6266
<div class="flex items-center space-x-2 text-background/75">
6367
<button
64-
@click="copyToClipboard(props.note.content || props.note.title)"
68+
@click="handleCopy"
6569
title="Copy to clipboard"
6670
class="hover:text-vue-green transition-colors cursor-pointer"
6771
>
6872
<Icon name="mdi:clipboard" size="22" />
6973
</button>
7074
<button
71-
@click="editNote()"
75+
@click="editNote"
7276
title="Edit note"
7377
class="hover:text-vue-green transition-colors cursor-pointer"
7478
>
7579
<Icon name="mdi:edit" size="22" />
7680
</button>
7781
<button
78-
@click="deleteNote()"
82+
@click="deleteNote"
7983
title="Delete note"
8084
class="hover:text-vue-green transition-colors cursor-pointer"
8185
>
@@ -86,7 +90,7 @@ const limitText = (text: string, limit: number) => {
8690

8791
<p
8892
class="mt-2 text-gray-500 text-sm font-light leading-relaxed"
89-
@click="editNote()"
93+
@click="editNote"
9094
>
9195
{{ limitText(props.note?.content, 50) || "No content available." }}
9296
</p>

app/components/NoteList.vue

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { type Note, useNotes } from "@/composables/useNotes";
33
const { deleteNote } = useNotes();
44
const selectedCategoryId = ref("");
5+
const noteToDeleteId = ref("");
56
67
const props = defineProps({
78
listOfNotes: {
@@ -20,6 +21,17 @@ const editOneNote = (note: Note) => {
2021
emit("edit", note);
2122
};
2223
24+
const showPopup = ref(false);
25+
const togglePopup = (noteId: string) => {
26+
noteToDeleteId.value = noteId;
27+
showPopup.value = !showPopup.value;
28+
};
29+
30+
const closePopup = () => {
31+
showPopup.value = false;
32+
noteToDeleteId.value = "";
33+
};
34+
2335
const deleteOneNote = (noteId: string) => {
2436
deleteNote(noteId);
2537
refreshNotes();
@@ -55,7 +67,7 @@ onMounted(() => {
5567
:key="note.id"
5668
:note="note"
5769
@edit="editOneNote(note)"
58-
@delete="deleteOneNote(note.id)"
70+
@delete="togglePopup(note.id)"
5971
/>
6072
<div
6173
v-if="filteredNotes.length === 0"
@@ -64,4 +76,10 @@ onMounted(() => {
6476
No notes available. Please add a note.
6577
</div>
6678
</div>
79+
<DeleteComponent
80+
v-if="showPopup"
81+
@closeDelete="closePopup"
82+
@deleteNote="deleteOneNote(noteToDeleteId)"
83+
:id="noteToDeleteId"
84+
/>
6785
</template>

app/composables/useNotes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function useNotes() {
4646
}
4747

4848
function deleteNote(noteId: string) {
49+
// console.log("Deleting note with ID:", noteId);
4950
notes.value = notes.value.filter((note) => note.id !== noteId);
5051
saveNotes();
5152
}

0 commit comments

Comments
 (0)