diff --git a/server.js b/server.js index f479b03..c06f309 100644 --- a/server.js +++ b/server.js @@ -187,7 +187,7 @@ Server.prototype.fillTemplate = function (file, templateVars = {}) { Server.prototype.generateHomePage = function (req) { const files = fs.readdirSync(this.fileLocation).filter(fileName => fileName.includes('.json')); - const books = files.map(fileName => { + let books = files.map(fileName => { const bookData = JSON.parse(fs.readFileSync(path.resolve(this.fileLocation, fileName), 'utf8')); if (bookData.hasOwnProperty('fileName')) return ''; @@ -220,6 +220,11 @@ Server.prototype.generateHomePage = function (req) { modal, }); }).join(''); + + if (books == '') { + books = '
The shelf is empty. Would you like to add a book?
'; + } + const body = '
' + books + '
'; return this.fillTemplate('./templates/htmlContainer.html', { title: 'View', @@ -230,7 +235,7 @@ Server.prototype.generateHomePage = function (req) { Server.prototype.generateHistoryPage = function (req) { const files = fs.readdirSync(this.historyLocation).filter(fileName => fileName.includes('.json')); - const history = files.map(fileName => { + let history = files.map(fileName => { const bookData = JSON.parse(fs.readFileSync(path.resolve(this.historyLocation, fileName), 'utf8')); const id = fileName.replace('.json', ''); const added = fecha.format(new Date(bookData.added), 'hh:mm:ssA on dddd MMMM Do, YYYY'); @@ -256,6 +261,11 @@ Server.prototype.generateHistoryPage = function (req) { modal, }); }).join(''); + + if (history == '') { + history = '
No books have been taken yet. Would you like to take a book?
'; + } + const body = '
' + history + '
'; return this.fillTemplate('./templates/htmlContainer.html', { title: 'History', diff --git a/templates/pages/uploadForm.html b/templates/pages/uploadForm.html index 45481c2..0604c8c 100644 --- a/templates/pages/uploadForm.html +++ b/templates/pages/uploadForm.html @@ -1,3 +1,13 @@ +

+ Give a Book +

+ +
+

+ Use this form to add a book to the library! +

+
+