diff --git a/index.js b/index.js index a93607d..0b5f708 100644 --- a/index.js +++ b/index.js @@ -39,6 +39,7 @@ io.on("connection", (socket) => { } } socket.join(room); + socket.to(room).emit("roomJoined"); }); }); diff --git a/src/components/settingsInputs.jsx b/src/components/settingsInputs.jsx index 31f8bab..5a40dfc 100644 --- a/src/components/settingsInputs.jsx +++ b/src/components/settingsInputs.jsx @@ -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; diff --git a/src/localisation/ru.js b/src/localisation/ru.js index 907beda..42d0ae8 100644 --- a/src/localisation/ru.js +++ b/src/localisation/ru.js @@ -44,7 +44,7 @@ let ru = { NoNotesYet: "Заметок пока нет", AIComplete: "Продолжить заметку (ИИ)", AdditionalFeatures: "Дополнительные функции", - CollabEdit: "Совместное редактрование", + CollabEdit: "Совместное редактирование", Password: "Пароль", CollabEditPassword: "Пароль для совместного редактирования", }; diff --git a/src/pages/create.jsx b/src/pages/create.jsx index cb9570c..732cf03 100644 --- a/src/pages/create.jsx +++ b/src/pages/create.jsx @@ -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); } }}