2021-11-16 16:01:29 +00:00
|
|
|
import React from 'react'
|
2021-11-26 15:14:10 +00:00
|
|
|
import * as gtag from 'utils/gtag'
|
|
|
|
import { Tldraw, TldrawApp, useFileSystem } from '@tldraw/tldraw'
|
|
|
|
import { useAccountHandlers } from 'hooks/useAccountHandlers'
|
2021-11-16 16:01:29 +00:00
|
|
|
|
|
|
|
declare const window: Window & { app: TldrawApp }
|
|
|
|
|
|
|
|
interface EditorProps {
|
|
|
|
id?: string
|
|
|
|
isUser?: boolean
|
|
|
|
isSponsor?: boolean
|
|
|
|
}
|
|
|
|
|
2021-11-19 12:59:08 +00:00
|
|
|
export default function Editor({ id = 'home', isUser = false, isSponsor = false }: EditorProps) {
|
2021-11-16 16:01:29 +00:00
|
|
|
const handleMount = React.useCallback((app: TldrawApp) => {
|
|
|
|
window.app = app
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
// Send events to gtag as actions.
|
|
|
|
const handlePersist = React.useCallback((_app: TldrawApp, reason?: string) => {
|
|
|
|
gtag.event({
|
2021-11-26 15:14:10 +00:00
|
|
|
action: reason ?? '',
|
2021-11-16 16:01:29 +00:00
|
|
|
category: 'editor',
|
2021-11-26 15:14:10 +00:00
|
|
|
label: reason ?? 'persist',
|
2021-11-16 16:01:29 +00:00
|
|
|
value: 0,
|
|
|
|
})
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
const fileSystemEvents = useFileSystem()
|
|
|
|
|
|
|
|
const { onSignIn, onSignOut } = useAccountHandlers()
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="tldraw">
|
|
|
|
<Tldraw
|
|
|
|
id={id}
|
|
|
|
autofocus
|
|
|
|
onMount={handleMount}
|
|
|
|
onPersist={handlePersist}
|
|
|
|
showSponsorLink={!isSponsor}
|
|
|
|
onSignIn={isSponsor ? undefined : onSignIn}
|
2021-11-19 12:59:08 +00:00
|
|
|
onSignOut={isUser ? onSignOut : undefined}
|
2021-11-16 16:01:29 +00:00
|
|
|
{...fileSystemEvents}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|