import React, { MouseEvent, useEffect, useState } from "react"; import { useLocation, useNavigate, Link, Outlet } from "react-router-dom"; import { catchErrors } from "../helpers"; import { postApi } from "../apis"; import { PostType } from "../types"; export interface PostState { state: PostType; } export interface FileType { id: string; post: string; originalfilename: string; newfilename: string; picturepath: string; } export interface FilesList { filesList: FileType[]; } export function IntoPost() { const location = useLocation() as PostState; const post = location.state; const navigate = useNavigate(); const [filesList, setFilesList] = useState(); // console.log(post); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const [addSuccess, setAddSuccess] = useState(false); const [delSuccess, setDelSuccess] = useState(false); useEffect(() => { getFilesList(post._id); }, []); const getFilesList = async (postId: string) => { const res = await postApi.getFileByPostId(postId); setFilesList(res); }; const handleDeleteClick = async (event: MouseEvent) => { try { if (confirm("삭제하시겠습니까?") == true) { const postId = event.currentTarget.id; const res = await postApi.deletePost(postId); navigate("/board", { replace: true }); console.log("delete post", res); } else { return false; } } catch (error) { console.log("에러발생"); catchErrors(error, setError); } }; return (
{post.title}
작성자: {post.user.slice(0, 8)}
작성일 : {post.date.slice(0, 10)}
{post.city}
{post.theme}
조회수 : {post.counts}
{filesList?.map((file, i) => ( ))}
{post.text}
); }