-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.jsx
159 lines (145 loc) · 6.65 KB
/
index.jsx
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
const textarea = document.getElementById("text-field");
const input = document.getElementById("title");
const input2 = document.getElementById("input2");
const save_btn = document.getElementById("submit");
const color_red = document.getElementById("red");
const color_blue = document.getElementById("blue");
const color_green = document.getElementById("green");
const color_purple = document.getElementById("purple");
const category1 = document.getElementById("s1");
const category2 = document.getElementById("s2");
const category3 = document.getElementById("s3");
const notepad = document.querySelector(".notepad");
const add_btn = document.getElementById("add_note");
let message_text = "Note saved sucessfully";
let appendNote = document.createElement("div");
notepad.appendChild(appendNote);
let cat1 = "Design";
let cat2 = "Networking";
let cat3 = "Student";
const date = new Date(); //getting todays date
const day = date.getDate(); //getting today's full date with getDate function
const month = date.getMonth() + 1; //getting today's month with getMonth function
const year = date.getFullYear();//getting current year in full with getFullYear function
console.log(day); //logging date to the console
const monthNames = ["Jan", "Feb", "Mar", "April", "May", "Jun",
"Jul", "Aug", "Sept", "Oct", "Nov", "Dec"
]; //calling all the months
const d = new Date(); //getting todays date
let fullMonth = monthNames[d.getMonth()]
console.log(fullMonth + ' ' + year); //logging fullmonth and year to the console
var days = ['Sun','Mon','Tues','Wed','Thurs','Fri','Sat']; //setting the days of the week in an array
var day2 = days[ date.getDay() ];
console.log(day2); //loggging the current day of the week to the console
window.onbeforeunload = function() {
return true; //prevening page from loading
}
let tdoo = { "Header": textarea.value, "Body": input.value, "category": input2.value, "Dates": day2 + ' ' + fullMonth + ' ' + year} //getting full information from called properties
save_btn.addEventListener("click", () => { //save button onclick
let tdoo = { "Header": textarea.value, "Body": input.value, "category": input2.value, "Dates": day2 + ' ' + fullMonth + ' ' + year} //getting full information from called properties
let appendNote = document.createElement("div");
notepad.appendChild(appendNote);
console.log(message_text); //custom note message for saving
setTimeout(() => {
console.clear(); //clearing the console
}, 1000);
setTimeout(() => {
localStorage.setItem("Storage", JSON.stringify(tdoo)); //setting localstorage and adding a "Storage" item, stringifying the called tdoo element
var retrieveData = JSON.parse(localStorage.getItem("Storage")); //localstorage now is getting the setItem of tdoo and parsing to the set "Storage" Item of localStorage
console.log(retrieveData);
// console.error(tdoo.Body);
// console.log(textarea.value);
appendNote.innerHTML = `<div class="note-content">
<div class="notes">
<div class="note-title" id="ntx">${tdoo.Body}</div>
<div class="note-pfx">
<p class="note-sub">${tdoo.Header}</p>
</div>
<div class="c5">
<div class="category">
<div class="cat" id="category">${tdoo.category}</div>
</div>
<div class="date-created">
<div class="date" id="date">${tdoo.Dates}</div>
</div>
</div>
<div class="tweet">
<div class="tweet_content">
<a href="https://twitter.com/intent/tweet?url=${tdoo.Body + ' ' + tdoo.Header}" rel="noopener" class="tweet_btn">Tweet <i class="fa-brands fa-twitter"></i></a>
</div>
</div>
</div>
</div>`
}, 2000);
});
window.addEventListener("load", () => {
textarea.value = tdoo.Header;
input.value = tdoo.Body;
input2.value = tdoo.category;
appendNote.innerHTML = `<div class="note-content">
<div class="notes">
<div class="note-title" id="ntx">${tdoo.Body}</div>
<div class="note-pfx">
<p class="note-sub">${tdoo.Header}</p>
</div>
<div class="c5">
<div class="category">
<div class="cat" id="category">${tdoo.category}</div>
</div>
<div class="date-created">
<div class="date" id="date">${tdoo.Dates}</div>
</div>
</div>
<div class="tweet">
<div class="tweet_content">
<a href="https://twitter.com/intent/tweet?url=${tdoo.Body + ' ' + tdoo.Header}" rel="noopener" class="tweet_btn">Tweet <i class="fa-brands fa-twitter"></i></a>
</div>
</div>
</div>
</div>`
});
const add_color = (cname) => {
const colors = ["blue", "red", "green", "purple"];
colors.filter(c => c !== cname).map(c => textarea.classList.remove(c));
textarea.classList.add(cname);
};
color_red.addEventListener("click", function(event) {
console.log(event.target);
add_color("red");
})
color_blue.addEventListener("click", function(event) {
console.log(event.target);
add_color("blue");
})
color_green.addEventListener("click", function(event) {
console.log(event.target);
add_color("blue");
})
color_purple.addEventListener("click", function(event) {
console.log(event.target);
add_color("blue");
})
category1.addEventListener("click", (e) => {
console.log(e.target);
document.getElementById("category").innerHTML = `${cat1}`
input2.value = `${cat1}`;
});
category2.addEventListener("click", (e) => {
console.log(e.target);
document.getElementById("category").innerHTML = `${cat2}`
input2.value = `${cat2}`;
});
category3.addEventListener("click", (e) => {
console.log(e.target);
document.getElementById("category").innerHTML = `${cat3}`
input2.value = `${cat3}`;
});
// categories button to change the note category
add_btn.addEventListener("click", (e) => {
document.querySelector(".container").style.display = "block";
document.querySelector(".wrapper").style.display = "none"; //linking to the write note page
});
document.getElementById("return").addEventListener("click", function(event) {
document.querySelector(".container").style.display = "none";
document.querySelector(".wrapper").style.display = "block"; //returning back to the main note page
});