Refactor alias handling in incident and live pages
- Updated the `load` and `connectStream` functions to accept an optional `aliasOverride` parameter, allowing for more flexible alias filtering. - Enhanced the logic for determining the active alias based on URL parameters, ensuring accurate data retrieval and stream connections. - Improved consistency in alias management across both incident and live pages, streamlining user experience.
This commit is contained in:
@@ -114,12 +114,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function load() {
|
async function load(aliasOverride?: string) {
|
||||||
loading = true;
|
loading = true;
|
||||||
err = null;
|
err = null;
|
||||||
try {
|
try {
|
||||||
|
const activeAlias = aliasOverride ?? aliasFilter;
|
||||||
const env = await fetchAggIncidents({
|
const env = await fetchAggIncidents({
|
||||||
aliases: aliasFilter === 'all' ? undefined : aliasFilter
|
aliases: activeAlias === 'all' ? undefined : activeAlias
|
||||||
});
|
});
|
||||||
data = env.data ?? null;
|
data = env.data ?? null;
|
||||||
partial = !!env.partial;
|
partial = !!env.partial;
|
||||||
@@ -151,11 +152,12 @@
|
|||||||
$effect(() => {
|
$effect(() => {
|
||||||
queryKey;
|
queryKey;
|
||||||
if (typeof window === 'undefined') return;
|
if (typeof window === 'undefined') return;
|
||||||
aliasFilter = parseAliasFilter(page.url.searchParams.get('aliases'));
|
const nextAlias = parseAliasFilter(page.url.searchParams.get('aliases'));
|
||||||
|
aliasFilter = nextAlias;
|
||||||
refreshSeconds = parseRefresh(page.url.searchParams.get('refresh'));
|
refreshSeconds = parseRefresh(page.url.searchParams.get('refresh'));
|
||||||
refreshInput = String(refreshSeconds);
|
refreshInput = String(refreshSeconds);
|
||||||
restartPolling();
|
restartPolling();
|
||||||
void load();
|
void load(nextAlias);
|
||||||
});
|
});
|
||||||
|
|
||||||
let staleSeconds = $derived.by(() =>
|
let staleSeconds = $derived.by(() =>
|
||||||
|
|||||||
@@ -151,11 +151,12 @@
|
|||||||
}, 250);
|
}, 250);
|
||||||
}
|
}
|
||||||
|
|
||||||
function connectStream() {
|
function connectStream(aliasOverride?: string) {
|
||||||
closeStream();
|
closeStream();
|
||||||
clearReconnectTimer();
|
clearReconnectTimer();
|
||||||
err = null;
|
err = null;
|
||||||
const aliasesParam = aliasFilter === 'all' ? undefined : aliasFilter;
|
const activeAlias = aliasOverride ?? aliasFilter;
|
||||||
|
const aliasesParam = activeAlias === 'all' ? undefined : activeAlias;
|
||||||
const url = liveEventsUrl({ aliases: aliasesParam });
|
const url = liveEventsUrl({ aliases: aliasesParam });
|
||||||
const next = new EventSource(url);
|
const next = new EventSource(url);
|
||||||
next.onopen = () => {
|
next.onopen = () => {
|
||||||
@@ -214,8 +215,9 @@
|
|||||||
$effect(() => {
|
$effect(() => {
|
||||||
queryKey;
|
queryKey;
|
||||||
if (typeof window === 'undefined') return;
|
if (typeof window === 'undefined') return;
|
||||||
aliasFilter = parseAliasFilter(page.url.searchParams.get('aliases'));
|
const nextAlias = parseAliasFilter(page.url.searchParams.get('aliases'));
|
||||||
connectStream();
|
aliasFilter = nextAlias;
|
||||||
|
connectStream(nextAlias);
|
||||||
});
|
});
|
||||||
|
|
||||||
let staleSeconds = $derived.by(() =>
|
let staleSeconds = $derived.by(() =>
|
||||||
|
|||||||
Reference in New Issue
Block a user