Files
overleaf-cep/services/web/frontend/js/features/ide-react/components/unsaved-docs/unsaved-docs-alert.tsx
T
Rebeka Dekany e2a8bf768b Merge intermediate component wrappers into OL-prefixed components (#34996)
* Merge intermediate component wrappers into OL-prefixed components

* Replace all intermediate wrapper consumers with OL-prefixed components directly

* Fix jsx/js files still importing deleted shim components

* Remove duplicate OLNotification imports left by first pass

* Rename OLTagIcon to TagIcon, remove OL prefix

* Rename OLDropdownMenuItem to DropdownMenuItem, remove OL prefix

* Remove OLNotification, use Notification directly

* Move Notification to the main shared component folder

* Update tag-icon import path out of ol/

* Move TagIcon to the main shared component folder

* Update dropdown-menu-item import path out of ol/

* Move DropdownMenuItem to the main shared component folder

* Fix dropdown-menu-item import path to dropdown/ subfolder

* Remove BS5 alias prefixes from shared components

* Restore notification-list wrapper in Notification component

* Add translation for loading button

* Remove redundant import aliasing

* Resolve conflicts

* Restore notification container `notification-list`

GitOrigin-RevId: 24a5af18599a3e02ac6fd61c09cf5a49ef6e0020
2026-09-17 11:19:34 +00:00

64 lines
1.7 KiB
TypeScript

import { FC, useEffect, useMemo, useRef } from 'react'
import { useFileTreePathContext } from '@/features/file-tree/contexts/file-tree-path'
import { useTranslation } from 'react-i18next'
import Notification from '@/shared/components/notification'
import { sendMB } from '@/infrastructure/event-tracking'
import { useConnectionContext } from '@/features/ide-react/context/connection-context'
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 { socket } = useConnectionContext()
const { t } = useTranslation()
const recordedRef = useRef(false)
useEffect(() => {
if (!recordedRef.current) {
recordedRef.current = true
sendMB('unsaved-doc-alert-shown', {
docId,
transport: socket.socket.transport?.name,
})
}
}, [docId, socket])
const doc = useMemo(() => {
const path = pathInFolder(docId)
return path ? findEntityByPath(path) : null
}, [docId, findEntityByPath, pathInFolder])
if (!doc) {
return null
}
return (
<div className="notification-list">
<Notification
type="warning"
content={t('saving_notification_with_seconds', {
docname: doc.entity.name,
seconds,
})}
/>
</div>
)
}