-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor and redesign of the 3d-web-text-chat package (#38)
* refactor and redesign of the 3d-web-text-chat package * removes unused file
- Loading branch information
1 parent
ec6b399
commit c9bd94d
Showing
16 changed files
with
270 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { createRef, forwardRef } from "react"; | ||
import { flushSync } from "react-dom"; | ||
import { createRoot, Root } from "react-dom/client"; | ||
|
||
import { ChatUIComponent } from "./components/ChatPanel/TextChatUIComponent"; | ||
|
||
const ForwardedChatUIComponent = forwardRef(ChatUIComponent); | ||
|
||
export type ChatUIInstance = { | ||
addMessage: (username: string, message: string) => void; | ||
}; | ||
|
||
export class TextChatUI { | ||
private root: Root; | ||
private appRef: React.RefObject<ChatUIInstance> = createRef<ChatUIInstance>(); | ||
|
||
public addTextMessage(username: string, message: string) { | ||
if (this.appRef.current) this.appRef.current.addMessage(username, message); | ||
} | ||
|
||
private container = document.getElementById("text-chat-ui")!; | ||
|
||
constructor( | ||
private clientname: string, | ||
private sendMessageToServerMethod: (message: string) => void, | ||
) { | ||
this.root = createRoot(this.container); | ||
this.sendMessageToServerMethod = sendMessageToServerMethod; | ||
} | ||
|
||
init() { | ||
flushSync(() => | ||
this.root.render( | ||
<ForwardedChatUIComponent | ||
ref={this.appRef} | ||
clientName={this.clientname} | ||
sendMessageToServer={this.sendMessageToServerMethod} | ||
/>, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.