| 33 | }) |
| 34 | |
| 35 | const handleSetRead = title => { |
| 36 | if (title) { |
| 37 | const read = JSON.parse(window.localStorage.getItem('read')) || [] |
| 38 | const isFavorite = read.includes(title) |
| 39 | if (isFavorite) { |
| 40 | read.splice(read.indexOf(title), 1) |
| 41 | setIsRead(false) |
| 42 | } else { |
| 43 | read.push(title) |
| 44 | setIsRead(true) |
| 45 | } |
| 46 | |
| 47 | const newValue = JSON.stringify(read) |
| 48 | window.localStorage.setItem('read', newValue) |
| 49 | window.dispatchEvent( |
| 50 | new CustomEvent('local-storage', { |
| 51 | detail: { key: 'read', newValue }, |
| 52 | }) |
| 53 | ) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return ( |
| 58 | <button |