fix autofresh

Signed-off-by: Ronni Skansing <rskansing@gmail.com>
This commit is contained in:
Ronni Skansing
2026-02-19 01:46:56 +01:00
parent ae00679886
commit 0b71c3af2b
4 changed files with 27 additions and 16 deletions
+15 -12
View File
@@ -19,19 +19,15 @@
});
let intervalId;
let settings;
$: {
if (pageId) {
settings = getPageAutoRefresh(pageId);
autoRefreshStore.set(settings);
}
}
let initialized = false;
function handleIntervalChange(optKey) {
const value = Number(options.byKey(optKey));
autoRefreshStore.setEnabled(value > 0);
autoRefreshStore.setInterval(value);
// batch the update to prevent multiple reactive triggers
autoRefreshStore.set({
enabled: value > 0,
interval: value
});
}
const startAutoRefresh = () => {
@@ -52,7 +48,8 @@
}
};
$: if ($autoRefreshStore) {
// reactive statement to handle store changes and persist to localStorage
$: if (initialized && $autoRefreshStore) {
startAutoRefresh();
if (pageId) {
setPageAutoRefresh(pageId, $autoRefreshStore);
@@ -60,7 +57,13 @@
}
onMount(() => {
startAutoRefresh();
// load saved settings from localStorage only once on mount
if (pageId) {
const settings = getPageAutoRefresh(pageId);
autoRefreshStore.set(settings);
}
// mark as initialized to enable reactive statement which will start auto-refresh
initialized = true;
});
onDestroy(() => {
@@ -111,6 +111,8 @@
const closeDropdown = () => {
showDropdown = false;
hasTyped = false; // Reset typing flag when closing
// only clear activeFormElement if it was set by this component
activeFormElement.update((current) => (current === id ? null : current));
};
// Update dropdown position for fixed positioning
+5 -2
View File
@@ -58,8 +58,11 @@
const handleAutoRefreshChange = (optKey) => {
const value = Number(autoRefreshOptions.byKey(optKey));
autoRefreshStore.setEnabled(value > 0);
autoRefreshStore.setInterval(value);
// batch the update to prevent multiple reactive triggers
autoRefreshStore.set({
enabled: value > 0,
interval: value
});
setPageAutoRefresh('dashboard', $autoRefreshStore);
startAutoRefresh();
};
@@ -56,8 +56,11 @@
const handleAutoRefreshChange = (optKey) => {
const value = Number(autoRefreshOptions.byKey(optKey));
autoRefreshStore.setEnabled(value > 0);
autoRefreshStore.setInterval(value);
// batch the update to prevent multiple reactive triggers
autoRefreshStore.set({
enabled: value > 0,
interval: value
});
setPageAutoRefresh('dashboard-events', $autoRefreshStore);
};