diff --git a/src/home.js b/src/home.js index fc3dbca..08cabbc 100644 --- a/src/home.js +++ b/src/home.js @@ -1,7 +1,12 @@ /* globals clientData */ const moment = require('moment') +const initSearch = require('./search') + +const noteMap = {} const contentStr = clientData.reduce((acc, note, idx) => { + const title = note.name.toLowerCase() + noteMap[title] = note.name return acc + `
@@ -27,13 +32,14 @@ Modified ${moment(note.mtimeMs).fromNow()} module.exports = () => { const containerElement = document.querySelector('#mainAppElement') containerElement.innerHTML = ` -
-
-
- ${contentStr} -
-
+
+
+
+ ${contentStr} +
+
+
-
-` + ` + initSearch(noteMap) } diff --git a/public/search.js b/src/search.js similarity index 91% rename from public/search.js rename to src/search.js index 1bf9fb8..062005c 100644 --- a/public/search.js +++ b/src/search.js @@ -1,14 +1,9 @@ +const resultContainer = document.querySelector('#resultListContainer') const searchBox = document.querySelector('#searchBox') const allNotes = document.querySelectorAll('.card-columns .card-title') -const noteMap = Array.from(allNotes).reduce((acc, e) => { - const title = e.innerText.toLowerCase() - acc[title] = e.innerText - return acc -}, {}) - let resultElements = [] -const resultContainer = document.querySelector('#resultListContainer') -searchBox.focus() +let noteMap = {} + const search = () => { const searchQuery = searchBox.value if (searchQuery.length < 2) return @@ -73,3 +68,9 @@ searchBox.addEventListener('keyup', (e) => { search() }) +const initSearch = (titleMap) => { + searchBox.focus() + noteMap = titleMap +} + +module.exports = initSearch diff --git a/views/notes.ejs b/views/notes.ejs index 9da60f5..1755a87 100644 --- a/views/notes.ejs +++ b/views/notes.ejs @@ -1,4 +1,5 @@ <%- include('./layout/header.ejs') %> +

@@ -27,5 +28,4 @@ console.log(clientData) - <%- include('./layout/footer.ejs') %>