|
58 | 58 | return { user, usePreview, previewRole: selectedPreviewRole } |
59 | 59 | }) |
60 | 60 |
|
61 | | - /** |
62 | | - * Check if the current user (or preview role) has access to a roles array. |
63 | | - * Handles both normal access and admin preview mode. |
64 | | - */ |
65 | | - function checkAccess(roles?: Role[]): boolean { |
66 | | - const context = accessCheckContext |
67 | | - // Use preview function if admin has selected a different role to preview |
68 | | - if (context.usePreview) { |
69 | | - return hasRoleAccessForPreview(context.previewRole, roles) |
70 | | - } |
71 | | - return hasRoleAccess(context.user, roles) |
72 | | - } |
73 | | -
|
74 | 61 | // Get active tabs only (filtered by active and roles) |
75 | 62 | // Optimized: $derived.by() automatically memoizes - only recalculates when dependencies change |
76 | 63 | const activeTabs = $derived.by(() => { |
|
227 | 214 | // Calculate progress for each tab |
228 | 215 | function getTabProgress(tabId: TabId) { |
229 | 216 | const tabConfig = TUTORIALS_CONFIG[tabId] |
| 217 | + const context = accessCheckContext |
230 | 218 | |
231 | 219 | // Get all tutorial indexes for this tab (filtered by role) |
232 | 220 | const indexes: number[] = [] |
233 | 221 | for (const tutorial of tabConfig.tutorials) { |
234 | 222 | if (tutorial.active === false || tutorial.index === undefined) continue |
235 | | - if (!checkAccess(tutorial.roles)) continue |
| 223 | + // Use context directly to check access |
| 224 | + if (context.usePreview) { |
| 225 | + if (!hasRoleAccessForPreview(context.previewRole, tutorial.roles)) continue |
| 226 | + } else { |
| 227 | + if (!hasRoleAccess(context.user, tutorial.roles)) continue |
| 228 | + } |
236 | 229 | indexes.push(tutorial.index) |
237 | 230 | } |
238 | 231 | |
|
0 commit comments