CraftCamp /
official-website
| 1 | const formToJson = form => { |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 2 | let jsonObject = {}; |
||
| 3 | |||
| 4 | for (const [key, value] of form.entries()) { |
||
| 5 | jsonObject[key] = value; |
||
| 6 | } |
||
| 7 | return JSON.stringify(jsonObject); |
||
| 8 | }; |
||
| 9 | |||
| 10 | const toggleNotifications = () => { |
||
|
0 ignored issues
–
show
|
|||
| 11 | let notificationContainer = document.querySelector('#notifications'); |
||
| 12 | notificationContainer.classList.toggle('show'); |
||
| 13 | if (!notificationContainer.classList.contains('show')) { |
||
| 14 | return; |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 15 | } |
||
| 16 | |||
| 17 | let notifications = document.querySelectorAll('#notifications > div.unread'); |
||
| 18 | let ids = []; |
||
| 19 | |||
| 20 | for (let notification of notifications) { |
||
| 21 | notification.classList.remove('unread'); |
||
| 22 | ids.push(notification.getAttribute('data-id')); |
||
| 23 | } |
||
| 24 | return fetch('/users/me/notifications/read', { |
||
| 25 | method: 'PATCH', |
||
| 26 | headers: { |
||
| 27 | 'Content-Type': 'application/json' |
||
| 28 | }, |
||
| 29 | body: JSON.stringify({ ids: ids }), |
||
| 30 | credentials: 'include' |
||
| 31 | }).then(response => { |
||
| 32 | if (response.ok) { |
||
| 33 | let counter = document.querySelector('#notifications-counter'); |
||
| 34 | counter.querySelector('svg').style.color = 'black'; |
||
| 35 | counter.removeChild(counter.querySelector('span')); |
||
| 36 | } |
||
| 37 | }); |
||
| 38 | }; |