Skip to content

Commit 5a70fd1

Browse files
feat: tweak the socket io conn
1 parent 9e9af87 commit 5a70fd1

File tree

4 files changed

+7
-32
lines changed

4 files changed

+7
-32
lines changed

src/component/common/editor/main/CollarCodeEditor.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ const CollarCodeEditor: React.FC<EditorProps> = (props: EditorProps) => {
8282

8383
React.useEffect(() => {
8484
if (!BaseMethods.isNull(curSubYDoc)) {
85-
curSubYDoc.load();
8685
console.log("curSubYDoc", curSubYDoc);
8786
let ytext = curSubYDoc.getText(curSubYDoc.guid);
8887
const undoManager = new Y.UndoManager(ytext);
@@ -107,6 +106,7 @@ const CollarCodeEditor: React.FC<EditorProps> = (props: EditorProps) => {
107106
if (activeEditorView && !BaseMethods.isNull(activeEditorView)) {
108107
activeEditorView?.destroy();
109108
}
109+
curSubYDoc.load();
110110
setEditorInstance(editorView);
111111
if (curEditorRootDoc) {
112112
debugger;
@@ -115,7 +115,6 @@ const CollarCodeEditor: React.FC<EditorProps> = (props: EditorProps) => {
115115
.set(curSubYDoc.guid, curSubYDoc);
116116
setCurRootYDoc(curEditorRootDoc);
117117
}
118-
curSubYDoc.load();
119118
}
120119
}, [curSubYDoc]);
121120

src/component/common/projtree/main/ProjectTreeHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export function handleFileSelected(
7070
if (!subdoc || subdoc !== "subdoc") {
7171
return;
7272
}
73+
debugger
7374
let subDocs: Y.Map<Y.Doc> = curRootYDoc.getMap("texhubsubdoc");
7475
if (oldSelectedFile && !BaseMethods.isNull(oldSelectedFile)) {
7576
// destroy the legacy select file

src/service/editor/CollarEditorService.ts

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@ import * as Y from "rdyjs";
44
import * as random from "rdlib0/random";
55
import { createExtensions } from "@/component/common/editor/foundation/extensions/extensions";
66
import { Compartment, EditorState } from "@codemirror/state";
7-
import {
8-
BaseMethods,
9-
UserModel,
10-
} from "rdjs-wheel";
7+
import { BaseMethods } from "rdjs-wheel";
118
import { EditorAttr } from "@/model/proj/config/EditorAttr";
129
import { RefObject } from "react";
13-
import { projHasFile } from "../project/ProjectService";
1410
import { Metadata } from "@/component/common/editor/foundation/extensions/language";
1511
import {
1612
setCurRootYDoc,
1713
setEditorInstance,
1814
} from "../project/editor/EditorService";
15+
import { doSocketIOConn } from "./CollarEditorSocketIOService";
1916

2017
export const usercolors = [
2118
{ color: "#30bced", light: "#30bced33" },
@@ -30,28 +27,6 @@ export const usercolors = [
3027
export const themeConfig = new Compartment();
3128
export const userColor = usercolors[random.uint32() % usercolors.length];
3229

33-
const doWsConn = (ydoc: any, editorAttr: EditorAttr): any => {
34-
let contains = projHasFile(editorAttr.docId, editorAttr.projectId);
35-
if (!contains) {
36-
console.error("initial the file do not belong the project");
37-
}
38-
const wsProvider = null;
39-
const uInfo = localStorage.getItem("userInfo");
40-
if (!uInfo) {
41-
console.error("user info is null", uInfo);
42-
return wsProvider;
43-
}
44-
const user: UserModel = JSON.parse(uInfo);
45-
const ydocUser = {
46-
name: user.nickname,
47-
color: userColor.color,
48-
colorLight: userColor.light,
49-
};
50-
const permanentUserData = new Y.PermanentUserData(ydoc);
51-
permanentUserData.setUserMapping(ydoc, ydoc.clientID, ydocUser.name);
52-
return wsProvider;
53-
};
54-
5530
let history: Uint8Array[] = [];
5631
var ydoc: Y.Doc;
5732
export function saveHistory(docId: string) {
@@ -111,7 +86,7 @@ export function initEditor(
11186
setCurRootYDoc(ydoc);
11287
const ytext: Y.Text = ydoc.getText(editorAttr.docId);
11388
const undoManager = new Y.UndoManager(ytext);
114-
let wsProvider: any = doWsConn(ydoc, editorAttr);
89+
let wsProvider: any = doSocketIOConn(ydoc, editorAttr, false);
11590
const texEditorState = EditorState.create({
11691
doc: ytext.toString(),
11792
extensions: createExtensions({
@@ -134,4 +109,4 @@ export function initEditor(
134109
parent: edContainer.current!,
135110
});
136111
setEditorInstance(editorView);
137-
}
112+
}

src/service/editor/CollarEditorSocketIOService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const handleWsAuth = (
7878
}
7979
};
8080

81-
const doSocketIOConn = (
81+
export const doSocketIOConn = (
8282
rootYDoc: Y.Doc,
8383
editorAttr: EditorAttr,
8484
enableSubDoc: boolean

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy