Skip to content

Commit

Permalink
better
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamund Ferguson authored and xjamundx committed May 13, 2020
1 parent 24ce29b commit c32d03d
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions public/notes.js
Expand Up @@ -49,8 +49,8 @@ function handleSave(e) {
}

function handleHashChange(e) {
updateNav();
const id = location.hash.slice(1);
highlightCurrentNote(id);
const note = Note.getNote(id);
if (note) {
updateTitle(note.name);
Expand All @@ -67,26 +67,19 @@ function updateTitle(name) {
title.value = name;
}

function highlightCurrentNote(id) {
const highlightedClasses = ["selected", "bg-blue-300", "text-black", "block"];
const oldLink = document.querySelector(".selected");
const link = document.querySelector(`a[href="#${id}"]`);

// remove the old, add thew new ones
if (oldLink) oldLink.classList.remove(...highlightedClasses);
if (link) link.classList.add(...highlightedClasses);
}

function addNote(e) {
const id = getID();
Note.addNote(id);
updateNav();
}

function updateNav() {
const currentID = location.hash.slice(1);

const html = Note.getNotes()
.map(([id, name]) => {
return `<li><a href="#${id}">${name}</a></li>`;
const cls = id === currentID ? "bg-blue-300 text-black" : "";
return `<li><a href="#${id}" class="block ${cls}">${name}&nbsp;</a></li>`;
})
.join("");
notes.innerHTML = html;
Expand Down

0 comments on commit c32d03d

Please sign in to comment.