Dashboard Auto Refresh ergaenzen
All checks were successful
CI / Build and Deploy (push) Successful in 2m51s
All checks were successful
CI / Build and Deploy (push) Successful in 2m51s
This commit is contained in:
@@ -280,6 +280,16 @@ function urlBase64ToUint8Array(value: string) {
|
|||||||
return Uint8Array.from([...rawData], (character) => character.charCodeAt(0));
|
return Uint8Array.from([...rawData], (character) => character.charCodeAt(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasFocusedEditableElement() {
|
||||||
|
const activeElement = document.activeElement;
|
||||||
|
|
||||||
|
if (!activeElement || activeElement === document.body) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Boolean(activeElement.closest('input, textarea, select, [contenteditable="true"]'));
|
||||||
|
}
|
||||||
|
|
||||||
export function DashboardShell({
|
export function DashboardShell({
|
||||||
viewer,
|
viewer,
|
||||||
workingGroups,
|
workingGroups,
|
||||||
@@ -393,11 +403,49 @@ export function DashboardShell({
|
|||||||
const [periodEditForm, setPeriodEditForm] = useState<PeriodEditFormState>(getPeriodEditDraft(currentPeriod));
|
const [periodEditForm, setPeriodEditForm] = useState<PeriodEditFormState>(getPeriodEditDraft(currentPeriod));
|
||||||
const [pushStatus, setPushStatus] = useState<"idle" | "enabled" | "blocked" | "unsupported">("idle");
|
const [pushStatus, setPushStatus] = useState<"idle" | "enabled" | "blocked" | "unsupported">("idle");
|
||||||
const handledDeepLinkRef = useRef<string | null>(null);
|
const handledDeepLinkRef = useRef<string | null>(null);
|
||||||
|
const busyRef = useRef(busy);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSelectedCurrentPeriodId(currentPeriodId);
|
setSelectedCurrentPeriodId(currentPeriodId);
|
||||||
setPeriodForm(getSuggestedPeriodDraft(currentPeriod));
|
setPeriodForm(getSuggestedPeriodDraft(currentPeriod));
|
||||||
}, [currentPeriod, currentPeriodId]);
|
}, [currentPeriod, currentPeriodId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
busyRef.current = busy;
|
||||||
|
}, [busy]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
function refreshIfSafe() {
|
||||||
|
if (document.visibilityState !== "visible" || busyRef.current || hasFocusedEditableElement()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleVisibilityChange() {
|
||||||
|
if (document.visibilityState === "visible") {
|
||||||
|
refreshIfSafe();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handlePageShow() {
|
||||||
|
refreshIfSafe();
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("visibilitychange", handleVisibilityChange);
|
||||||
|
window.addEventListener("focus", refreshIfSafe);
|
||||||
|
window.addEventListener("pageshow", handlePageShow);
|
||||||
|
|
||||||
|
const intervalId = window.setInterval(refreshIfSafe, 45_000);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.clearInterval(intervalId);
|
||||||
|
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
||||||
|
window.removeEventListener("focus", refreshIfSafe);
|
||||||
|
window.removeEventListener("pageshow", handlePageShow);
|
||||||
|
};
|
||||||
|
}, [router]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const selectedPeriod = accountingPeriods.find((period) => period.id === selectedCurrentPeriodId) ?? currentPeriod ?? null;
|
const selectedPeriod = accountingPeriods.find((period) => period.id === selectedCurrentPeriodId) ?? currentPeriod ?? null;
|
||||||
setPeriodEditForm(getPeriodEditDraft(selectedPeriod));
|
setPeriodEditForm(getPeriodEditDraft(selectedPeriod));
|
||||||
|
|||||||
Reference in New Issue
Block a user