Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"EnableAddSelfToSystemuser": true,
"EnableDialogportenDialogLookup": false,
"UseConnectionsForAgentSystemuser": true,
"EnableMaskinportenAdministration": true
"EnableMaskinportenAdministration": true,
"RouteChangeReporteeViaAltinn2": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@
"EnableAddSelfToSystemuser": true,
"EnableDialogportenDialogLookup": true,
"EnableMaskinportenAdministration": true,
"RouteChangeReporteeViaAltinn2": true
"RouteChangeReporteeViaAltinn2": false
}
}
2 changes: 1 addition & 1 deletion src/components/ReloadAlert/ReloadAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import classes from './ReloadAlert.module.css';
export const ReloadAlert = () => {
const { t } = useTranslation();

const displayAlert = useCookieListener('AltinnPartyId');
const displayAlert = useCookieListener('AltinnPartyId', 2000, 2000);

return (
displayAlert && (
Expand Down
15 changes: 11 additions & 4 deletions src/resources/Cookie/CookieMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,30 @@ export function getCookie(cname: string) {
* Detects changes in a given cookie by polling it with the given interval
* @param cookieName The name of the cookie to be checked
* @param interval The interval in which to poll the cookie (given in milliseconds)
* @param delayResponse The delay in milliseconds before signalling that the cookie has changed. Defaults to 0ms (no delay).
* @returns `true` if the cookie has been changed from it's original value, `false` otherwise.
*/
export const useCookieListener = (cookieName: string, interval = 2000) => {
export const useCookieListener = (cookieName: string, interval = 2000, delayResponse = 0) => {
const [cookieValue, setCookieValue] = useState(getCookie(cookieName));
const [cookieChanged, setCookieChanged] = useState(false);

useEffect(() => {
let delayTimeout: ReturnType<typeof setTimeout> | undefined;

const checkCookie = setInterval(() => {
const currentCookie = getCookie(cookieName);
if (currentCookie !== cookieValue) {
setCookieValue(currentCookie);
setCookieChanged(true);
clearTimeout(delayTimeout);
delayTimeout = setTimeout(() => setCookieChanged(true), delayResponse);
}
}, interval); // Check every interval

return () => clearInterval(checkCookie);
}, [cookieName, interval]);
return () => {
clearInterval(checkCookie);
clearTimeout(delayTimeout);
};
}, [cookieName, interval, delayResponse]);
Comment thread
allinox marked this conversation as resolved.

return cookieChanged;
};
Loading