-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes-app.html
More file actions
136 lines (116 loc) · 5.14 KB
/
notes-app.html
File metadata and controls
136 lines (116 loc) · 5.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Buggy Notes App</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<div class="container py-5">
<h2 class="mb-4">My Notes</h2>
<!-- Add Note Form -->
<form id="addNoteForm" class="mb-4">
<div class="row g-2">
<div class="col-md-4">
<input type="text" id="noteTitle" class="form-control" placeholder="Note title" required>
</div>
<div class="col-md-6">
<input type="text" id="noteDescription" class="form-control" placeholder="Note description"
required>
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-success w-100">Add Note</button>
</div>
</div>
</form>
<!-- Notes List -->
<div id="notesList" class="row g-3">
<!-- Notes will be rendered here -->
</div>
</div>
<!-- View Note Modal -->
<div class="modal fade" id="viewNoteModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modalNoteTitle">Note Title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body" id="modalNoteBody">
Note content goes here.
</div>
</div>
</div>
</div>
<script>
// Static notes data
let notes = [
{ id: 1, title: "Shopping List", description: "Buy milk, eggs, and bread. Don’t forget the fruits." },
{ id: 2, title: "Project Ideas", description: "Build a quiz app. Try making a notes app with bugs." },
{ id: 3, title: "Meeting Notes", description: "Discuss Q3 targets. Assign tasks to the dev team." }
];
const notesList = document.getElementById("notesList");
function renderNotes() {
notesList.innerHTML = "";
notes.forEach(note => {
const col = document.createElement("div");
col.className = "col-md-4";
col.innerHTML = `
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">${note.title}</h5>
<p class="card-text">${note.description.substring(0, 50)}...</p>
<button class="btn btn-sm btn-primary view-btn" data-bs-toggle="modal" data-bs-target="#viewNoteModal">View</button>
<button class="btn btn-sm btn-warning edit-btn">Edit</button>
<button class="btn btn-sm btn-danger delete-btn">Delete</button>
</div>
</div>
`;
notesList.appendChild(col);
});
}
renderNotes();
// ❌ Bug: Edit button does nothing
document.addEventListener("click", function (e) {
if (e.target.classList.contains("edit-btn")) {
// alert("Edit not working yet!");
}
});
// ❌ Bug: Delete button deletes ALL notes
document.addEventListener("click", function (e) {
if (e.target.classList.contains("delete-btn")) {
notesList.innerHTML = ""; // clears all instead of one
}
});
// ❌ Bug: View button always opens last note
const modalNoteTitle = document.getElementById("modalNoteTitle");
const modalNoteBody = document.getElementById("modalNoteBody");
document.addEventListener("click", function (e) {
if (e.target.classList.contains("view-btn")) {
const lastNote = notes[notes.length - 1]; // always last
modalNoteTitle.innerText = lastNote.title;
modalNoteBody.innerText = lastNote.description;
}
});
// ✅ Add Note functionality (with bugs)
document.getElementById("addNoteForm").addEventListener("submit", function (e) {
e.preventDefault();
const title = document.getElementById("noteTitle").value;
const description = document.getElementById("noteDescription").value;
// ❌ Bug: new notes all get the same ID
const newNote = {
id: notes.length + 1,
title: title,
description: description
};
notes.push(newNote);
renderNotes();
// ❌ Bug: form fields don’t clear properly
document.getElementById("noteTitle").value = "";
// forgot to clear description on purpose
});
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>