-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
related to: #169
- Loading branch information
Showing
7 changed files
with
97 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
.../boards/[boardId]/create-post/_components/CreatePostForm/PostContentFieldEditor/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use client' | ||
|
||
import { useEffect, useMemo, useState } from 'react' | ||
|
||
import { Block, BlockNoteEditor, PartialBlock } from '@blocknote/core' | ||
import { BlockNoteView } from '@blocknote/mantine' | ||
import '@blocknote/mantine/style.css' | ||
|
||
import { usePostEditorStore } from '~create-post/_store/post-editor' | ||
|
||
export const PostContentFieldEditor = () => { | ||
const { setPostContent, getPostContent } = usePostEditorStore() | ||
const [initialContent, setInitialContent] = useState< | ||
'loading' | PartialBlock[] | undefined | ||
>('loading') | ||
|
||
useEffect(() => { | ||
const storedBlocks = getPostContent() | ||
setInitialContent(storedBlocks) | ||
}, [getPostContent]) | ||
|
||
const editor = useMemo(() => { | ||
if (initialContent === 'loading') { | ||
return undefined | ||
} | ||
return BlockNoteEditor.create({ initialContent }) | ||
}, [initialContent]) | ||
|
||
if (editor === undefined) { | ||
return <div>글 불러오는 중...</div> | ||
} | ||
|
||
return ( | ||
<BlockNoteView | ||
editor={editor} | ||
onChange={() => { | ||
setPostContent(editor.document as Block[]) | ||
}} | ||
className="h-96 overflow-auto rounded-md border pt-4" | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...)/activity/[semesterName]/[activityId]/boards/[boardId]/create-post/_store/post-editor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Block } from '@blocknote/core' | ||
import { create } from 'zustand' | ||
import { createJSONStorage, persist } from 'zustand/middleware' | ||
|
||
interface PostEditorProps { | ||
postContent?: Block[] | ||
setPostContent: (blocks: Block[]) => void | ||
getPostContent: () => Block[] | undefined | ||
clearPostContent: () => void | ||
} | ||
|
||
export const usePostEditorStore = create( | ||
persist<PostEditorProps>( | ||
(set, get) => ({ | ||
postContent: undefined, | ||
setPostContent: (block) => { | ||
set({ postContent: block }) | ||
}, | ||
getPostContent: () => get().postContent, | ||
clearPostContent: () => { | ||
set({ postContent: undefined }) | ||
}, | ||
}), | ||
{ | ||
name: 'post-editor', | ||
storage: createJSONStorage(() => sessionStorage), | ||
}, | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters