overleaf/services/web/frontend/js/features/pdf-preview/components/pdf-preview-detached-root-safari-warning.js
Timothée Alby 32741c07e0 Merge pull request #8218 from overleaf/ta-pdf-detach-safari-warnings
PDF Detach Safari Warning

GitOrigin-RevId: e6f8942d8c8c141d887c44921a09716c4e4c85ae
2022-05-31 08:04:36 +00:00

38 lines
998 B
JavaScript

import { Alert } from 'react-bootstrap'
import { useTranslation } from 'react-i18next'
import usePersistedState from '../../../shared/hooks/use-persisted-state'
const BROWSER_IS_SAFARI =
navigator.userAgent &&
/.*Safari\/.*/.test(navigator.userAgent) &&
!/.*Chrome\/.*/.test(navigator.userAgent) &&
!/.*Chromium\/.*/.test(navigator.userAgent)
function PdfPreviewDetachedRootSafariWarning() {
const { t } = useTranslation()
const [hidePdfDetachSafariAlert, setHidePdfDetachSafariAlert] =
usePersistedState('hide-pdf-detach-safari-alert', false, true)
function handleDismiss() {
setHidePdfDetachSafariAlert(true)
}
if (!BROWSER_IS_SAFARI) {
return null
}
if (hidePdfDetachSafariAlert) {
return null
}
return (
<div className="global-alerts global-alerts-detached">
<Alert bsStyle="warning" onDismiss={handleDismiss}>
{t('pdf_detach_safari_issues')}
</Alert>
</div>
)
}
export default PdfPreviewDetachedRootSafariWarning