mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-21 09:52:38 +00:00
8dbf2b64f8
* Notify about unsaved changes * Move system message components and types to shared folder * Add system messages component GitOrigin-RevId: ab81a24888847bd9a8a390fd1af6b58f471f7a4b
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { FC, useMemo } from 'react'
|
|
import { useFileTreePathContext } from '@/features/file-tree/contexts/file-tree-path'
|
|
import { Alert } from 'react-bootstrap'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
export const UnsavedDocsAlert: FC<{ unsavedDocs: Map<string, number> }> = ({
|
|
unsavedDocs,
|
|
}) => (
|
|
<div className="global-alerts">
|
|
{[...unsavedDocs.entries()].map(
|
|
([docId, seconds]) =>
|
|
seconds > 8 && (
|
|
<UnsavedDocAlert key={docId} docId={docId} seconds={seconds} />
|
|
)
|
|
)}
|
|
</div>
|
|
)
|
|
|
|
const UnsavedDocAlert: FC<{ docId: string; seconds: number }> = ({
|
|
docId,
|
|
seconds,
|
|
}) => {
|
|
const { pathInFolder, findEntityByPath } = useFileTreePathContext()
|
|
const { t } = useTranslation()
|
|
|
|
const doc = useMemo(() => {
|
|
const path = pathInFolder(docId)
|
|
return path ? findEntityByPath(path) : null
|
|
}, [docId, findEntityByPath, pathInFolder])
|
|
|
|
if (!doc) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<Alert bsStyle="warning" bsSize="small">
|
|
{t('saving_notification_with_seconds', {
|
|
docname: doc.entity.name,
|
|
seconds,
|
|
})}
|
|
</Alert>
|
|
)
|
|
}
|