mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-29 12:01:32 +02:00
* Reapply "Increase the length of unsaved doc time before the editor is locked (#23431)" This reverts commit d0efca398e59ca488c530ee9ec5ca76f29843679. * Use pendingOpCreatedAt if inflightOpCreatedAt isn't set GitOrigin-RevId: b3301d7cc1554215a4ba569537bd47beeefde20f
47 lines
1.2 KiB
TypeScript
47 lines
1.2 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'
|
|
|
|
const MAX_UNSAVED_ALERT_SECONDS = 15
|
|
|
|
export const UnsavedDocsAlert: FC<{ unsavedDocs: Map<string, number> }> = ({
|
|
unsavedDocs,
|
|
}) => (
|
|
<>
|
|
{[...unsavedDocs.entries()].map(
|
|
([docId, seconds]) =>
|
|
seconds >= MAX_UNSAVED_ALERT_SECONDS && (
|
|
<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,
|
|
})}
|
|
/>
|
|
)
|
|
}
|