Files
overleaf-cep/services/web/frontend/js/features/ide-react/components/unsaved-docs/unsaved-docs-alert.tsx
T
Alf Eaton 432bbe0db8 Merge pull request #23714 from overleaf/ae-revert-unsaved-docs
Revert "Increase the length of unsaved doc time before the editor is locked"

GitOrigin-RevId: 0f2d257a55ebc3353ded2b10d505bfdb2e85f402
2025-02-20 09:05:53 +00:00

45 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,
})}
/>
)
}