2023-12-14 06:06:36 -05:00
|
|
|
import { FC, useMemo } from 'react'
|
|
|
|
import { useFileTreePathContext } from '@/features/file-tree/contexts/file-tree-path'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
2024-10-11 05:23:33 -04:00
|
|
|
import OLNotification from '@/features/ui/components/ol/ol-notification'
|
2023-12-14 06:06:36 -05:00
|
|
|
|
|
|
|
export const UnsavedDocsAlert: FC<{ unsavedDocs: Map<string, number> }> = ({
|
|
|
|
unsavedDocs,
|
|
|
|
}) => (
|
2024-01-03 06:12:50 -05:00
|
|
|
<>
|
2023-12-14 06:06:36 -05:00
|
|
|
{[...unsavedDocs.entries()].map(
|
|
|
|
([docId, seconds]) =>
|
|
|
|
seconds > 8 && (
|
|
|
|
<UnsavedDocAlert key={docId} docId={docId} seconds={seconds} />
|
|
|
|
)
|
|
|
|
)}
|
2024-01-03 06:12:50 -05:00
|
|
|
</>
|
2023-12-14 06:06:36 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
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 (
|
2024-10-11 05:23:33 -04:00
|
|
|
<OLNotification
|
|
|
|
type="warning"
|
|
|
|
content={t('saving_notification_with_seconds', {
|
2023-12-14 06:06:36 -05:00
|
|
|
docname: doc.entity.name,
|
|
|
|
seconds,
|
|
|
|
})}
|
2024-10-11 05:23:33 -04:00
|
|
|
/>
|
2023-12-14 06:06:36 -05:00
|
|
|
)
|
|
|
|
}
|