-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddnotes.js
More file actions
46 lines (40 loc) · 1.29 KB
/
addnotes.js
File metadata and controls
46 lines (40 loc) · 1.29 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
/* jshint esversion: 6 */
let addButton = document.getElementById("addButton");
let deleteButton = document.getElementById("deleteButton");
let titleInput = document.getElementById('titleInput');
let noteTextArea = document.getElementById('noteTextArea');
let ref = firebase.database().ref('/notes/');
var shouldLoadValue = false;
if (sessionStorage.getItem("editNotesId") != null){
shouldLoadValue = true;
var noteId = sessionStorage.getItem("editNotesId");
sessionStorage.removeItem("editNotesId");
deleteButton.setAttribute('style','');
}
if (shouldLoadValue){
ref = firebase.database().ref('/notes/' + noteId);
ref.once('value').then((snapshot)=>{
console.log(snapshot.val());
let note = snapshot.val();
addButton.innerHTML = "Sumbit changes";
titleInput.value = note.title;
noteTextArea.value = note.notemessage;
});
}
addButton.addEventListener('click', () => {
console.log("got to here");
if (shouldLoadValue){
ref.set({
title: titleInput.value,
notemessage: noteTextArea.value
});
} else {
ref.push({
title: titleInput.value,
notemessage: noteTextArea.value
});
}
});
deleteButton.addEventListener('click', () => {
ref.remove();
});