Merge pull request #19 from Salastil/development
Auto-refresh sidebar data so a stale tab picks up backend polls
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '../lib/styles/app.css';
|
import '../lib/styles/app.css';
|
||||||
|
import { onMount } from 'svelte';
|
||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores';
|
||||||
import { invalidateAll } from '$app/navigation';
|
import { invalidateAll, invalidate } from '$app/navigation';
|
||||||
import ThemeToggle from '$lib/components/ThemeToggle.svelte';
|
import ThemeToggle from '$lib/components/ThemeToggle.svelte';
|
||||||
import PrivateAccessModal from '$lib/components/PrivateAccessModal.svelte';
|
import PrivateAccessModal from '$lib/components/PrivateAccessModal.svelte';
|
||||||
import Sidebar from '$lib/components/sidebar/Sidebar.svelte';
|
import Sidebar from '$lib/components/sidebar/Sidebar.svelte';
|
||||||
@@ -13,6 +14,17 @@
|
|||||||
|
|
||||||
let showLoginModal = $state(false);
|
let showLoginModal = $state(false);
|
||||||
|
|
||||||
|
// Weather/Stocks/PoE2/Bookmarks are all backend-polled on their own cadence (15m-1h) —
|
||||||
|
// without this, a tab left open never sees those updates, since SvelteKit only re-runs
|
||||||
|
// a load() on navigation or explicit invalidation, never on a timer by itself. Scoped
|
||||||
|
// to this layout's own 'app:sidebar' dependency (see +layout.ts) rather than
|
||||||
|
// invalidateAll(), so it doesn't also re-run page-level loads — e.g. the home feed's
|
||||||
|
// own pagination state would otherwise reset every refresh.
|
||||||
|
onMount(() => {
|
||||||
|
const interval = setInterval(() => invalidate('app:sidebar'), 5 * 60_000);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
});
|
||||||
|
|
||||||
// Admin pages already use full page width for their own tab UI — the sidebar's utility
|
// Admin pages already use full page width for their own tab UI — the sidebar's utility
|
||||||
// widgets don't belong there, unlike every reader-facing route (home, category,
|
// widgets don't belong there, unlike every reader-facing route (home, category,
|
||||||
// article, event, more, weather).
|
// article, event, more, weather).
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ import type { LayoutLoad } from './$types';
|
|||||||
import { getCategories, getEvents, getWeather, getStocks, getBookmarks, getPoe2 } from '$lib/api';
|
import { getCategories, getEvents, getWeather, getStocks, getBookmarks, getPoe2 } from '$lib/api';
|
||||||
import { getPrivateAccessStatus } from '$lib/privateAccess';
|
import { getPrivateAccessStatus } from '$lib/privateAccess';
|
||||||
|
|
||||||
export const load: LayoutLoad = async ({ fetch, data }) => {
|
// Named so the layout can be re-fetched on its own (see +layout.svelte's periodic
|
||||||
|
// invalidate('app:sidebar')) without disturbing page-level loads — e.g. the home feed's
|
||||||
|
// own pagination state, which a blanket invalidateAll() would reset every refresh.
|
||||||
|
export const load: LayoutLoad = async ({ fetch, data, depends }) => {
|
||||||
|
depends('app:sidebar');
|
||||||
const [categories, events, privateAccess, weather, stocks, bookmarks, poe2] = await Promise.all([
|
const [categories, events, privateAccess, weather, stocks, bookmarks, poe2] = await Promise.all([
|
||||||
getCategories(fetch),
|
getCategories(fetch),
|
||||||
getEvents(fetch),
|
getEvents(fetch),
|
||||||
|
|||||||
Reference in New Issue
Block a user