This commit is contained in:
Jeff Emmett 2024-10-18 17:41:50 -04:00
parent d81ae56de0
commit c369762001
5 changed files with 15 additions and 15 deletions

View File

@ -14,7 +14,7 @@ import { multiplayerAssetStore } from '../client/multiplayerAssetStore'
import { customSchema } from '../../worker/TldrawDurableObject' import { customSchema } from '../../worker/TldrawDurableObject'
import React, { useState } from 'react'; import React, { useState } from 'react';
import { chatBox } from '@/shapes/ChatBoxShapeUtil'; import { ChatBox } from '@/shapes/ChatBoxShapeUtil';
import { components, uiOverrides } from '@/ui-overrides' import { components, uiOverrides } from '@/ui-overrides'
const WORKER_URL = `https://jeffemmett-canvas.jeffemmett.workers.dev` const WORKER_URL = `https://jeffemmett-canvas.jeffemmett.workers.dev`
@ -61,7 +61,7 @@ export function Board() {
onChange={handleNameChange} onChange={handleNameChange}
placeholder="Enter your name" placeholder="Enter your name"
/> />
<chatBox <ChatBox
userName={userName} userName={userName}
roomId={roomId} // Added roomId roomId={roomId} // Added roomId
w={200} // Set appropriate width w={200} // Set appropriate width

View File

@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from "react";
import { BaseBoxShapeUtil, TLBaseShape } from "tldraw"; import { BaseBoxShapeUtil, TLBaseShape } from "tldraw";
export type IChatBoxShape = TLBaseShape< export type IChatBoxShape = TLBaseShape<
'chatBox', 'ChatBox',
{ {
w: number w: number
h: number h: number
@ -12,7 +12,7 @@ export type IChatBoxShape = TLBaseShape<
> >
export class ChatBoxShape extends BaseBoxShapeUtil<IChatBoxShape> { export class ChatBoxShape extends BaseBoxShapeUtil<IChatBoxShape> {
static override type = 'chatBox' static override type = 'ChatBox'
getDefaultProps(): IChatBoxShape['props'] { getDefaultProps(): IChatBoxShape['props'] {
return { return {
@ -29,7 +29,7 @@ export class ChatBoxShape extends BaseBoxShapeUtil<IChatBoxShape> {
component(shape: IChatBoxShape) { component(shape: IChatBoxShape) {
return ( return (
<chatBox roomId={shape.props.roomId} w={shape.props.w} h={shape.props.h} userName="" /> <ChatBox roomId={shape.props.roomId} w={shape.props.w} h={shape.props.h} userName="" />
) )
} }
} }
@ -44,8 +44,8 @@ interface Message {
// Update the chatBox component to accept userName // Update the ChatBox component to accept userName
export const chatBox: React.FC<IChatBoxShape['props']> = ({ roomId, w, h, userName }) => { export const ChatBox: React.FC<IChatBoxShape['props']> = ({ roomId, w, h, userName }) => {
const [messages, setMessages] = useState<Message[]>([]); const [messages, setMessages] = useState<Message[]>([]);
const [inputMessage, setInputMessage] = useState(""); const [inputMessage, setInputMessage] = useState("");
const [username, setUsername] = useState(userName); const [username, setUsername] = useState(userName);

View File

@ -1,7 +1,7 @@
import { BaseBoxShapeTool } from "tldraw"; import { BaseBoxShapeTool } from "tldraw";
export class ChatBoxTool extends BaseBoxShapeTool { export class ChatBoxTool extends BaseBoxShapeTool {
static override id = 'chatBox' static override id = 'ChatBox'
shapeType = 'chatBox'; shapeType = 'ChatBox';
override initial = 'idle'; override initial = 'idle';
} }

View File

@ -19,13 +19,13 @@ export const uiOverrides: TLUiOverrides = {
editor.setCurrentTool('VideoChat') editor.setCurrentTool('VideoChat')
}, },
} }
tools.chatBox = { tools.ChatBox = {
id: 'chatBox', id: 'ChatBox',
icon: 'color', icon: 'color',
label: 'Chat', label: 'Chat',
kbd: 'x', kbd: 'x',
onSelect: () => { onSelect: () => {
editor.setCurrentTool('chatBox') editor.setCurrentTool('ChatBox')
}, },
} }
return tools return tools
@ -35,12 +35,12 @@ export const uiOverrides: TLUiOverrides = {
export const components: TLComponents = { export const components: TLComponents = {
Toolbar: (props) => { Toolbar: (props) => {
const tools = useTools() const tools = useTools()
const isChatBoxSelected = useIsToolSelected(tools['chatBox']) const isChatBoxSelected = useIsToolSelected(tools['ChatBox'])
const isVideoSelected = useIsToolSelected(tools['VideoChat']) const isVideoSelected = useIsToolSelected(tools['VideoChat'])
return ( return (
<DefaultToolbar {...props}> <DefaultToolbar {...props}>
<TldrawUiMenuItem {...tools['VideoChat']} isSelected={isVideoSelected} /> <TldrawUiMenuItem {...tools['VideoChat']} isSelected={isVideoSelected} />
<TldrawUiMenuItem {...tools['chatBox']} isSelected={isChatBoxSelected} /> <TldrawUiMenuItem {...tools['ChatBox']} isSelected={isChatBoxSelected} />
<DefaultToolbarContent /> <DefaultToolbarContent />
</DefaultToolbar> </DefaultToolbar>
) )

View File

@ -15,7 +15,7 @@ import { VideoChatShape } from '@/shapes/VideoChatShapeUtil'
// add custom shapes and bindings here if needed: // add custom shapes and bindings here if needed:
export const customSchema = createTLSchema({ export const customSchema = createTLSchema({
shapes: { ...defaultShapeSchemas, chatBox: ChatBoxShape, VideoChat: VideoChatShape }, shapes: { ...defaultShapeSchemas, ChatBox: ChatBoxShape, VideoChat: VideoChatShape },
// bindings: { ...defaultBindingSchemas }, // bindings: { ...defaultBindingSchemas },
}) })