'use client' import { Crepe } from "@milkdown/crepe"; import { MilkdownProvider } from "@milkdown/react"; import { useCallback, useState,useRef } from "react"; import { MilkdownEditor } from "@/app/components/editor"; export default function Page() { const titleRef = useRef(null!); const tagRef = useRef(null!); const crepeRef = useRef(null!); const [isLoading, setIsLoading] = useState(false); const [toastMessage, setToastMessage] = useState(''); const handlePost = async () => { setIsLoading(true); try { const response = await fetch('/api/notice', { method: 'POST', body: JSON.stringify({ title: titleRef.current?.value, content: crepeRef.current?.getMarkdown(), tag: tagRef.current?.value, }), }); if (response.ok) { setToastMessage('Post successful!'); setTimeout(() => { setToastMessage(''); window.location.href = '/usr/4_noticeboard'; // Redirect after success }, 1000); // 3 seconds delay } else { setToastMessage('Failed to post.'); } } catch (error) { setToastMessage('An error occurred.'); } finally { setIsLoading(false); } }; return (
게시글작성
제목
내용
작업 태그 설정
window.location.href = '/usr/4_noticeboard'} > 취소
{toastMessage && (
{toastMessage}
)}
) }