Jake Vanderwerf
2025-09-30 2cb91676044ecd0abd9c45b4835abb8b0d042312
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
class DashboardNavigator {
    constructor() {
        this.currentPage = '';
        this.a11y = window.jvbA11y;
        this.mainContent = document.querySelector('main .replace');
        this.loadingManager = window.jvbLoading;
 
        this.cache = JSON.parse(localStorage.getItem('dashboard-cache') || '{}');
        this.cacheTimeout = 5 * 60 * 1000;
 
        // Get current page from URL on initial load
        const path = window.location.pathname;
        const dashPath = path.split('/dash/')[1];
        this.currentPage = dashPath ? dashPath.replace('/', '') : '';
 
        // Initialize current page if accessing directly
        if (this.currentPage) {
            this.initPageContent(this.currentPage);
        }
 
        this.initNavigation();
 
    }
 
    initNavigation() {
        // Update currentPage from URL
        const path = window.location.pathname;
        const dashPath = path.split('/dash/')[1];
        this.currentPage = dashPath ? dashPath.replace('/', '') : '';
 
        // Update initial nav state
        this.updateNavState(this.currentPage);
 
        // Listen for popstate (browser back/forward)
        window.addEventListener('popstate', (e) => {
            const page = e.state?.page || '';
            this.navigateTo(page, true);
        });
 
        // Add click handlers to dashboard links
        document.querySelectorAll('a[data-dash]').forEach(link => {
            link.addEventListener('click', (e) => {
                console.log('Clicked');
                e.preventDefault();
                this.navigateTo(link.dataset.page);
            });
        });
    }
 
    updateNavState(page) {
        const nav = document.querySelector('.dashboard-footer nav');
        if (!nav) return;
 
        nav.querySelectorAll('a').forEach(link => {
            const linkPage = link.dataset.page;
            link.parentElement.classList.toggle('current', linkPage === page);
            if (linkPage === page) {
                link.setAttribute('aria-current', 'page');
            } else {
                link.removeAttribute('aria-current');
            }
        });
    }
 
    getCachedContent(page) {
        const cached = this.cache[page];
        if (!cached) return null;
 
        // Check if cache is expired
        if (Date.now() - cached.timestamp > this.cacheTimeout) {
            delete this.cache[page];
            localStorage.setItem('dashboard-cache', JSON.stringify(this.cache));
            return null;
        }
 
        return cached.content;
    }
 
    setCachedContent(page, content) {
        if (!page || !content) return;
 
        this.cache[page] = {
            content: content,
            timestamp: Date.now()
        };
 
        localStorage.setItem('dashboard-cache', JSON.stringify(this.cache));
    }
 
    async navigateTo(page, fromPopState = false) {
        try {
            if (page === 'dash') {
                page = '';
            }
            if (page === this.currentPage) return;
 
            // Update URL if not from browser navigation
            if (!fromPopState) {
                const newPath = page ? `/dash/${page}/` : '/dash';
                history.pushState({ page }, '', newPath);
            }
 
            // Cache current page content before navigating
            const currentContent = this.mainContent?.innerHTML;
            if (currentContent) {
                this.setCachedContent(this.currentPage, currentContent);
            }
 
            // Check cache for requested page
            const cachedContent = this.getCachedContent(page);
            if (cachedContent) {
                this.mainContent.innerHTML = cachedContent;
                this.currentPage = page;
                this.updateNavState(page);
                this.initPageContent(page);
                return;
            }
 
 
            // If not cached, follow the link normally
            window.location.href = page ? `/dash/${page}/` : '/dash';
 
        } catch (error) {
            console.error('Navigation error:', error);
            if (this.loadingManager) {
                this.loadingManager.showError(error.message || 'Navigation failed');
            }
        } finally {
            this.a11y.announce(`Currently on ${page} dashboard page.`);
        }
    }
 
    updateContent(data) {
        this.mainContent.innerHTML = data.content;
        document.title = `${data.title} - edmonton.ink Dashboard`;
 
        if (this.currentPage) {
            this.initPageContent(this.currentPage);
        }
    }
 
    initPageContent(page) {
        console.log(page);
        switch (page) {
            case 'settings':
                this.initNorthehSettingsPage();
                break;
            case 'bio':
                this.initBioPage();
                break;
            case 'favourites':
                new window.favouritesManager();
                break;
            case 'shop':
                this.initShopPage();
                break;
            case 'news':
                new window.newsManager();
                break;
            case 'events':
                new window.crud({
                    content: 'event'
                });
                break;
            default:
                // new window.crud({content: page});
                break;
        }
    }
 
 
    initBioPage() {
        const form = document.querySelector('form');
        if(!form){
            return;
        }
        console.log(jvbSettings, 'jvbSettings');
 
        // Initialize form manager with selectors
        new window.formManager(form, {
            loadingManager: window.jvbLoading,
            objectId: jvbSettings.currentUser.artistID,
            highlights: {
                style: {
                    max: 3,
                    name: 'jvb_top_styles',
                    label: 'Highlight Styles',
                    description: 'Select up to 3 styles to highlight'
                }
                // Can add more highlight configurations for other taxonomies as needed
                // theme: {
                //     max: 5,
                //     name: 'jvb_featured_themes',
                //     label: 'Featured Themes',
                //     description: 'Select up to 5 themes to highlight'
                // }
            }
        });
    }
 
    initNorthehSettingsPage() {
        new window.jvbTabs(document.querySelector('.replace'));
        // window.jvbForm.addForm(document.querySelector('form#menu-sections'));
        // window.jvbForm.addForm(document.querySelector('form#hours'));
    }
    initSettingsPage() {
        const form = document.querySelector('form');
 
        // Initialize form manager with selectors
        window.jvbForm.addForm(form, {
            content: 'artist',
            onSave: (data) => {
                if (Object.hasOwn(data, 'menu_section_order')) {
                    data['menu_section_order'] = JSON.stringify(data['menu_section_order']);
                }
                data.user = jvbSettings.currentUser;
                window.jvbQueue.addToQueue({
                    type: 'user_settings',
                    data: data,
                });
            }
        });
 
    }
    initShopPage() {
        const form = document.querySelector('form');
        if (!form) return;
 
        new window.jvbShopManager();
    }
 
 
    clearCache() {
        this.cache = {};
    }
}
 
document.addEventListener('DOMContentLoaded', ()=>{
    window.dashboardNavigator = new DashboardNavigator();
});