-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.js
More file actions
35 lines (28 loc) · 988 Bytes
/
render.js
File metadata and controls
35 lines (28 loc) · 988 Bytes
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
'use strict'
const { ipcRenderer } = require('electron');
// delete book by its text value ( used below in event listener)
const deleteBook = (e) => {
ipcRenderer.send('delete-book', e.target.textContent);
}
// on receive books
ipcRenderer.on('displayBook', (event, books) => {
console.log("render books" + books)
// get the todoList ul
const bookList = document.getElementById('bookList')
console.log("html: " + bookList)
// create html string
const bookItems = books.reduce((html, book) => {
html += `<tr>
<td class="book-item">${book.title}</td>
<td>${book.author}</td>
<td>${book.genre}</td>
<td>${book.url}</td></tr>`
return html
}, '');
// set list html to the todo items
bookList.innerHTML = bookItems
// add click handlers to delete the clicked todo
bookList.querySelectorAll('.book-item').forEach(item => {
item.addEventListener('click', deleteBook)
})
})