356a0d1e73
- Remove TLUser, TLUserPresence - Add first-class support for user preferences that persists across rooms and tabs ### Change Type <!-- 💡 Indicate the type of change your pull request is. --> <!-- 🤷♀️ If you're not sure, don't select anything --> <!-- ✂️ Feel free to delete unselected options --> <!-- To select one, put an x in the box: [x] --> - [ ] `patch` — Bug Fix - [ ] `minor` — New Feature - [x] `major` — Breaking Change - [ ] `dependencies` — Dependency Update (publishes a `patch` release, for devDependencies use `internal`) - [ ] `documentation` — Changes to the documentation only (will not publish a new version) - [ ] `tests` — Changes to any testing-related code only (will not publish a new version) - [ ] `internal` — Any other changes that don't affect the published package (will not publish a new version) ### Test Plan 1. Add a step-by-step description of how to test your PR here. 2. - [ ] Unit Tests - [ ] Webdriver tests ### Release Notes - Add a brief release note for your PR here.
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { TLInstanceId, useApp } from '@tldraw/editor'
|
|
import { parseAndLoadDocument } from '@tldraw/file-format'
|
|
import { useDefaultHelpers } from '@tldraw/ui'
|
|
import React from 'react'
|
|
import { vscode } from './utils/vscode'
|
|
|
|
export function FileOpen({
|
|
fileContents,
|
|
instanceId,
|
|
forceDarkMode,
|
|
}: {
|
|
instanceId: TLInstanceId
|
|
fileContents: string
|
|
forceDarkMode: boolean
|
|
}) {
|
|
const app = useApp()
|
|
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(app, fileContents, msg, addToast, onV1FileLoad, forceDarkMode)
|
|
}
|
|
|
|
loadFile()
|
|
setIsFileLoaded(true)
|
|
return () => {
|
|
clearToasts()
|
|
}
|
|
}, [fileContents, app, instanceId, addToast, msg, clearToasts, forceDarkMode, isFileLoaded])
|
|
|
|
return null
|
|
}
|