From 730f6124f97383f349b7a533d8d4904815f4cdbd Mon Sep 17 00:00:00 2001 From: sscoderati <69716992+sscoderati@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:42:43 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=93=9D=20Chore(#347):=20SteadyState?= =?UTF-8?q?=20reset=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/createSteadyData.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/stores/createSteadyData.ts b/src/stores/createSteadyData.ts index 82ed8b34..12cc524c 100644 --- a/src/stores/createSteadyData.ts +++ b/src/stores/createSteadyData.ts @@ -8,6 +8,7 @@ interface CreateSteadyState { steadyState: SteadyStateType; // eslint-disable-next-line no-unused-vars setSteadyState: (steadyState: SteadyStateType) => void; + resetSteadyState: () => void; } const useCreateSteadyStore = create( @@ -15,6 +16,7 @@ const useCreateSteadyStore = create( (set) => ({ steadyState: {} as SteadyStateType, setSteadyState: (steadyState: SteadyStateType) => set({ steadyState }), + resetSteadyState: () => set({ steadyState: {} as SteadyStateType }), }), { name: CreateSteadyStorageKey, From d854a7c92c52076300e191782ffc83c096ec55d6 Mon Sep 17 00:00:00 2001 From: sscoderati <69716992+sscoderati@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:45:07 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=9A=A8=20Fix(#347):=20SteadyState?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=9E=91=EC=84=B1=EC=A4=91=EC=9D=B4?= =?UTF-8?q?=EB=8D=98=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=B6=88=EB=9F=AC?= =?UTF-8?q?=EC=98=A4=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(steady)/steady/create/page.tsx | 78 ++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/src/app/(steady)/steady/create/page.tsx b/src/app/(steady)/steady/create/page.tsx index 7e7c9485..f0982c19 100644 --- a/src/app/(steady)/steady/create/page.tsx +++ b/src/app/(steady)/steady/create/page.tsx @@ -1,5 +1,6 @@ "use client"; +import { useEffect, useRef, useState } from "react"; import { useForm } from "react-hook-form"; import { useRouter } from "next/navigation"; import { @@ -14,12 +15,16 @@ import type { SteadyStateType } from "@/schemas/steadySchema"; import { SteadySchema } from "@/schemas/steadySchema"; import useCreateSteadyStore from "@/stores/createSteadyData"; import { zodResolver } from "@hookform/resolvers/zod"; +import type { MDXEditorMethods } from "@mdxeditor/editor"; import { Separator } from "@radix-ui/themes"; import { useSuspenseQuery } from "@tanstack/react-query"; -import { format } from "date-fns"; +import { format, parse } from "date-fns"; +import rehypeParse from "rehype-parse"; +import rehypeRemark from "rehype-remark"; import rehypeStringify from "rehype-stringify"; import remarkParse from "remark-parse"; import remarkRehype from "remark-rehype"; +import remarkStringify from "remark-stringify"; import { unified } from "unified"; import getPositions from "@/services/steady/getPositions"; import getStacks from "@/services/steady/getStacks"; @@ -46,6 +51,8 @@ import { const CreateSteadyPage = () => { const router = useRouter(); const { steadyState, setSteadyState } = useCreateSteadyStore(); + const editorRef = useRef(null); + const [editorLoaded, setEditorLoaded] = useState(false); const steadyForm = useForm({ resolver: zodResolver(SteadySchema), }); @@ -80,6 +87,20 @@ const CreateSteadyPage = () => { router.replace("/"); }; + useEffect(() => { + if (editorRef.current) { + unified() + .use(rehypeParse) + .use(rehypeRemark) + .use(remarkStringify) + .process(steadyState.content) + .then((file) => editorRef.current?.setMarkdown(String(file.value))) + .catch((error) => { + throw error; + }); + } + }, [editorLoaded]); + return (
{
( { field.onChange(value); }} @@ -114,12 +137,14 @@ const CreateSteadyPage = () => { /> ( { field.onChange(value); }} @@ -143,6 +168,7 @@ const CreateSteadyPage = () => { > ( @@ -150,6 +176,7 @@ const CreateSteadyPage = () => { initialLabel={"프로젝트 / 스터디"} items={steadyCategories} className={cn("w-full")} + initialData={steadyState?.type} onSelectedChange={(selected) => { field.onChange(selected); }} @@ -161,11 +188,13 @@ const CreateSteadyPage = () => { ( { @@ -179,11 +208,13 @@ const CreateSteadyPage = () => { ( { @@ -197,11 +228,21 @@ const CreateSteadyPage = () => { ( { field.onChange(format(date, "yyyy-MM-dd")); @@ -215,12 +256,26 @@ const CreateSteadyPage = () => { ( + steadyState.positions.includes( + Number(position.id), + ), + ) + .map(({ id, name }) => ({ + value: id.toString(), + label: name, + }))) || + [] + } items={positions.positions.map((position) => ({ value: position.id.toString(), label: position.name, @@ -237,11 +292,13 @@ const CreateSteadyPage = () => { ( { @@ -255,11 +312,23 @@ const CreateSteadyPage = () => { ( + steadyState.stacks.includes(Number(stack.id)), + ) + .map(({ id, name }) => ({ + value: id.toString(), + label: name, + })) + } items={stacks.stacks.map((stack) => ({ value: stack.id.toString(), label: stack.name, @@ -277,6 +346,7 @@ const CreateSteadyPage = () => { ( @@ -301,11 +371,13 @@ const CreateSteadyPage = () => { /> ( { field.onChange(value); }} @@ -316,6 +388,7 @@ const CreateSteadyPage = () => { /> ( { }); }} markdown={""} + setIsLoaded={setEditorLoaded} /> From e6865c29b56fbbb02626fd1d6eafce3455eefa0f Mon Sep 17 00:00:00 2001 From: sscoderati <69716992+sscoderati@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:46:25 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=9A=A8=20Fix(#47):=20=EC=97=90?= =?UTF-8?q?=EB=94=94=ED=84=B0=20=ED=95=98=EB=8B=A8=EA=B9=8C=EC=A7=80=20?= =?UTF-8?q?=ED=81=B4=EB=A6=AD=20=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=86=92=EC=9D=B4=20=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(steady)/steady/create/page.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/(steady)/steady/create/page.tsx b/src/app/(steady)/steady/create/page.tsx index f0982c19..d5df8ab3 100644 --- a/src/app/(steady)/steady/create/page.tsx +++ b/src/app/(steady)/steady/create/page.tsx @@ -393,11 +393,13 @@ const CreateSteadyPage = () => { render={({ field }) => ( { unified() .use(remarkParse) From 18660a7b2435cf7eddaccc573654e171a66ea9c0 Mon Sep 17 00:00:00 2001 From: sscoderati <69716992+sscoderati@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:47:08 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=9A=A8=20Fix(#347):=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=20=EC=B7=A8=EC=86=8C=20=ED=9B=84=EC=97=90=EB=8F=84=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=EB=90=9C=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=EA=B0=80=20=EB=B6=88=EB=9F=AC=EC=99=80=EC=A7=80=EB=8A=94=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(steady)/steady/create/page.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/(steady)/steady/create/page.tsx b/src/app/(steady)/steady/create/page.tsx index d5df8ab3..153c0977 100644 --- a/src/app/(steady)/steady/create/page.tsx +++ b/src/app/(steady)/steady/create/page.tsx @@ -50,7 +50,8 @@ import { const CreateSteadyPage = () => { const router = useRouter(); - const { steadyState, setSteadyState } = useCreateSteadyStore(); + const { steadyState, setSteadyState, resetSteadyState } = + useCreateSteadyStore(); const editorRef = useRef(null); const [editorLoaded, setEditorLoaded] = useState(false); const steadyForm = useForm({ @@ -83,6 +84,8 @@ const CreateSteadyPage = () => { const handleCancelProcess = () => { if (steadyState) { useCreateSteadyStore.persist.clearStorage(); + steadyForm.reset(); + resetSteadyState(); } router.replace("/"); }; From 26b2c7c93c35977f38041b3840ba12e05270f49d Mon Sep 17 00:00:00 2001 From: sscoderati <69716992+sscoderati@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:53:09 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=93=9D=20Chore(#347):=20=EC=8A=A4?= =?UTF-8?q?=ED=85=8C=EB=94=94=20=EB=93=B1=EB=A1=9D=20=EC=84=B1=EA=B3=B5=20?= =?UTF-8?q?=EC=8B=9C=20SteadyState=20=EC=B4=88=EA=B8=B0=ED=99=94=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(steady)/steady/create/questions/page.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/(steady)/steady/create/questions/page.tsx b/src/app/(steady)/steady/create/questions/page.tsx index dd96824e..61c7538b 100644 --- a/src/app/(steady)/steady/create/questions/page.tsx +++ b/src/app/(steady)/steady/create/questions/page.tsx @@ -25,7 +25,7 @@ const CreateQuestionsPage = () => { const [isTemplateTitleSetting, setIsTemplateTitleSetting] = useState(false); const { toast } = useToast(); const router = useRouter(); - const { steadyState } = useCreateSteadyStore(); + const { steadyState, resetSteadyState } = useCreateSteadyStore(); useEffect(() => { if (!steadyState || Object.keys(steadyState).length === 0) { @@ -103,6 +103,7 @@ const CreateQuestionsPage = () => { variant: "green", }); useCreateSteadyStore.persist.clearStorage(); + resetSteadyState(); router.push("/"); }) .catch(() => {