From 2b682792cb48f9ac24c6a30c8dbed2a71d978ad8 Mon Sep 17 00:00:00 2001 From: JeongwooSeo Date: Fri, 20 Dec 2024 02:41:03 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20main=20=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=B8=94=EB=A1=9C=EA=B7=B8=20=EA=B8=80?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=8F=99=ED=95=A0=EB=95=8C=20slug?= =?UTF-8?q?=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/page.tsx b/app/page.tsx index 729de90..e8a8520 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -91,7 +91,7 @@ export default function Home() { posts && posts.slice(0, 3).map((post) => ( From a3542690b96d345c24ad190f84dbd748f1695c78 Mon Sep 17 00:00:00 2001 From: JeongwooSeo Date: Fri, 20 Dec 2024 02:49:45 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=EA=B8=80=EC=93=B0=EA=B8=B0=20?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=EC=97=90=EC=84=9C=20=EC=83=88?= =?UTF-8?q?=EB=A1=9C=EA=B3=A0=EC=B9=A8=20=EB=A7=89=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/entities/post/write/BlogForm.tsx | 3 +++ app/hooks/useBlockNavigate.ts | 32 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 app/hooks/useBlockNavigate.ts diff --git a/app/entities/post/write/BlogForm.tsx b/app/entities/post/write/BlogForm.tsx index a79c41d..a7ad1b5 100644 --- a/app/entities/post/write/BlogForm.tsx +++ b/app/entities/post/write/BlogForm.tsx @@ -12,6 +12,7 @@ import { StaticImport } from 'next/dist/shared/lib/get-img-props'; import LoadingSpinner from '@/app/entities/common/Loading/LoadingSpinner'; import axios from 'axios'; import useToast from '@/app/hooks/useToast'; +import { useBlockNavigate } from '@/app/hooks/useBlockNavigate'; const MDEditor = dynamic(() => import('@uiw/react-md-editor'), { ssr: false }); @@ -32,6 +33,8 @@ const BlogForm = ({ postBlog, postId }: BlogFormProps) => { const buttonStyle = `font-bold py-2 px-4 rounded mr-2 disabled:bg-opacity-75 `; const NICKNAME = '개발자 서정우'; + useBlockNavigate({ title, content: content || '' }); + useEffect(() => { if (postId) { getPostDetail(); diff --git a/app/hooks/useBlockNavigate.ts b/app/hooks/useBlockNavigate.ts new file mode 100644 index 0000000..d71da05 --- /dev/null +++ b/app/hooks/useBlockNavigate.ts @@ -0,0 +1,32 @@ +import { useEffect, useState } from 'react'; + +interface PostForm { + title: string; + content: string; +} + +export const useBlockNavigate = (formData: PostForm, alertMessage?: string) => { + const [isDirty, setIsDirty] = useState(false); + + useEffect(() => { + if (formData.title || formData.content) { + setIsDirty(true); + } + }, [formData]); + + useEffect(() => { + const handleBeforeUnload = (e: BeforeUnloadEvent) => { + if (isDirty) { + const message = alertMessage || '변경사항이 적용되지 않을 수 있습니다.'; + e.returnValue = message; + return message; + } + }; + + window.addEventListener('beforeunload', handleBeforeUnload); + + return () => { + window.removeEventListener('beforeunload', handleBeforeUnload); + }; + }, [isDirty]); +}; From 869b26472255ea69d5360eb33aaa661e321a5386 Mon Sep 17 00:00:00 2001 From: JeongwooSeo Date: Fri, 20 Dec 2024 17:23:19 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20=ED=8F=AC=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=ED=97=A4=EB=8D=94=20=EB=B0=B0=EA=B2=BD=EC=9D=84=20=EB=B0=98?= =?UTF-8?q?=ED=88=AC=EB=AA=85=ED=95=9C=20=ED=9A=8C=EC=83=89=20=EB=B0=B0?= =?UTF-8?q?=EA=B2=BD=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 제목 가시성 향상을 위해 --- app/entities/post/detail/PostHeader.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/entities/post/detail/PostHeader.tsx b/app/entities/post/detail/PostHeader.tsx index 3d92fd2..ee3c4d6 100644 --- a/app/entities/post/detail/PostHeader.tsx +++ b/app/entities/post/detail/PostHeader.tsx @@ -47,10 +47,10 @@ const PostHeader = ({ return (
-

+

{displayTitle} {!isTypingComplete && (