import { useState, useEffect, useCallback } from 'react'; import { FormattedMessage } from 'react-intl'; import ButtonLayout from 'components/layout/ButtonLayout'; import useStore, { checkVersion } from 'store/version'; import { setItem } from 'lib/web'; import { REPO_URL, VERSION_CHECK } from 'lib/constants'; import Button from './Button'; import styles from './UpdateNotice.module.css'; export default function UpdateNotice() { const { latest, checked, hasUpdate, releaseUrl } = useStore(); const [dismissed, setDismissed] = useState(false); const updateCheck = useCallback(() => { setItem(VERSION_CHECK, { version: latest, time: Date.now() }); }, [latest]); function handleViewClick() { updateCheck(); setDismissed(true); location.href = releaseUrl || REPO_URL; } function handleDismissClick() { updateCheck(); setDismissed(true); } useEffect(() => { if (!checked) { checkVersion(); } }, []); if (!hasUpdate || dismissed) { return null; } return (