Skip to content

Commit

Permalink
luoluo/fix/notepad (#2310)
Browse files Browse the repository at this point in the history
* perf是否ws.colse,由后端501状态码决定

* fix:标题拼音问题(减少频率,未完全修复)
  • Loading branch information
luoluoTH authored Jan 22, 2025
1 parent 7dbeedd commit 9bb89f2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ export class CollabManager extends ObservableV2<CollabManagerEvents> {
})

this.wsProvider.once("online-user-count", (onlineUserCount: number) => {
if (onlineUserCount < 2 && this.collabStatus.isSynced) {
this.collabService.applyTemplate(template).connect()
} else if (this.collabStatus.isSynced) {
this.collabService.connect()
}
this.collabService
.applyTemplate(template, () => {
return onlineUserCount < 2 && this.collabStatus.isSynced
})
.connect()
})

this.wsProvider.on("saveStatus", ({saveStatus}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ const closeWebsocketConnection = (provider: WebsocketProvider, ws: WebSocket, ev
if (ws === provider.ws) {
if (event) provider.emit("connection-close", [event, provider])
provider.ws = null
ws.close()
provider.wsconnecting = false
if (provider.wsconnected) {
provider.wsconnected = false
Expand All @@ -212,13 +211,19 @@ const closeWebsocketConnection = (provider: WebsocketProvider, ws: WebSocket, ev
} else {
provider.wsUnsuccessfulReconnects++
}
switch (event?.code) {
const code = event?.code || 0
switch (code) {
// event为undefined;
// 1.发送notepadActions.leave,主动断开,不重连,等待后端返回200后关闭ws
case 0:
break
case 401:
case 403:
case 404:
case 200:
case 200: // 发送notepadActions.leave,后端会给200,正常关闭
case 209:
case 500:
ws.close()
break
default:
// Start with no reconnect timeout and increase timeout by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {headingSchema} from "@milkdown/kit/preset/commonmark"
import {$prose} from "@milkdown/kit/utils"
import {Plugin, PluginKey} from "@milkdown/kit/prose/state"
import type {EditorView} from "@milkdown/prose/view"
import debounce from "lodash/debounce"

export const listToHeadingCommand = $command(
`listToHeadingCommand`,
Expand Down Expand Up @@ -42,7 +43,7 @@ export const headingToParagraphCommand = $command(`headingToParagraphCommand`, (
export const customSyncHeadingIdPlugin = $prose((ctx) => {
const headingIdPluginKey = new PluginKey("CUSTOM_MILKDOWN_HEADING_ID")
let isComposed = false
const updateId = (view: EditorView) => {
const updateId = debounce((view: EditorView) => {
if (isComposed) return

const tr = view.state.tr.setMeta("addToHistory", false)
Expand All @@ -67,7 +68,7 @@ export const customSyncHeadingIdPlugin = $prose((ctx) => {
})

if (found) view.dispatch(tr)
}
}, 500)

return new Plugin({
key: headingIdPluginKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {Plugin,PluginKey} from "@milkdown/kit/prose/state"
import {Plugin, PluginKey} from "@milkdown/kit/prose/state"
import {$prose} from "@milkdown/kit/utils"

import {ReplaceStep} from "prosemirror-transform"
import {fileCustomId} from "./uploadPlugin"
import {createSlice} from "@milkdown/kit/ctx"
import moment from "moment"
import {DeleteOSSFileItem} from "../MilkdownEditorType"
import {ReplaceStep} from "@milkdown/kit/prose/transform"

export const getFileNameByUrl = (url) => {
if (!url) return ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {ReactNode, useState} from "react"
import React, {ReactNode, useRef, useState} from "react"
import styles from "./NotepadShareModal.module.scss"
import {YakitButton} from "@/components/yakitUI/YakitButton/YakitButton"
import {
Expand Down Expand Up @@ -48,6 +48,8 @@ const NotepadShareModal: React.FC<NotepadShareModalProps> = React.memo((props) =
const [selectUserList, setSelectUserList] = useState<SelectUserProps[]>([])
const [collaborators, setCollaborators] = useState<NotepadCollaboratorInfoProps[]>(notepadInfo?.collaborator || [])

const colorRef = useRef<string>(randomAvatarColor())

const onClear = useMemoizedFn(() => {
setUserList([])
setSelectUserList([])
Expand Down Expand Up @@ -180,7 +182,7 @@ const NotepadShareModal: React.FC<NotepadShareModalProps> = React.memo((props) =
imgNode: judgeAvatar(
{companyHeadImg: notepadInfo.headImg, companyName: notepadInfo.userName},
28,
randomAvatarColor()
colorRef.current
),
role: ""
}
Expand Down

0 comments on commit 9bb89f2

Please sign in to comment.