mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 09:07:49 -05:00
5b6bbcb73c
[web] Migrate notifications and error boundaries on the editor page GitOrigin-RevId: c195ecf0dd9e38ec8326c823174e559e1f192ce1
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { FC, useMemo } from 'react'
|
|
import { useFileTreePathContext } from '@/features/file-tree/contexts/file-tree-path'
|
|
import { useTranslation } from 'react-i18next'
|
|
import OLNotification from '@/features/ui/components/ol/ol-notification'
|
|
|
|
export const UnsavedDocsAlert: FC<{ unsavedDocs: Map<string, number> }> = ({
|
|
unsavedDocs,
|
|
}) => (
|
|
<>
|
|
{[...unsavedDocs.entries()].map(
|
|
([docId, seconds]) =>
|
|
seconds > 8 && (
|
|
<UnsavedDocAlert key={docId} docId={docId} seconds={seconds} />
|
|
)
|
|
)}
|
|
</>
|
|
)
|
|
|
|
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 (
|
|
<OLNotification
|
|
type="warning"
|
|
content={t('saving_notification_with_seconds', {
|
|
docname: doc.entity.name,
|
|
seconds,
|
|
})}
|
|
/>
|
|
)
|
|
}
|