-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes-app.js
44 lines (35 loc) · 937 Bytes
/
notes-app.js
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
"use strict";
let notes = getSavedNotes();
const filters = {
searchText: "",
sortBy: "byEdited",
};
renderNotes(notes, filters);
document.querySelector("#create-note").addEventListener("click", (e) => {
const id = uuidv4();
const timeStamp = moment().valueOf();
notes.push({
id: id,
title: "",
body: "",
ctreatedAt: timeStamp,
updatedAt: timeStamp,
});
saveNotes(notes);
renderNotes(notes, filters);
location.assign(`/notes-app/edit.html#${id}`);
});
document.querySelector("#search-text").addEventListener("input", (e) => {
filters.searchText = e.target.value;
renderNotes(notes, filters);
});
document.querySelector("#filter-by").addEventListener("change", (e) => {
filters.sortBy = e.target.value;
renderNotes(notes, filters);
});
window.addEventListener("storage", (e) => {
if (e.key === "notes") {
notes = JSON.parse(e.newValue);
renderNotes(notes, filters);
}
});