Skip to content

[Deploy] 11 #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/entities/post/detail/PostHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const PostHeader = ({
return (
<div
className={
'post-header h-[220px] md:h-[292px] relative overflow-hidden w-full text-center'
'post-header h-[220px] md:h-[292px] relative overflow-hidden w-full text-center bg-gray-400/50'
}
>
<h1 className={'font-bold mb-4 pt-10 md:pt-20 text-3xl lg:text-5xl'}>
<h1 className={'font-bold mb-4 pt-10 md:pt-20 text-3xl lg:text-5xl '}>
{displayTitle}
{!isTypingComplete && (
<span className="inline-block w-1 h-6 ml-1 bg-black animate-blink" />
Expand Down
3 changes: 3 additions & 0 deletions app/entities/post/write/BlogForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand All @@ -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();
Expand Down
32 changes: 32 additions & 0 deletions app/hooks/useBlockNavigate.ts
Original file line number Diff line number Diff line change
@@ -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]);
};
2 changes: 1 addition & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default function Home() {
posts &&
posts.slice(0, 3).map((post) => (
<Link
href={`/posts/${post._id}`}
href={`/posts/${post.slug}`}
key={post._id}
className="group cursor-pointer"
>
Expand Down
Loading