Skip to content

Commit cd43ca5

Browse files
committed
fix: novel editor 형식과 맞지 않았던 이슈 해결
1 parent 73bcace commit cd43ca5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

apps/backend/src/yjs/yjs.service.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,16 @@ export class YjsService
9393
// 노드를 클릭해 페이지를 열었을 때만 해당 페이지 값을 가져와서 초기 데이터로 세팅해줍니다.
9494
if (customDoc.name !== 'flow-room') {
9595
const pageId = parseInt(customDoc.name.split('-')[1]);
96-
const content = await this.pageService.findPageById(pageId);
96+
const findPage = await this.pageService.findPageById(pageId);
9797

9898
// content가 비어있다면 내부 구조가 novel editor schema를 따르지 않기 때문에 오류가 납니다.
99-
// type이라는 key가 있을 때만 초기 데이터를 세팅해줍니다.
100-
'type' in content &&
101-
this.initializePageContent(content.content, editorDoc);
99+
// content가 존재할 때만 넣어줍니다.
100+
const novelEditorContent = {
101+
type: 'doc',
102+
content: findPage.content,
103+
};
104+
Object.keys(findPage.content).length > 0 &&
105+
this.initializePageContent(novelEditorContent, editorDoc);
102106

103107
// 페이지 내용 변경 사항을 감지해서 데이터베이스에 갱신합니다.
104108
editorDoc.observeDeep(() => {
@@ -207,7 +211,7 @@ export class YjsService
207211
});
208212
}
209213
// yXmlFragment에 content를 넣어준다.
210-
initializePageContent(content: JSON, yXmlFragment: Y.XmlFragment) {
214+
initializePageContent(content: Object, yXmlFragment: Y.XmlFragment) {
211215
prosemirrorJSONToYXmlFragment(novelEditorSchema, content, yXmlFragment);
212216
}
213217
handleConnection() {

0 commit comments

Comments
 (0)