Issues (324)

public/js/main.js (3 issues)

1
const formToJson = form => {
0 ignored issues
show
The constant formToJson seems to be never used. Consider removing it.
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
The constant toggleNotifications seems to be never used. Consider removing it.
Loading history...
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
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
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
};