mirror of
https://github.com/fluencelabs/fluent-pad
synced 2025-04-25 08:52:14 +00:00
Fix a bug when newly connected peer overwrites existing room state
This commit is contained in:
parent
e1574427a5
commit
18daaa3439
@ -120,6 +120,10 @@ body {
|
||||
|
||||
border: none;
|
||||
outline: none;
|
||||
|
||||
&:disabled {
|
||||
background-color: $color-disabled;
|
||||
}
|
||||
}
|
||||
|
||||
.text-input {
|
||||
|
@ -17,11 +17,10 @@ const broadcastUpdates = _.debounce((text: string, syncClient: SyncClient) => {
|
||||
|
||||
export const CollaborativeEditor = () => {
|
||||
const client = useFluenceClient()!;
|
||||
const [text, setText] = useState('');
|
||||
const [text, setText] = useState<string | null>(null);
|
||||
const [syncClient, setSyncClient] = useState(new SyncClient());
|
||||
|
||||
useEffect(() => {
|
||||
syncClient.syncDoc(initDoc());
|
||||
syncClient.handleDocUpdate = (doc) => {
|
||||
setText(doc.text.toString());
|
||||
};
|
||||
@ -48,6 +47,10 @@ export const CollaborativeEditor = () => {
|
||||
for (let e of res) {
|
||||
syncClient.receiveChanges(e.body);
|
||||
}
|
||||
|
||||
if (syncClient.getDoc() === undefined) {
|
||||
syncClient.syncDoc(initDoc());
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
@ -62,5 +65,13 @@ export const CollaborativeEditor = () => {
|
||||
broadcastUpdates(newText, syncClient);
|
||||
};
|
||||
|
||||
return <textarea spellCheck={false} className="code-editor" value={text} onChange={handleTextUpdate} />;
|
||||
return (
|
||||
<textarea
|
||||
spellCheck={false}
|
||||
className="code-editor"
|
||||
disabled={text === null}
|
||||
value={text ?? ''}
|
||||
onChange={handleTextUpdate}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user