mirror of
https://github.com/artegoser/AnoPaper.git
synced 2024-11-22 03:46:22 +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.to(room).emit("roomJoined");
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ function SettingsTextInput({
|
|||
type={secret ? "password" : "text"}
|
||||
placeholder={placeholder}
|
||||
title={title}
|
||||
autoComplete="new-password"
|
||||
defaultValue={window.settings[settingName]}
|
||||
onChange={(e) => {
|
||||
window.settings[settingName] = e.target.value;
|
||||
|
|
|
@ -44,7 +44,7 @@ let ru = {
|
|||
NoNotesYet: "Заметок пока нет",
|
||||
AIComplete: "Продолжить заметку (ИИ)",
|
||||
AdditionalFeatures: "Дополнительные функции",
|
||||
CollabEdit: "Совместное редактрование",
|
||||
CollabEdit: "Совместное редактирование",
|
||||
Password: "Пароль",
|
||||
CollabEditPassword: "Пароль для совместного редактирования",
|
||||
};
|
||||
|
|
|
@ -22,20 +22,20 @@ import {
|
|||
import { inputStyle } from "../components/styles";
|
||||
import { Complete } from "../components/openai";
|
||||
|
||||
function nameUpdate(e) {
|
||||
if (Date.now() - window.lastSocketUpdate > window.socketTimeout) {
|
||||
function nameUpdate(val, force) {
|
||||
if (Date.now() - window.lastSocketUpdate > window.socketTimeout || force) {
|
||||
socket.emit("nameChanged", {
|
||||
name: e.target.value,
|
||||
name: val,
|
||||
room: settings.CollabEditPassword,
|
||||
});
|
||||
window.lastSocketUpdate = Date.now();
|
||||
}
|
||||
}
|
||||
|
||||
function textUpdate(e) {
|
||||
if (Date.now() - window.lastSocketUpdate > window.socketTimeout) {
|
||||
function textUpdate(val, force) {
|
||||
if (Date.now() - window.lastSocketUpdate > window.socketTimeout || force) {
|
||||
socket.emit("textChanged", {
|
||||
text: e.target.value,
|
||||
text: val,
|
||||
room: settings.CollabEditPassword,
|
||||
});
|
||||
window.lastSocketUpdate = Date.now();
|
||||
|
@ -88,6 +88,11 @@ function CreateNote() {
|
|||
setName(data.name);
|
||||
localStorage.setItem("NoteName", data.name);
|
||||
});
|
||||
|
||||
socket.on("roomJoined", (data) => {
|
||||
nameUpdate(localStorage.getItem("NoteName"), true);
|
||||
textUpdate(localStorage.getItem("NoteText"), true);
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -121,9 +126,9 @@ function CreateNote() {
|
|||
localStorage.setItem("NoteName", e.target.value);
|
||||
|
||||
if (settings.CollabEdit === true) {
|
||||
nameUpdate(e);
|
||||
nameUpdate(e.target.value);
|
||||
setTimeout(() => {
|
||||
nameUpdate(e);
|
||||
nameUpdate(e.target.value);
|
||||
}, window.socketTimeout);
|
||||
}
|
||||
}}
|
||||
|
@ -142,9 +147,9 @@ function CreateNote() {
|
|||
localStorage.setItem("NoteText", e.target.value);
|
||||
|
||||
if (settings.CollabEdit === true) {
|
||||
textUpdate(e);
|
||||
textUpdate(e.target.value);
|
||||
setTimeout(() => {
|
||||
textUpdate(e);
|
||||
textUpdate(e.target.value);
|
||||
}, window.socketTimeout);
|
||||
}
|
||||
}}
|
||||
|
|
Loading…
Add table
Reference in a new issue