From a41380f4991dd7a1e25ac77a92b803f68ead5911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A7=80=EC=88=98?= Date: Fri, 19 Jan 2024 03:28:35 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B8=88=EC=9C=B5=20=EB=B0=B0=EC=9A=B0?= =?UTF-8?q?=EC=9E=90=20UI=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/eduApi.ts | 6 +-- src/app/(learn)/educations/page.tsx | 8 +-- src/app/(learn)/news/page.tsx | 8 +-- .../molecules/Education/EducationList.tsx | 19 +++---- src/components/molecules/News/NewsList.tsx | 50 +++++++------------ src/components/templates/editor/editor.tsx | 2 - src/libs/editor/slateCompiler.ts | 14 ++++-- 7 files changed, 44 insertions(+), 63 deletions(-) diff --git a/src/api/eduApi.ts b/src/api/eduApi.ts index a0f9cfd..08e31c6 100644 --- a/src/api/eduApi.ts +++ b/src/api/eduApi.ts @@ -35,11 +35,9 @@ export const postEduApi = async ({ title, content }: { title: string; content: s }); if (res.ok) { - const data = await res.json(); - console.log('[✅postEduApi API Data]', data); + return res; } - - return res; + throw new Error('postEduApi error'); }; export const deleteEduApi = async (id: number): Promise => { diff --git a/src/app/(learn)/educations/page.tsx b/src/app/(learn)/educations/page.tsx index 41d7e0f..dda5289 100644 --- a/src/app/(learn)/educations/page.tsx +++ b/src/app/(learn)/educations/page.tsx @@ -20,13 +20,7 @@ const Educations: any = () => {
- {activeToggle === 0 ? ( -
- -
- ) : ( - - )} + {activeToggle === 0 ? : } {/* TODO: 글 작성하는 api 연결 (createFn) */} diff --git a/src/app/(learn)/news/page.tsx b/src/app/(learn)/news/page.tsx index a23c03e..cbab2a7 100644 --- a/src/app/(learn)/news/page.tsx +++ b/src/app/(learn)/news/page.tsx @@ -12,13 +12,7 @@ const LearnWithUs: any = () => { return (
- {activeToggle === 0 ? ( -
- -
- ) : ( - - )} + {activeToggle === 0 ? : }
); }; diff --git a/src/components/molecules/Education/EducationList.tsx b/src/components/molecules/Education/EducationList.tsx index 4864ae4..358352c 100644 --- a/src/components/molecules/Education/EducationList.tsx +++ b/src/components/molecules/Education/EducationList.tsx @@ -48,7 +48,6 @@ export type TEducationsApiResponse = { empty: boolean; }; const Education = () => { - console.log(user.getAccessToken()); const slateCompiler = new SlateCompiler(); const [EducationData, setEducationData] = useState([]); @@ -71,7 +70,6 @@ const Education = () => { const data = await getEducationsData(`size=8&page=${pageNum}`); if (data) { setPageTotalNum(data.totalPages); - setEducationData(data.content); } } catch (error) { @@ -79,6 +77,10 @@ const Education = () => { } }; + const onHeartClick = (id: number, bookmarked: boolean) => { + // TODO: 북마크 api 연결 @이가은 + }; + useEffect(() => { fetchData(); }, [pageNum]); @@ -106,26 +108,25 @@ const Education = () => {
-
+
-
- {/* {truncateText(slateCompiler.toPlainText(JSON.parse(i.content)), 59)} */} +
+ {truncateText(slateCompiler.toPlainText(JSON.parse(i.content)), 50)}
-
{ event.stopPropagation(); - // onHeartClick(i.id, i.bookmarked); + onHeartClick(i.id, i.bookmarked); }} > {i.bookmarked ? : } -
+
))} diff --git a/src/components/molecules/News/NewsList.tsx b/src/components/molecules/News/NewsList.tsx index e1054a7..d9d0e17 100644 --- a/src/components/molecules/News/NewsList.tsx +++ b/src/components/molecules/News/NewsList.tsx @@ -72,38 +72,26 @@ const NewsList = () => { let date = new Date(i.created_at); let dateOnly = date.toISOString().split('T')[0]; return ( -
- -
- -
- -
-

- {i.title} -

-
-
- -
-
{dateOnly}
+
+
+

+ {i.title} +

+
+
+
+
{dateOnly}
- -

+

-
+ ); })} diff --git a/src/components/templates/editor/editor.tsx b/src/components/templates/editor/editor.tsx index d1a5ba4..c070f2c 100644 --- a/src/components/templates/editor/editor.tsx +++ b/src/components/templates/editor/editor.tsx @@ -35,8 +35,6 @@ export default function Editor({ if (mode === 'edit' && (!title || !content || !id)) { throw new Error('edit 모드에서는 title, content, id를 필수로 넘겨주세요'); } - console.log('제목이다.', title); - console.log('내용이다.', content); const initialValue: Descendant[] = [ { diff --git a/src/libs/editor/slateCompiler.ts b/src/libs/editor/slateCompiler.ts index bd1dfb5..0bd0add 100644 --- a/src/libs/editor/slateCompiler.ts +++ b/src/libs/editor/slateCompiler.ts @@ -68,9 +68,17 @@ class SlateCompiler { } } - // toPlainText(node: Descendant[]) { - // return node.map((n) => Node.string(n)).join('\n'); - // } + toPlainText(node: Descendant[]) { + return node.map((n) => this.toPlainTextChild(n)).join(' '); + } + + toPlainTextChild(node: CustomElement | CustomText): string { + if (Text.isText(node)) { + return node.text; + } + + return node.children.map((n) => this.toPlainTextChild(n)).join(' '); + } } export default SlateCompiler;