import { useEffect, useRef } from "react"; import { useTranslation } from "react-i18next"; import { accountSwitchNotice } from "./entryUrl"; import { notify } from "./notifications"; /** Say, once per load, what the entry URL tells the account signed in here about a switch of * account (`accountSwitchNotice`): a sign-in as someone else the server refused, or a tab that * reloaded because another account signed in under it. It waits for the account — until it is * known there is no one signed in to say it to. */ export function useAccountSwitchNotice(signedIn: boolean): void { const { t } = useTranslation(); const said = useRef(false); useEffect(() => { if (!signedIn || said.current) return; said.current = true; const notice = accountSwitchNotice(); if (notice) notify({ level: notice.level, message: t(notice.key, notice.values) }); }, [signedIn, t]); }