mirror of
https://github.com/artegoser/AnoPaper.git
synced 2024-11-25 05:16:21 +03:00
fix: get initial text in collaborative editing
This commit is contained in:
parent
536c847375
commit
ac79495f83
4 changed files with 18 additions and 11 deletions
1
index.js
1
index.js
|
@ -39,6 +39,7 @@ io.on("connection", (socket) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
socket.join(room);
|
socket.join(room);
|
||||||
|
socket.to(room).emit("roomJoined");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ function SettingsTextInput({
|
||||||
type={secret ? "password" : "text"}
|
type={secret ? "password" : "text"}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
title={title}
|
title={title}
|
||||||
|
autoComplete="new-password"
|
||||||
defaultValue={window.settings[settingName]}
|
defaultValue={window.settings[settingName]}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
window.settings[settingName] = e.target.value;
|
window.settings[settingName] = e.target.value;
|
||||||
|
|
|
@ -44,7 +44,7 @@ let ru = {
|
||||||
NoNotesYet: "Заметок пока нет",
|
NoNotesYet: "Заметок пока нет",
|
||||||
AIComplete: "Продолжить заметку (ИИ)",
|
AIComplete: "Продолжить заметку (ИИ)",
|
||||||
AdditionalFeatures: "Дополнительные функции",
|
AdditionalFeatures: "Дополнительные функции",
|
||||||
CollabEdit: "Совместное редактрование",
|
CollabEdit: "Совместное редактирование",
|
||||||
Password: "Пароль",
|
Password: "Пароль",
|
||||||
CollabEditPassword: "Пароль для совместного редактирования",
|
CollabEditPassword: "Пароль для совместного редактирования",
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,20 +22,20 @@ import {
|
||||||
import { inputStyle } from "../components/styles";
|
import { inputStyle } from "../components/styles";
|
||||||
import { Complete } from "../components/openai";
|
import { Complete } from "../components/openai";
|
||||||
|
|
||||||
function nameUpdate(e) {
|
function nameUpdate(val, force) {
|
||||||
if (Date.now() - window.lastSocketUpdate > window.socketTimeout) {
|
if (Date.now() - window.lastSocketUpdate > window.socketTimeout || force) {
|
||||||
socket.emit("nameChanged", {
|
socket.emit("nameChanged", {
|
||||||
name: e.target.value,
|
name: val,
|
||||||
room: settings.CollabEditPassword,
|
room: settings.CollabEditPassword,
|
||||||
});
|
});
|
||||||
window.lastSocketUpdate = Date.now();
|
window.lastSocketUpdate = Date.now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function textUpdate(e) {
|
function textUpdate(val, force) {
|
||||||
if (Date.now() - window.lastSocketUpdate > window.socketTimeout) {
|
if (Date.now() - window.lastSocketUpdate > window.socketTimeout || force) {
|
||||||
socket.emit("textChanged", {
|
socket.emit("textChanged", {
|
||||||
text: e.target.value,
|
text: val,
|
||||||
room: settings.CollabEditPassword,
|
room: settings.CollabEditPassword,
|
||||||
});
|
});
|
||||||
window.lastSocketUpdate = Date.now();
|
window.lastSocketUpdate = Date.now();
|
||||||
|
@ -88,6 +88,11 @@ function CreateNote() {
|
||||||
setName(data.name);
|
setName(data.name);
|
||||||
localStorage.setItem("NoteName", data.name);
|
localStorage.setItem("NoteName", data.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on("roomJoined", (data) => {
|
||||||
|
nameUpdate(localStorage.getItem("NoteName"), true);
|
||||||
|
textUpdate(localStorage.getItem("NoteText"), true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -121,9 +126,9 @@ function CreateNote() {
|
||||||
localStorage.setItem("NoteName", e.target.value);
|
localStorage.setItem("NoteName", e.target.value);
|
||||||
|
|
||||||
if (settings.CollabEdit === true) {
|
if (settings.CollabEdit === true) {
|
||||||
nameUpdate(e);
|
nameUpdate(e.target.value);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
nameUpdate(e);
|
nameUpdate(e.target.value);
|
||||||
}, window.socketTimeout);
|
}, window.socketTimeout);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
@ -142,9 +147,9 @@ function CreateNote() {
|
||||||
localStorage.setItem("NoteText", e.target.value);
|
localStorage.setItem("NoteText", e.target.value);
|
||||||
|
|
||||||
if (settings.CollabEdit === true) {
|
if (settings.CollabEdit === true) {
|
||||||
textUpdate(e);
|
textUpdate(e.target.value);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
textUpdate(e);
|
textUpdate(e.target.value);
|
||||||
}, window.socketTimeout);
|
}, window.socketTimeout);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Add table
Reference in a new issue