Skip to content

Commit 914d448

Browse files
committed
limit title and content characters
1 parent a0d44c4 commit 914d448

3 files changed

Lines changed: 33 additions & 12 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ Build a simple, fast, and local web application that allows a developer to:
2727
2. **Display and manage notes**
2828
- List of notes as cards or accordion
2929
- Shows title, content, and category
30-
- Buttons: 🗑️ Delete, 📋 Copy (Clipboard API)
30+
- Buttons: 🗑️ Delete, Edit, 📋 Copy (Clipboard API)
3131
- Filter by category
3232

33-
3. **Light/Dark theme**
33+
<!-- 3. **Light/Dark theme**
3434
- ☀️🌙 toggle button to switch appearance
35-
- Choice is saved in `localStorage`
35+
- Choice is saved in `localStorage` -->
3636

37-
4. **Persistence**
37+
3. **Persistence**
3838
- Data is stored client-side (`localStorage`)
3939
- No backend required, fast to deploy, offline ready
4040

app/components/NoteCard.vue

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script setup lang="ts">
2-
// TODO - Limit the number of characters in the note title and content
32
import { type Note } from "@/composables/useNotes";
43
import { categories as CategoryList, type Category } from "@/utils/categories";
4+
import { useClipboard } from "@/composables/useClipboard";
5+
const { copyToClipboard } = useClipboard();
56
67
const props = defineProps({
78
note: {
@@ -32,6 +33,10 @@ const editNote = () => {
3233
const deleteNote = () => {
3334
emit("delete");
3435
};
36+
37+
const limitText = (text: string, limit: number) => {
38+
return text.length > limit ? text.slice(0, limit) + "..." : text;
39+
};
3540
</script>
3641

3742
<template>
@@ -45,30 +50,45 @@ const deleteNote = () => {
4550
<Icon :name="category?.icon" size="1.5em" />
4651
</div>
4752

48-
<div class="text-background/95 text-sm font-semibold">
49-
{{ props.note?.title || "Untitled" }}
53+
<div
54+
class="text-background/95 text-sm font-semibold"
55+
@click="editNote()"
56+
>
57+
{{ limitText(props.note?.title, 25) || "Untitled" }}
5058
</div>
5159
</div>
5260

5361
<!-- actions -->
54-
<div class="flex items-center space-x-2 text-white">
62+
<div class="flex items-center space-x-2 text-background/75">
63+
<button
64+
@click="copyToClipboard(props.note.content || props.note.title)"
65+
title="Copy to clipboard"
66+
class="hover:text-vue-green transition-colors cursor-pointer"
67+
>
68+
<Icon name="mdi:clipboard" size="22" />
69+
</button>
5570
<button
5671
@click="editNote()"
72+
title="Edit note"
5773
class="hover:text-vue-green transition-colors cursor-pointer"
5874
>
59-
<Icon name="mdi:edit" size="20" />
75+
<Icon name="mdi:edit" size="22" />
6076
</button>
6177
<button
6278
@click="deleteNote()"
79+
title="Delete note"
6380
class="hover:text-vue-green transition-colors cursor-pointer"
6481
>
65-
<Icon name="mdi:trash" size="20" />
82+
<Icon name="mdi:trash" size="22" />
6683
</button>
6784
</div>
6885
</div>
6986

70-
<p class="mt-2 text-gray-500 text-sm font-light leading-relaxed">
71-
{{ props.note?.content || "No content available." }}
87+
<p
88+
class="mt-2 text-gray-500 text-sm font-light leading-relaxed"
89+
@click="editNote()"
90+
>
91+
{{ limitText(props.note?.content, 50) || "No content available." }}
7292
</p>
7393
</div>
7494
</div>

app/pages/index.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const startEdition = (note: Note) => {
2121
const closeForm = () => {
2222
showForm.value = false;
2323
noteToEdit.value = null;
24+
getNotes();
2425
};
2526
2627
useHead({

0 commit comments

Comments
 (0)