Skip to content

Commit f750e3c

Browse files
committed
[#118] feat: onBlur처리가 될 때마다 서버에 update
1 parent 39dc667 commit f750e3c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

frontend/src/components/atoms/BlockContent/BlockContent.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/** @jsx jsx */
22
/** @jsxRuntime classic */
33
import { jsx, css, SerializedStyles } from '@emotion/react';
4-
import { useEffect, useRef, FormEvent, KeyboardEvent } from 'react';
4+
import { useEffect, useRef, FormEvent, KeyboardEvent, useState } from 'react';
55
import { useRecoilState, useRecoilValue } from 'recoil';
66

77
import { blockRefState, throttleState, blockMapState } from '@/stores';
88
import { Block, BlockType } from '@/schemes';
9+
import { updateBlock } from '@/utils';
910
import {
1011
regex,
1112
fontSize,
@@ -57,6 +58,7 @@ function BlockContent(blockDTO: Block) {
5758
const caretRef = useRef(0);
5859
const listCnt = useRef(1);
5960
const [Dispatcher] = useCommand();
61+
const [isBlur, setIsBlur] = useState(false);
6062

6163
const indexInSibling: number = blockMap[
6264
blockDTO.parentId
@@ -165,6 +167,13 @@ function BlockContent(blockDTO: Block) {
165167
}
166168
};
167169

170+
useEffect(() => {
171+
(async () => {
172+
const { block: updatedBlock } = await updateBlock(blockDTO);
173+
setBlockMap({ ...blockMap, [blockDTO.id]: updatedBlock });
174+
})();
175+
}, [isBlur]);
176+
168177
useEffect(() => {
169178
blockRefState[blockDTO.id] = contentEditableRef;
170179
return () => {
@@ -208,6 +217,7 @@ function BlockContent(blockDTO: Block) {
208217
placeholder={placeHolder[blockDTO.type]}
209218
onInput={handleValue}
210219
onKeyUp={handleKeyUp}
220+
onBlur={() => setIsBlur(!isBlur)}
211221
>
212222
{blockDTO.value}
213223
</div>

0 commit comments

Comments
 (0)