Commit 5135892d authored by Lee Soobeom's avatar Lee Soobeom
Browse files

debugging

parent 35f8698d
...@@ -17,7 +17,7 @@ export default function BoardPage() { ...@@ -17,7 +17,7 @@ export default function BoardPage() {
const location = useLocation() as Newpost; const location = useLocation() as Newpost;
const newPost = location.state; const newPost = location.state;
// console.log("get newPost Info", newPost); console.log("get newPost Info", newPost);
const setNewPosts = (newpost: PostType) => { const setNewPosts = (newpost: PostType) => {
const postArr = posts?.splice(-1, 0, newPost); const postArr = posts?.splice(-1, 0, newPost);
......
import React, { FormEvent, useState } from "react"; import React, { FormEvent, MouseEventHandler, useState } from "react";
import { useNavigate, useLocation } from "react-router-dom"; import { useNavigate, useLocation, Link } from "react-router-dom";
import isLength from "validator/lib/isLength"; import isLength from "validator/lib/isLength";
import equals from "validator/lib/equals"; import equals from "validator/lib/equals";
import { catchErrors } from "../helpers"; import { catchErrors } from "../helpers";
...@@ -65,8 +65,8 @@ export function EditPost() { ...@@ -65,8 +65,8 @@ export function EditPost() {
if (postingFormMatch(user) === true) { if (postingFormMatch(user) === true) {
setLoading(true); setLoading(true);
const res = updateImg2Db(file); const updateRes = await updateImg2Db(file);
navigate("/board", { replace: true }); navigate("/board", { replace: true, state: updateRes });
setSuccess(true); setSuccess(true);
setError(""); setError("");
...@@ -164,6 +164,12 @@ export function EditPost() { ...@@ -164,6 +164,12 @@ export function EditPost() {
setUser(newUser); setUser(newUser);
}; };
const GoBack = () => {
if (confirm("취소하시겠습니까?") == true) {
navigate(-1);
}
};
const oldFileShow = (post: PostType) => { const oldFileShow = (post: PostType) => {
const res = post.file?.map((file, i) => ( const res = post.file?.map((file, i) => (
<img <img
...@@ -185,90 +191,100 @@ export function EditPost() { ...@@ -185,90 +191,100 @@ export function EditPost() {
}; };
return ( return (
<form onSubmit={reWriteSubmit} className="flex flex-col w-full"> <div>
<div className="flex flex-row h-10 gap-x-1 justify-end"> <form onSubmit={reWriteSubmit} className="flex flex-col w-full">
<div className="place-self-center w-16 h-6 border-2 border-sky-400 transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-gray-300 duration-300"> <div className="flex flex-row h-10 gap-x-1 justify-end">
<input <div className="place-self-center w-16 h-6 border-2 border-sky-400 transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-gray-300 duration-300">
id="files" <input
type="file" id="files"
multiple type="file"
onChange={handleInputPic} multiple
className="hidden" onChange={handleInputPic}
/> className="hidden"
<label htmlFor="files" className="text-xs grid place-items-center"> />
파일 선택 <label htmlFor="files" className="text-xs grid place-items-center">
</label> 파일 선택
</div> </label>
</div>
<select <select
name="city" name="city"
className="border-2 border-sky-400 text-xs h-6 place-self-center" className="border-2 border-sky-400 text-xs h-6 place-self-center"
onChange={cityChange} onChange={cityChange}
defaultValue={post.city} defaultValue={post.city}
> >
<option value="city">도시</option> <option value="city">도시</option>
<option value="Seoul">서울</option> <option value="Seoul">서울</option>
<option value="Busan">부산</option> <option value="Busan">부산</option>
<option value="Incheon">인천</option> <option value="Incheon">인천</option>
<option value="Daegu">대구</option> <option value="Daegu">대구</option>
<option value="Gwangju">광주</option> <option value="Gwangju">광주</option>
<option value="Daejeon">대전</option> <option value="Daejeon">대전</option>
<option value="Woolsan">울산</option> <option value="Woolsan">울산</option>
<option value="Sejong">세종</option> <option value="Sejong">세종</option>
<option value="Dokdo">독도</option> <option value="Dokdo">독도</option>
<option value="Jeju">제주</option> <option value="Jeju">제주</option>
</select> </select>
<select <select
name="theme" name="theme"
className="border-2 border-sky-400 text-xs h-6 place-self-center" className="border-2 border-sky-400 text-xs h-6 place-self-center"
onChange={themeChange} onChange={themeChange}
defaultValue={post.theme} defaultValue={post.theme}
> >
<option value="theme">테마</option> <option value="theme">테마</option>
<option value="cycling">사이클링</option> <option value="cycling">사이클링</option>
<option value="surfing">서핑</option> <option value="surfing">서핑</option>
<option value="activity">액티비티</option> <option value="activity">액티비티</option>
<option value="camping">캠핑</option> <option value="camping">캠핑</option>
<option value="sking">스키</option> <option value="sking">스키</option>
<option value="boat">보트</option> <option value="boat">보트</option>
<option value="desert">사막</option> <option value="desert">사막</option>
<option value="golf">골프</option> <option value="golf">골프</option>
<option value="cave">동굴</option> <option value="cave">동굴</option>
<option value="history">문화재</option> <option value="history">문화재</option>
<option value="zoo">동물원</option> <option value="zoo">동물원</option>
<option value="cycling">사이클링</option> <option value="cycling">사이클링</option>
</select> </select>
<button <button
type="submit" type="submit"
className="h-6 w-10 place-self-center place-self-center border-2 border-sky-400 text-xs text-center transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-sky-300 duration-300" className="h-6 w-10 place-self-center place-self-center border-2 border-sky-400 text-xs text-center transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-sky-300 duration-300"
> >
수정 수정
</button> </button>
</div> </div>
<div className="flex flex-col w-full border-y-2 border-sky-500"> <div className="flex flex-col w-full border-y-2 border-sky-500">
<textarea <textarea
defaultValue={post.title} defaultValue={post.title}
name="title" name="title"
onChange={titleChange} onChange={titleChange}
placeholder="제목을 입력해 주세요!" placeholder="제목을 입력해 주세요!"
className="flex focus:outline-none" className="flex focus:outline-none"
/> />
<div className="flex flex-col mt-1 mb-1 border-t-2 border-sky-200"> <div className="flex flex-col mt-1 mb-1 border-t-2 border-sky-200">
<div className="flex gap-x-2 h-44 overflow-x-auto "> <div className="flex gap-x-2 h-44 overflow-x-auto ">
{change ? newFileShow(imgSrc) : oldFileShow(post)} {change ? newFileShow(imgSrc) : oldFileShow(post)}
</div>
</div> </div>
<textarea
defaultValue={post.text}
onChange={textChange}
name="text"
placeholder="여행 후기를 알려주세요!"
className="flex h-44 border-t-2 border-sky-200 focus:outline-none "
/>
</div> </div>
<textarea </form>
defaultValue={post.text} <div className="flex md:mb-20 justify-center">
onChange={textChange} <button
name="text" onClick={GoBack}
placeholder="여행 후기를 알려주세요!" className=" mt-5 h-12 w-40 text-lg border-2 border-sky-500 place-self-center"
className="flex h-44 border-t-2 border-sky-200 focus:outline-none " >
/> 취소
</button>
</div> </div>
</form> </div>
); );
} }
...@@ -13,6 +13,8 @@ export function IntoPost() { ...@@ -13,6 +13,8 @@ export function IntoPost() {
const post = location.state; const post = location.state;
const navigate = useNavigate(); const navigate = useNavigate();
console.log("user info", post.user);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [error, setError] = useState(""); const [error, setError] = useState("");
const [addSuccess, setAddSuccess] = useState(false); const [addSuccess, setAddSuccess] = useState(false);
...@@ -56,7 +58,7 @@ export function IntoPost() { ...@@ -56,7 +58,7 @@ export function IntoPost() {
<div className="flex h-10 items-center border-t-2 border-sky-200 md:flex-row justify-between bg-slate-50 text-sm"> <div className="flex h-10 items-center border-t-2 border-sky-200 md:flex-row justify-between bg-slate-50 text-sm">
<div className="flex whitespace-nowrap pr-5 "> <div className="flex whitespace-nowrap pr-5 ">
작성자: {post.user.slice(0, 8)} 작성자: {post.user.name}
</div> </div>
<div className="flex divide-x divide-slate-300 "> <div className="flex divide-x divide-slate-300 ">
......
import React, { FormEvent, useEffect, useState } from "react"; import React, { FormEvent, useEffect, useState } from "react";
import { useNavigate } from "react-router-dom"; import { useNavigate, Link } from "react-router-dom";
import isLength from "validator/lib/isLength"; import isLength from "validator/lib/isLength";
import equals from "validator/lib/equals"; import equals from "validator/lib/equals";
import { catchErrors } from "../helpers"; import { catchErrors } from "../helpers";
...@@ -21,11 +21,15 @@ export default function Posting() { ...@@ -21,11 +21,15 @@ export default function Posting() {
theme: "", theme: "",
city: "", city: "",
date: "", date: "",
user: "", user: {
_id: "",
name: "",
},
counts: 0, counts: 0,
_id: "", _id: "",
file: [ file: [
{ {
_id: "",
originalfilename: "", originalfilename: "",
newfilename: "", newfilename: "",
picturepath: "", picturepath: "",
...@@ -69,12 +73,10 @@ export default function Posting() { ...@@ -69,12 +73,10 @@ export default function Posting() {
try { try {
if (confirm("게시물을 작성하시겠습니까?") == true) { if (confirm("게시물을 작성하시겠습니까?") == true) {
setError(""); setError("");
// console.log("user data", user);
if (postingFormMatch(user, file)) { if (postingFormMatch(user, file)) {
setLoading(true); setLoading(true);
if (file) { if (file) {
const postRes = await sendImg2Db(file); const postRes = await sendImg2Db(file);
// console.log("Newpost Info", postRes);
navigate("/board", { replace: true, state: postRes }); navigate("/board", { replace: true, state: postRes });
} }
setSuccess(true); setSuccess(true);
...@@ -174,91 +176,107 @@ export default function Posting() { ...@@ -174,91 +176,107 @@ export default function Posting() {
} }
}; };
const GoBack = () => {
if (confirm("취소하시겠습니까?") == true) {
navigate(-1);
}
};
return ( return (
<form onSubmit={handlePostSubmit} className="flex flex-col w-full"> <div>
<div className="flex flex-row gap-x-1 justify-end h-10 "> <form onSubmit={handlePostSubmit} className="flex flex-col w-full">
<div className="place-self-center w-16 h-6 border-2 border-sky-400 transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-gray-300 duration-300"> <div className="flex flex-row gap-x-1 justify-end h-10 ">
<input <div className="place-self-center w-16 h-6 border-2 border-sky-400 transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-gray-300 duration-300">
id="files" <input
type="file" id="files"
multiple type="file"
onChange={handleInputPic} multiple
className="hidden" onChange={handleInputPic}
/> className="hidden"
<label htmlFor="files" className="text-xs grid place-items-center"> />
파일 선택 <label htmlFor="files" className="text-xs grid place-items-center">
</label> 파일 선택
</div> </label>
</div>
<select <select
name="city" name="city"
className="border-2 border-sky-400 text-xs h-6 place-self-center" className="border-2 border-sky-400 text-xs h-6 place-self-center"
onChange={cityChange} onChange={cityChange}
defaultValue="질문종류" defaultValue="질문종류"
> >
<option value="질문종류">도시</option> <option value="질문종류">도시</option>
<option value="Seoul">서울</option> <option value="Seoul">서울</option>
<option value="Busan">부산</option> <option value="Busan">부산</option>
<option value="Incheon">인천</option> <option value="Incheon">인천</option>
<option value="Daegu">대구</option> <option value="Daegu">대구</option>
<option value="Gwangju">광주</option> <option value="Gwangju">광주</option>
<option value="Daejeon">대전</option> <option value="Daejeon">대전</option>
<option value="Woolsan">울산</option> <option value="Woolsan">울산</option>
<option value="Sejong">세종</option> <option value="Sejong">세종</option>
<option value="Dokdo">독도</option> <option value="Dokdo">독도</option>
<option value="Jeju">제주</option> <option value="Jeju">제주</option>
</select> </select>
<select <select
name="theme" name="theme"
className="border-2 border-sky-400 text-xs h-6 place-self-center" className="border-2 border-sky-400 text-xs h-6 place-self-center"
onChange={themeChange} onChange={themeChange}
defaultValue="질문종류" defaultValue="질문종류"
> >
<option value="질문종류">테마</option> <option value="질문종류">테마</option>
<option value="cycling">사이클링</option> <option value="cycling">사이클링</option>
<option value="surfing">서핑</option> <option value="surfing">서핑</option>
<option value="activity">액티비티</option> <option value="activity">액티비티</option>
<option value="camping">캠핑</option> <option value="camping">캠핑</option>
<option value="sking">스키</option> <option value="sking">스키</option>
<option value="boat">보트</option> <option value="boat">보트</option>
<option value="desert">사막</option> <option value="desert">사막</option>
<option value="golf">골프</option> <option value="golf">골프</option>
<option value="cave">동굴</option> <option value="cave">동굴</option>
<option value="history">문화재</option> <option value="history">문화재</option>
<option value="zoo">동물원</option> <option value="zoo">동물원</option>
<option value="cycling">사이클링</option> <option value="cycling">사이클링</option>
</select> </select>
<button <button
type="submit" type="submit"
className="h-6 place-self-center place-self-center border-2 border-sky-400 text-xs text-center transition ease-in-out delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-sky-300 duration-300" className="h-6 place-self-center place-self-center border-2 border-sky-400 text-xs text-center transition ease-in-out delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-sky-300 duration-300"
> >
글쓰기 글쓰기
</button> </button>
</div> </div>
<div className="flex flex-col w-full border-y-2 border-sky-500"> <div className="flex flex-col w-full border-y-2 border-sky-500">
<textarea <textarea
name="title" name="title"
onChange={titleChange} onChange={titleChange}
placeholder="제목을 입력해 주세요!" placeholder="제목을 입력해 주세요!"
className="flex focus:outline-none" className="flex focus:outline-none"
/> />
<div className="flex flex-col mt-1 mb-1 border-t-2 border-sky-200"> <div className="flex flex-col mt-1 mb-1 border-t-2 border-sky-200">
<div className="flex gap-x-2 h-44 overflow-x-auto"> <div className="flex gap-x-2 h-44 overflow-x-auto">
{imgSrc?.map((img, i) => ( {imgSrc?.map((img, i) => (
<img key={i} src={img} width={200} height={200} /> <img key={i} src={img} width={200} height={200} />
))} ))}
</div>
</div> </div>
<textarea
onChange={textChange}
name="text"
placeholder="여행 후기를 알려주세요!"
className="flex h-44 border-t-2 border-sky-200 focus:outline-none "
/>
</div> </div>
<textarea </form>
onChange={textChange} <div className="flex md:mb-20 justify-center">
name="text" <button
placeholder="여행 후기를 알려주세요!" onClick={GoBack}
className="flex h-44 border-t-2 border-sky-200 focus:outline-none " className=" mt-5 h-12 w-40 text-lg border-2 border-sky-500 place-self-center"
/> >
취소
</button>
</div> </div>
</form> </div>
); );
} }
...@@ -20,9 +20,13 @@ export interface PostType { ...@@ -20,9 +20,13 @@ export interface PostType {
date: string; date: string;
counts: number; counts: number;
_id: string; _id: string;
user: string; user: {
_id: string;
name: string;
};
file: [ file: [
{ {
_id: string;
originalfilename: string; originalfilename: string;
newfilename: string; newfilename: string;
picturepath: string; picturepath: string;
......
...@@ -22,6 +22,7 @@ export const authenticate = asyncWrap( ...@@ -22,6 +22,7 @@ export const authenticate = asyncWrap(
if (req.auth) { if (req.auth) {
const { userId } = req.auth; const { userId } = req.auth;
const user = req.user; const user = req.user;
// const adminId =
if (user && user.id === userId) { if (user && user.id === userId) {
return next(); return next();
} else { } else {
......
...@@ -18,7 +18,7 @@ export const userByPostId = ( ...@@ -18,7 +18,7 @@ export const userByPostId = (
next(); next();
}; };
export const subTract = (oldSet: Set<string>, newSet: Set<string>) => { export const SubTract = (oldSet: Set<string>, newSet: Set<string>) => {
const keep = new Array<string>(); //유지 const keep = new Array<string>(); //유지
const drop = new Array<string>(); //삭제 const drop = new Array<string>(); //삭제
const add = new Array<string>(); //추가 const add = new Array<string>(); //추가
...@@ -234,7 +234,7 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => { ...@@ -234,7 +234,7 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
console.log("NewSet", newSet); console.log("NewSet", newSet);
//유지, 삭제, 추가 구분하기 //유지, 삭제, 추가 구분하기
const trdPart = subTract(oldSet, newSet); const trdPart = SubTract(oldSet, newSet);
console.log("keep", trdPart.keep); console.log("keep", trdPart.keep);
console.log("drop", trdPart.drop); console.log("drop", trdPart.drop);
...@@ -294,7 +294,7 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => { ...@@ -294,7 +294,7 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
console.log("NewSet", newSet); console.log("NewSet", newSet);
//유지, 삭제, 추가 구분하기 //유지, 삭제, 추가 구분하기
const trdPart = subTract(oldSet, newSet); const trdPart = SubTract(oldSet, newSet);
//삭제 //삭제
for (var i = 0; i < trdPart.drop.length; i++) { for (var i = 0; i < trdPart.drop.length; i++) {
......
...@@ -34,8 +34,11 @@ export const createFilesRow = async ( ...@@ -34,8 +34,11 @@ export const createFilesRow = async (
//Read //Read
export const getPosts = async () => { export const getPosts = async () => {
const posts = await Post.find().populate("file").sort({ date: -1 }); const posts = await Post.find()
console.log(posts); .populate("file")
.populate("user")
.sort({ date: -1 });
console.log("file nickname", posts);
return posts; return posts;
}; };
......
...@@ -4,13 +4,11 @@ export interface IFileInfo { ...@@ -4,13 +4,11 @@ export interface IFileInfo {
originalfilename: string; originalfilename: string;
newfilename: string; newfilename: string;
picturepath: string; picturepath: string;
nickname?: string;
} }
const schema = new Schema<IFileInfo>({ const schema = new Schema<IFileInfo>({
originalfilename: { type: String, unique: true }, originalfilename: { type: String, unique: true },
newfilename: { type: String }, newfilename: { type: String },
nickname: { type: String },
picturepath: { type: String }, picturepath: { type: String },
}); });
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment