Jake Vanderwerf
2026-05-12 c32ed859f4abd1591c882f4f2a6ee16b1ec275e2
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
class UserNotificationManager {
    constructor(){
        this.resetFilters();
        this.activeTab = 'all';
        this.isLoading = false;
        this.loading = window.jvbLoading;
 
        this.container = document.querySelector('.container');
        this.grid = this.container.querySelector('.notifications-list');
 
 
 
        this.tabs = new window.jvbTabs(this.container, {
            all: () => {
                this.resetFilters();
                this.activeTab = 'all';
                this.loadNotifications();
            },
            favourite: () =>{
                this.resetFilters();
                this.activeTab = 'favourite';
                this.filters.content = 'favourite';
                this.loadNotifications();
            },
            artist: () =>{
                this.resetFilters();
                this.activeTab = 'artist';
                this.filters.content = 'artist';
                this.loadNotifications();
            },
            shop: () =>{
                this.resetFilters();
                this.activeTab = 'shop';
                this.filters.content = 'shop';
                this.loadNotifications();
            },
            event: () =>{
                this.resetFilters();
                this.activeTab = 'favourite';
                this.filters.content = 'favourite';
                this.loadNotifications();
            },
            news: () =>{
                this.resetFilters();
                this.activeTab = 'news';
                this.filters.content = 'news';
                this.loadNotifications();
            },
            system: () =>{
                this.resetFilters();
                this.activeTab = 'system';
                this.filters.content = 'system';
                this.loadNotifications();
            },
 
        });
 
        this.loadNotifications();
    }
 
    resetFilters(){
        this.filters = {
            content: 'all',
            date: ''
        };
        this.hasMore = true;
    }
 
    async loadNotifications(reset = true) {
 
        if(this.isLoading || !this.hasMore) return;
 
        try {
            this.isLoading = true;
            this.loading.show();
 
            if(reset){
                this.filters.page = 1;
                this.grid.classList.remove('empty');
            }
            const params = this.buildFilters();
            console.log(this.filters);
            console.log('Reset? ',this.reset);
            const data = await this.cache.fetchWithCache(
                `${jvbSettings.api}notifications?${params.toString()}`,
                {
                    method: 'GET',
                    headers: {
                        'X-WP-Nonce': window.auth.getNonce(),
                        'X-Action-Nonce': jvbAdmin.nonce,
                    }
                },{
                    context: 'admin',
                    forceRefresh: true
                }
            );
 
            console.log(data);
 
            // // Process and render the favourites
            // this.renderItems(data.items || [], this.filters.page > 1);
            // [
            //  this.hasMore,
            //  this.totalItems,
            //  this.maxPages
            // ] = [
            //  data.has_more,
            //  data.total_items,
            //  data.total_pages
            // ];
            // if(this.hasMore){
            //  this.filters.page++;
            // }
            //
            // this.setupInfiniteScroll();
 
            return data;
        } catch (error) {
            this.handleError(error, 'loading notifications');
            throw error;
        } finally {
            this.isLoading = false;
            this.loading.hide();
        }
 
    }
 
    buildFilters(){
        //Clone to avoid modifying original
        const filters = JSON.parse(JSON.stringify(this.filters));
 
        let temp = {};
        for(var[name, value] of Object.entries(filters)){
            if(value !== false && value !== null){
                temp[name] = value;
            }
        }
        temp.context = 'admin';
        temp.user = window.auth.getUser();
 
        return new URLSearchParams(temp);
    }
}
 
 
document.addEventListener('DOMContentLoaded', () => {
    window.notificationsDash = new UserNotificationManager();
    console.log(jvbSettings);
});