-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAppShell.svelte
More file actions
366 lines (327 loc) · 10.5 KB
/
Copy pathAppShell.svelte
File metadata and controls
366 lines (327 loc) · 10.5 KB
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<script lang="ts">
// The authenticated app shell. Everything heavy (the IndexedDB data layer via
// appManager, the Sidebar, the feed stores, @mention polling) lives here so it
// can be code-split: the root layout imports this component dynamically, only
// once the user is authenticated. A logged-out visitor never downloads any of it.
import { browser } from '$app/environment';
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { onMount } from 'svelte';
import type { Snippet } from 'svelte';
import { auth } from '$lib/stores/auth.svelte';
import { appManager } from '$lib/stores/app.svelte';
import { viewTitleStore } from '$lib/stores/viewTitle.svelte';
import { sidebarStore } from '$lib/stores/sidebar.svelte';
import { preferences } from '$lib/stores/preferences.svelte';
import { keyboardStore } from '$lib/stores/keyboard.svelte';
import { notificationsStore } from '$lib/stores/notifications.svelte';
import { feedPath, FEEDS_PATH, SAVED_PATH } from '$lib/utils/viewNav';
import Sidebar from '$lib/components/Sidebar.svelte';
import KeyboardShortcutsModal from '$lib/components/KeyboardShortcutsModal.svelte';
import RefreshProgressBar from '$lib/components/RefreshProgressBar.svelte';
let { children }: { children: Snippet } = $props();
let pageTitle = $derived.by(() => {
const count = viewTitleStore.unreadCount;
const view = viewTitleStore.current;
const suffix = view ? `${view} - Skyreader` : 'Skyreader';
return count > 0 ? `(${count}) ${suffix}` : suffix;
});
// Helper function for feed cycling
function cycleFeeds(direction: 1 | -1) {
// Use sorted feed IDs from sidebar store (matches visual order)
const feedIds = sidebarStore.sortedFeedIds;
if (feedIds.length === 0) return;
const feedParam = $page.url.searchParams.get('feed');
const currentFeedId = feedParam ? parseInt(feedParam) : null;
if (currentFeedId === null) {
// Not on a feed view, go to first/last feed
const targetId = direction === 1 ? feedIds[0] : feedIds[feedIds.length - 1];
goto(feedPath(targetId));
return;
}
const currentIndex = feedIds.indexOf(currentFeedId);
if (currentIndex === -1) {
// Current feed not found in sorted list, go to first
goto(feedPath(feedIds[0]));
return;
}
const newIndex = (currentIndex + direction + feedIds.length) % feedIds.length;
goto(feedPath(feedIds[newIndex]));
}
// Initialize app data (cache-first hydrate + background refresh).
// The appManager has an internal phase guard so re-entry is a no-op.
// Skip on /dev/* — those routes are isolated visual harnesses that run on
// mock data and must not hit the API (so they're noise-free even when a dev
// session is present).
$effect(() => {
if (browser && !$page.url.pathname.startsWith('/dev')) {
appManager.initialize();
}
});
// Register global keyboard shortcuts on mount. keyboardStore.register() keys by
// shortcut, so re-registering on remount (e.g. logout → login) just overwrites.
// The auth conditions are redundant here (this component only mounts when
// authenticated) but kept to preserve the original gating semantics.
onMount(() => {
// View switching shortcuts
keyboardStore.register({
key: '0',
description: 'Home',
category: 'Views',
action: () => goto('/home'),
condition: () => auth.isAuthenticated,
});
keyboardStore.register({
key: '1',
description: 'Feeds',
category: 'Views',
action: () => goto(FEEDS_PATH),
condition: () => auth.isAuthenticated,
});
keyboardStore.register({
key: '2',
description: 'Saved',
category: 'Views',
action: () => goto(SAVED_PATH),
condition: () => auth.isAuthenticated,
});
keyboardStore.register({
key: '3',
description: 'Linkblog',
category: 'Views',
action: () => goto('/linkblog'),
condition: () => auth.isAuthenticated,
});
keyboardStore.register({
key: '4',
description: 'Highlights',
category: 'Views',
action: () => goto('/highlights'),
condition: () => auth.isAuthenticated,
});
keyboardStore.register({
key: '5',
description: 'Discover',
category: 'Views',
action: () => goto('/discover'),
condition: () => auth.isAuthenticated,
});
keyboardStore.register({
key: '6',
description: 'Manage Sources',
category: 'Views',
action: () => goto('/sources'),
condition: () => auth.isAuthenticated,
});
keyboardStore.register({
key: '7',
description: 'Settings',
category: 'Views',
action: () => goto('/settings'),
condition: () => auth.isAuthenticated,
});
// Feed/user cycling shortcuts
keyboardStore.register({
key: '[',
description: 'Previous feed',
category: 'Feed',
action: () => cycleFeeds(-1),
condition: () => auth.isAuthenticated,
});
keyboardStore.register({
key: ']',
description: 'Next feed',
category: 'Feed',
action: () => cycleFeeds(1),
condition: () => auth.isAuthenticated,
});
// Add menu shortcut (Add feed / @handle / Save URL / …)
keyboardStore.register({
key: 'a',
description: 'Toggle add menu',
category: 'Other',
action: () => sidebarStore.toggleAddMenu(),
condition: () => auth.isAuthenticated,
});
// Navigation switcher shortcut
keyboardStore.register({
key: '/',
description: 'Open switcher',
category: 'Navigation',
action: () => sidebarStore.toggleNavigationDropdown(),
condition: () => auth.isAuthenticated,
});
// Font size shortcuts (use resulting character from Shift+key)
keyboardStore.register({
key: '+',
shift: true,
description: 'Increase font size',
category: 'Article',
action: () => preferences.increaseFontSize(),
condition: () => auth.isAuthenticated,
});
keyboardStore.register({
key: '_',
shift: true,
description: 'Decrease font size',
category: 'Article',
action: () => preferences.decreaseFontSize(),
condition: () => auth.isAuthenticated,
});
keyboardStore.register({
key: ')',
shift: true,
description: 'Reset font size',
category: 'Article',
action: () => preferences.resetFontSize(),
condition: () => auth.isAuthenticated,
});
});
// Own the @mention badge-polling lifecycle, tied to this shell's lifetime. Both
// the desktop sidebar bell and the mobile bottom-bar bell are pure consumers; if
// either component owned start/stop, unmounting it (e.g. the mobile bar when the
// reader opens) would tear down polling for the other. start() is idempotent;
// stop() also clears per-account state, so it doubles as logout cleanup.
$effect(() => {
if (!browser) return;
notificationsStore.start();
return () => notificationsStore.stop();
});
// Apply article font preference to document
$effect(() => {
if (browser) {
document.documentElement.setAttribute('data-article-font', preferences.articleFont);
}
});
// Apply article font size preference to document
$effect(() => {
if (browser) {
document.documentElement.setAttribute('data-article-font-size', preferences.articleFontSize);
}
});
</script>
<svelte:window onkeydown={keyboardStore.handleKeydown} />
<svelte:head>
<title>{pageTitle}</title>
</svelte:head>
<KeyboardShortcutsModal />
<RefreshProgressBar />
<div class="app-container">
<Sidebar />
<button
class="mobile-menu-btn"
onclick={() => sidebarStore.toggleMobile()}
aria-label="Open menu"
>
☰
</button>
<div class="main-wrapper">
{#if auth.scopeUpgradeRequired}
<div class="scope-upgrade-banner">
<span
>Your session was created with outdated permissions. Please
<button
class="reauth-link"
onclick={async () => {
await auth.logout();
goto('/auth/login');
}}>log in again</button
> to restore full functionality.</span
>
<button class="dismiss-btn" onclick={() => auth.dismissScopeUpgrade()}>Dismiss</button>
</div>
{/if}
<main>
{@render children()}
</main>
</div>
</div>
<style>
/* Centered container for sidebar + main content */
.app-container {
display: flex;
max-width: 1200px;
width: 100%;
margin: 0 auto;
min-height: 100vh;
}
/* Main wrapper next to sidebar — z-index ensures fixed overlays
(e.g. fullscreen reader at z-index:100) stack above the sticky sidebar (z-index:50) */
.main-wrapper {
flex: 1;
min-height: 100vh;
display: flex;
flex-direction: column;
min-width: 0;
position: relative;
z-index: 51;
}
.mobile-menu-btn {
display: none;
position: fixed;
top: 1rem;
left: 1rem;
z-index: 45;
background: var(--color-bg);
border: 1px solid var(--color-border);
border-radius: 6px;
font-size: var(--text-2xl);
cursor: pointer;
padding: 0.5rem 0.75rem;
color: var(--color-text);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
main {
flex: 1;
width: 100%;
padding: 0.5rem;
}
.scope-upgrade-banner {
background: var(--color-warning-bg, #fff3cd);
color: var(--color-warning-text, #856404);
border-bottom: 1px solid var(--color-warning-border, #ffc107);
padding: 0.625rem 1rem;
display: flex;
align-items: center;
justify-content: center;
gap: 1rem;
font-size: var(--text-md);
text-align: center;
position: sticky;
top: 0;
z-index: 11;
}
.scope-upgrade-banner .reauth-link {
color: inherit;
font-weight: var(--weight-semibold);
text-decoration: underline;
background: none;
border: none;
padding: 0;
font: inherit;
font-size: inherit;
cursor: pointer;
}
.scope-upgrade-banner .dismiss-btn {
background: none;
border: 1px solid var(--color-warning-text, #856404);
color: inherit;
border-radius: 4px;
padding: 0.25rem 0.5rem;
cursor: pointer;
font-size: var(--text-xs);
white-space: nowrap;
}
.scope-upgrade-banner .dismiss-btn:hover {
background: rgba(0, 0, 0, 0.05);
}
@media (max-width: 1000px) {
.app-container {
flex-direction: column;
}
/* Hide floating hamburger - mobile header in page handles this now */
.mobile-menu-btn {
display: none;
}
}
</style>