tldraw/apps/vscode/editor/src/FileOpen.tsx
alex a0628f9cb2
tldraw_final_v6_final(old version).docx.pdf (#2998)
Rename `@tldraw/tldraw` to just `tldraw`! `@tldraw/tldraw` still exists
as an alias to `tldraw` for folks who are still using that.

### Test Plan

- [x] Unit Tests
- [ ] End to end tests

### Release Notes

- The `@tldraw/tldraw` package has been renamed to `tldraw`. You can
keep using the old version if you want though!
2024-02-29 16:06:19 +00:00

44 lines
1.2 KiB
TypeScript

import React from 'react'
import { parseAndLoadDocument, useDefaultHelpers, useEditor } from 'tldraw'
import { vscode } from './utils/vscode'
export function FileOpen({
fileContents,
forceDarkMode,
}: {
fileContents: string
forceDarkMode: boolean
}) {
const editor = useEditor()
const { msg, addToast, clearToasts } = useDefaultHelpers()
const [isFileLoaded, setIsFileLoaded] = React.useState(false)
React.useEffect(() => {
if (isFileLoaded) return
function onV1FileLoad() {
vscode.postMessage({
type: 'vscode:v1-file-opened',
data: {
description: msg('vscode.file-open.desc'),
backup: msg('vscode.file-open.backup'),
backupSaved: msg('vscode.file-open.backup-saved'),
backupFailed: msg('vscode.file-open.backup-failed'),
dontAskAgain: msg('vscode.file-open.dont-show-again'),
open: msg('vscode.file-open.open'),
},
})
}
async function loadFile() {
await parseAndLoadDocument(editor, fileContents, msg, addToast, onV1FileLoad, forceDarkMode)
}
loadFile()
setIsFileLoaded(true)
return () => {
clearToasts()
}
}, [fileContents, editor, addToast, msg, clearToasts, forceDarkMode, isFileLoaded])
return null
}