Skip to content

Commit f473618

Browse files
committed
Updated files
1 parent 4d8f585 commit f473618

File tree

3 files changed

+25
-53
lines changed

3 files changed

+25
-53
lines changed

public/images/plus.png

1.13 KB
Loading

public/images/square_add.png

1.17 KB
Loading

public/javascript/script.js

Lines changed: 25 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ class Notes {
6464
objectStore.createIndex('title', 'title', { unique: false });
6565
objectStore.createIndex('body', 'body', { unique: false });
6666
objectStore.createIndex('noteid', 'noteid', { unique: true });
67-
objectStore.createIndex('created_at', 'created_at', { unique: true });
68-
objectStore.createIndex('updated_at', 'updated_at', { unique: true });
6967
db.close();
7068
};
7169
}
@@ -107,17 +105,13 @@ const queryDB = () => {
107105
var cust = tx.objectStore("notes")
108106
var request = cust.openCursor()
109107
request.onsuccess = (e) => {
110-
var cursor = e.target.result
108+
var cursor = e.target.result
109+
111110
if (cursor) {
112111
//`{noteid: ${cursor.key}, title: ${cursor.value.title}, body: ${cursor.value.body}}`
113112
// contenteditable
114-
var date_diff = countDown(cursor.value.created_at)
115-
var ago = []
116-
date_diff.days > 0 ? ago[0] = (date_diff.days + "d") : date_diff.hours > 0 ? ago[1] = (date_diff.hours + "h") : date_diff.minutes > 0 ? ago[2] = (date_diff.seconds + "m") : ago[2] = "now"
117-
console.log(ago)
118113
html = `<div class="column note" id="${cursor.key}" onclick='showNote(this)'>
119114
<h2>${marked(cursor.value.title)}</h2>
120-
<caption>Created ${ago[0]||""} ${ago[1]||""} ${ago[2]||""} ago</caption>
121115
</div>`;
122116
notesGrid.innerHTML += html;
123117
noteSelect()
@@ -156,7 +150,7 @@ function showNote(notediv){
156150
} else{}
157151
}
158152
}
159-
// document.getElementById(notediv.id).classList.add("active")
153+
document.getElementById(notediv.id).classList.add(" active")
160154
}
161155

162156
function noteSelect(){
@@ -204,37 +198,19 @@ function deleteNote(notediv) {
204198
}
205199
}
206200

207-
208-
209-
function countDown(epoch_timestamp) {
210-
var now = new Date().getTime();
211-
// Find the distance between now and the count down date
212-
var distance = now - epoch_timestamp * 1000;
213-
// Time calculations for days, hours, minutes and seconds
214-
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
215-
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
216-
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
217-
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
218-
219-
dateJson = {
220-
days: days,
221-
hours: hours,
222-
minutes: minutes,
223-
seconds: seconds
224-
}
225-
return dateJson
226-
}
227201
// Get new note values from the UI
228202
function save() {
203+
function genID(d) {
204+
return Math.floor(d / 1000);
205+
}
229206
var noteTitle = document.getElementById("title").value
230207
var noteBody = document.getElementById("notebody").value
231-
var id = Math.round(Date.now() / 1000)
208+
var d = new Date()
209+
var id = genID(d);
232210
const note = {
233211
noteid: id.toString(),
234212
title: noteTitle,
235-
body: noteBody,
236-
created_at: id.toString(),
237-
updated_at: ""
213+
body: noteBody
238214
};
239215
console.log(note)
240216
addNote(note)
@@ -263,18 +239,30 @@ function update(editdiv) {
263239
var id = editdiv.name
264240
var noteTitle = document.getElementById("title").value
265241
var noteBody = document.getElementById("notebody").value
266-
var updated_at = Math.round(Date.now() / 1000)
267242
const note = {
268243
noteid: id.toString(),
269244
title: noteTitle,
270-
body: noteBody,
271-
created_at: id.toString(),
272-
updated_at: updated_at.toString()
245+
body: noteBody
273246
};
274247
console.log(note)
275248
updateNote(note)
276249
}
277250

251+
// Update note in the database
252+
function updateNote(note){
253+
var connection = indexedDB.open(DBNAME);
254+
connection.onsuccess = function () {
255+
db = connection.result;
256+
var tx = db.transaction('notes', "readwrite")
257+
var store = tx.objectStore("notes")
258+
store.put(note);
259+
tx.oncomplete = function () {
260+
console.log('Note updated' + note);
261+
document.getElementById(note.noteid).style.display = "none"
262+
}
263+
}
264+
getNote(note.noteid)
265+
}
278266

279267
function cancelEdit(notediv){
280268
if(notediv){
@@ -315,22 +303,6 @@ function getNote(noteid) {
315303
}
316304
}
317305

318-
// Update note in the database
319-
function updateNote(note) {
320-
var connection = indexedDB.open(DBNAME);
321-
connection.onsuccess = function () {
322-
db = connection.result;
323-
var tx = db.transaction('notes', "readwrite")
324-
var store = tx.objectStore("notes")
325-
store.put(note);
326-
tx.oncomplete = function () {
327-
console.log('Note updated' + note);
328-
document.getElementById(note.noteid).style.display = "none"
329-
}
330-
}
331-
getNote(note.noteid)
332-
}
333-
334306
const turndownService = new TurndownService();
335307

336308
// Get single note for editing

0 commit comments

Comments
 (0)