Merge pull request #35725 from overleaf/ds-unable-to-sync-modal

[WEB] adds unable-to-sync modal for intermittent connection improvements

GitOrigin-RevId: 4cd85cf742cb3f36cc0c97f83bdeab09bb6f7c53
This commit is contained in:
Davinder Singh
2026-09-17 11:36:54 +00:00
committed by Copybot
parent 02d36687cd
commit e0a2af4bf6
6 changed files with 108 additions and 9 deletions
@@ -0,0 +1,53 @@
import { useTranslation } from 'react-i18next'
import { memo, useCallback } from 'react'
import OLButton from '@/shared/components/ol/ol-button'
import {
OLModal,
OLModalBody,
OLModalFooter,
OLModalHeader,
OLModalTitle,
} from '@/shared/components/ol/ol-modal'
import { downloadFileContent } from '@/utils/download-file'
export type UnableToSyncModalProps = {
editorContent: string
docName: string | null
show: boolean
onHide: () => void
}
function UnableToSyncModal({
editorContent,
docName,
show,
onHide,
}: UnableToSyncModalProps) {
const { t } = useTranslation()
const handleDownload = useCallback(() => {
downloadFileContent(editorContent, docName ?? 'document.txt')
}, [editorContent, docName])
return (
<OLModal
show={show}
onHide={onHide}
backdrop="static"
keyboard={false}
centered
>
<OLModalHeader>
<OLModalTitle>{t('your_offline_edits_couldnt_be_synced')}</OLModalTitle>
</OLModalHeader>
<OLModalBody>{t('offline_edits_couldnt_be_synced_detail')}</OLModalBody>
<OLModalFooter>
<OLButton variant="primary" onClick={handleDownload}>
{t('download_local_version')}
</OLButton>
</OLModalFooter>
</OLModal>
)
}
export default memo(UnableToSyncModal)
@@ -12,6 +12,9 @@ import GenericMessageModal, {
import OutOfSyncModal, {
OutOfSyncModalProps,
} from '@/features/ide-react/components/modals/out-of-sync-modal'
import UnableToSyncModal, {
UnableToSyncModalProps,
} from '@/features/ide-react/components/modals/unable-to-sync-modal'
import GenericConfirmModal, {
GenericConfirmModalOwnProps,
} from '../components/modals/generic-confirm-modal'
@@ -26,6 +29,10 @@ type ModalsContextValue = {
showOutOfSyncModal: (
editorContent: OutOfSyncModalProps['editorContent']
) => void
showUnableToSyncModal: (
editorContent: UnableToSyncModalProps['editorContent'],
docName: UnableToSyncModalProps['docName']
) => void
}
const ModalsContext = createContext<ModalsContextValue | undefined>(undefined)
@@ -50,6 +57,16 @@ export const ModalsContextProvider: FC<React.PropsWithChildren> = ({
editorContent: '',
})
const [shouldShowUnableToSyncModal, setShouldShowUnableToSyncModal] =
useState(false)
const [unableToSyncModalData, setUnableToSyncModalData] = useState<{
editorContent: string
docName: string | null
}>({
editorContent: '',
docName: null,
})
const handleHideGenericModal = useCallback(() => {
setShowGenericModal(false)
}, [])
@@ -91,18 +108,32 @@ export const ModalsContextProvider: FC<React.PropsWithChildren> = ({
setShouldShowOutOfSyncModal(true)
}, [])
const handleHideUnableToSyncModal = useCallback(() => {
setShouldShowUnableToSyncModal(false)
}, [])
const showUnableToSyncModal = useCallback(
(editorContent: string, docName: string | null) => {
setUnableToSyncModalData({ editorContent, docName })
setShouldShowUnableToSyncModal(true)
},
[]
)
const value = useMemo<ModalsContextValue>(
() => ({
showGenericMessageModal,
showGenericConfirmModal,
genericModalVisible: showGenericModal,
showOutOfSyncModal,
showUnableToSyncModal,
}),
[
showGenericMessageModal,
showGenericConfirmModal,
showGenericModal,
showOutOfSyncModal,
showUnableToSyncModal,
]
)
@@ -125,6 +156,11 @@ export const ModalsContextProvider: FC<React.PropsWithChildren> = ({
show={shouldShowOutOfSyncModal}
onHide={handleHideOutOfSyncModal}
/>
<UnableToSyncModal
{...unableToSyncModalData}
show={shouldShowUnableToSyncModal}
onHide={handleHideUnableToSyncModal}
/>
</ModalsContext.Provider>
)
}