-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
46 lines (45 loc) · 1.43 KB
/
app.js
File metadata and controls
46 lines (45 loc) · 1.43 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
function app() {
const entries = JSON.parse(localStorage.getItem('entries')) || [];
return {
entries,
date: new Date().toISOString().slice(0, 10),
description: '',
saveEntries() {
const Entries = {
date: this.date,
description: this.description,
};
this.entries.push(Entries);
localStorage.setItem('entries', JSON.stringify(this.entries));
this.resetForm();
},
resetForm() {
this.date = '';
this.description = '';
},
copyEntries() {
const text = this.entries.map(({date, description}) => {
return `# ${date}\n\n${description}`;
}).join('\n\n');
if (navigator.clipboard) {
navigator.clipboard.writeText(text);
} else {
console.error(text);
}
},
deleteAllEntries() {
this.entries = [];
localStorage.setItem('entries', JSON.stringify([]));
},
editEntries(index) {
const {date, description} = this.entries[index];
this.date = date;
this.description = description;
this.deleteEntries(index);
},
deleteEntries(index) {
this.entries.splice(index, 1);
localStorage.setItem('entries', JSON.stringify(this.entries));
}
};
}