Merge pull request #18323 from overleaf/mj-editor-loss-debug

[web] DEBUG: Calculate diff size when detecting edit-loss

GitOrigin-RevId: 750f7ed91d5ce81beb520e23181a6a8dc22b6078
This commit is contained in:
Mathias Jakobsen
2024-05-16 08:05:26 +00:00
committed by Copybot
parent c1a4e4a873
commit 2ce41e0ee6
3 changed files with 108 additions and 4 deletions
@@ -11,7 +11,7 @@ import { useGlobalAlertsContainer } from '@/features/ide-react/context/global-al
const MAX_UNSAVED_SECONDS = 15 // lock the editor after this time if unsaved
export const UnsavedDocs: FC = () => {
const { openDocs } = useEditorManagerContext()
const { openDocs, debugTimers } = useEditorManagerContext()
const { permissionsLevel, setPermissionsLevel } = useEditorContext()
const [isLocked, setIsLocked] = useState(false)
const [unsavedDocs, setUnsavedDocs] = useState(new Map<string, number>())
@@ -47,6 +47,7 @@ export const UnsavedDocs: FC = () => {
// NOTE: openDocs should never change, so it's safe to use as a dependency here
useEffect(() => {
const interval = window.setInterval(() => {
debugTimers.current.CheckUnsavedDocs = Date.now()
const unsavedDocs = new Map()
const unsavedDocIds = openDocs.unsavedDocIds()
@@ -67,7 +68,7 @@ export const UnsavedDocs: FC = () => {
return () => {
window.clearInterval(interval)
}
}, [openDocs])
}, [openDocs, debugTimers])
const maxUnsavedSeconds = Math.max(0, ...unsavedDocs.values())