Skip to content

Commit

Permalink
[#118] feat: Modal에 의한 Block 생성 시 서버 동기화 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
domino8788 committed Dec 17, 2020
1 parent 971d32e commit 4510344
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions frontend/src/components/molecules/BlockModal/BlockModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import ReactDOM from 'react-dom';

import { useRecoilState, useRecoilValue } from 'recoil';
import { modalState, focusState } from '@/stores';
import { createBlock } from '@/utils';
import { useManager } from '@/hooks';

import TextImg from '@assets/text.png';
Expand Down Expand Up @@ -121,23 +120,24 @@ function BlockModal(): JSX.Element {
const focusId = useRecoilValue(focusState);
const [
{ block, blockIndex },
{ startTransaction, commitTransaction, insertNewSibling, setBlock },
{
startTransaction,
commitTransaction,
insertNewSibling,
setBlock,
setFocus,
},
] = useManager(focusId);

const createBlockHandler = async (type: string) => {
const { block: updatedBlock } = await createBlock({
parentBlockId: block.parentId,
index: blockIndex + 1,
block: { type },
});
startTransaction();
const newBlock = insertNewSibling(updatedBlock);
const newBlock = await insertNewSibling({ type }, blockIndex + 1);
const content =
block.value.substring(0, modal.caretOffset - 1) +
block.value.substring(modal.caretOffset);
setBlock(modal.blockId, { value: content });
await setBlock(modal.blockId, { value: content });
commitTransaction();
// setFocus(newBlock);
setFocus(newBlock);
};

const onClickType = (type: string) => (
Expand Down

0 comments on commit 4510344

Please sign in to comment.