tldraw/packages/www/components/editor.tsx
Steve Ruiz 99730b4fe2
[feature] MVP multiplayer support (#135)
* Adds multiplayer support

* Update liveblocks.tsx

* Update liveblocks.tsx

* Create chaos.tsx

* Fix undo redo, add merge state

* Update multiplayer-editor.tsx

* Adds secret room

* Update chaos.tsx

* Moves shhh to shhhmp

* Fix accidentally deleting the editing shape

* Fix bug where a selected shape is deleted by another user.

* Remove relative path

* Tweak editor

* Remove chaos endpoint

* Adds error state for maximum connections, fixes selectedIds bug on new rooms
2021-10-09 00:05:24 +01:00

37 lines
960 B
TypeScript

import { TLDraw, TLDrawState, Data } from '@tldraw/tldraw'
import * as gtag from '-utils/gtag'
import React from 'react'
interface EditorProps {
id?: string
}
export default function Editor({ id = 'home' }: EditorProps) {
// Put the tlstate into the window, for debugging.
const handleMount = React.useCallback((tlstate: TLDrawState) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.tlstate = tlstate
}, [])
// Send events to gtag as actions.
const handleChange = React.useCallback(
(_tlstate: TLDrawState, _state: Data, reason: string) => {
if (reason.startsWith('command')) {
gtag.event({
action: reason,
category: 'editor',
label: `page:${id}`,
value: 0,
})
}
},
[id]
)
return (
<div className="tldraw">
<TLDraw id={id} onMount={handleMount} onChange={handleChange} autofocus />
</div>
)
}