mirror of
https://github.com/fluencelabs/fluent-pad
synced 2025-04-25 17:02:12 +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;
|
border: none;
|
||||||
outline: none;
|
outline: none;
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
background-color: $color-disabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.text-input {
|
.text-input {
|
||||||
|
@ -17,11 +17,10 @@ const broadcastUpdates = _.debounce((text: string, syncClient: SyncClient) => {
|
|||||||
|
|
||||||
export const CollaborativeEditor = () => {
|
export const CollaborativeEditor = () => {
|
||||||
const client = useFluenceClient()!;
|
const client = useFluenceClient()!;
|
||||||
const [text, setText] = useState('');
|
const [text, setText] = useState<string | null>(null);
|
||||||
const [syncClient, setSyncClient] = useState(new SyncClient());
|
const [syncClient, setSyncClient] = useState(new SyncClient());
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
syncClient.syncDoc(initDoc());
|
|
||||||
syncClient.handleDocUpdate = (doc) => {
|
syncClient.handleDocUpdate = (doc) => {
|
||||||
setText(doc.text.toString());
|
setText(doc.text.toString());
|
||||||
};
|
};
|
||||||
@ -48,6 +47,10 @@ export const CollaborativeEditor = () => {
|
|||||||
for (let e of res) {
|
for (let e of res) {
|
||||||
syncClient.receiveChanges(e.body);
|
syncClient.receiveChanges(e.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (syncClient.getDoc() === undefined) {
|
||||||
|
syncClient.syncDoc(initDoc());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
@ -62,5 +65,13 @@ export const CollaborativeEditor = () => {
|
|||||||
broadcastUpdates(newText, syncClient);
|
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