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

debugging

parent 35f8698d
......@@ -17,7 +17,7 @@ export default function BoardPage() {
const location = useLocation() as Newpost;
const newPost = location.state;
// console.log("get newPost Info", newPost);
console.log("get newPost Info", newPost);
const setNewPosts = (newpost: PostType) => {
const postArr = posts?.splice(-1, 0, newPost);
......
import React, { FormEvent, useState } from "react";
import { useNavigate, useLocation } from "react-router-dom";
import React, { FormEvent, MouseEventHandler, useState } from "react";
import { useNavigate, useLocation, Link } from "react-router-dom";
import isLength from "validator/lib/isLength";
import equals from "validator/lib/equals";
import { catchErrors } from "../helpers";
......@@ -65,8 +65,8 @@ export function EditPost() {
if (postingFormMatch(user) === true) {
setLoading(true);
const res = updateImg2Db(file);
navigate("/board", { replace: true });
const updateRes = await updateImg2Db(file);
navigate("/board", { replace: true, state: updateRes });
setSuccess(true);
setError("");
......@@ -164,6 +164,12 @@ export function EditPost() {
setUser(newUser);
};
const GoBack = () => {
if (confirm("취소하시겠습니까?") == true) {
navigate(-1);
}
};
const oldFileShow = (post: PostType) => {
const res = post.file?.map((file, i) => (
<img
......@@ -185,6 +191,7 @@ export function EditPost() {
};
return (
<div>
<form onSubmit={reWriteSubmit} className="flex flex-col w-full">
<div className="flex flex-row h-10 gap-x-1 justify-end">
<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">
......@@ -270,5 +277,14 @@ export function EditPost() {
/>
</div>
</form>
<div className="flex md:mb-20 justify-center">
<button
onClick={GoBack}
className=" mt-5 h-12 w-40 text-lg border-2 border-sky-500 place-self-center"
>
취소
</button>
</div>
</div>
);
}
......@@ -13,6 +13,8 @@ export function IntoPost() {
const post = location.state;
const navigate = useNavigate();
console.log("user info", post.user);
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
const [addSuccess, setAddSuccess] = useState(false);
......@@ -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 whitespace-nowrap pr-5 ">
작성자: {post.user.slice(0, 8)}
작성자: {post.user.name}
</div>
<div className="flex divide-x divide-slate-300 ">
......
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 equals from "validator/lib/equals";
import { catchErrors } from "../helpers";
......@@ -21,11 +21,15 @@ export default function Posting() {
theme: "",
city: "",
date: "",
user: "",
user: {
_id: "",
name: "",
},
counts: 0,
_id: "",
file: [
{
_id: "",
originalfilename: "",
newfilename: "",
picturepath: "",
......@@ -69,12 +73,10 @@ export default function Posting() {
try {
if (confirm("게시물을 작성하시겠습니까?") == true) {
setError("");
// console.log("user data", user);
if (postingFormMatch(user, file)) {
setLoading(true);
if (file) {
const postRes = await sendImg2Db(file);
// console.log("Newpost Info", postRes);
navigate("/board", { replace: true, state: postRes });
}
setSuccess(true);
......@@ -174,7 +176,14 @@ export default function Posting() {
}
};
const GoBack = () => {
if (confirm("취소하시겠습니까?") == true) {
navigate(-1);
}
};
return (
<div>
<form onSubmit={handlePostSubmit} className="flex flex-col w-full">
<div className="flex flex-row gap-x-1 justify-end h-10 ">
<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">
......@@ -260,5 +269,14 @@ export default function Posting() {
/>
</div>
</form>
<div className="flex md:mb-20 justify-center">
<button
onClick={GoBack}
className=" mt-5 h-12 w-40 text-lg border-2 border-sky-500 place-self-center"
>
취소
</button>
</div>
</div>
);
}
......@@ -20,9 +20,13 @@ export interface PostType {
date: string;
counts: number;
_id: string;
user: string;
user: {
_id: string;
name: string;
};
file: [
{
_id: string;
originalfilename: string;
newfilename: string;
picturepath: string;
......
......@@ -22,6 +22,7 @@ export const authenticate = asyncWrap(
if (req.auth) {
const { userId } = req.auth;
const user = req.user;
// const adminId =
if (user && user.id === userId) {
return next();
} else {
......
......@@ -18,7 +18,7 @@ export const userByPostId = (
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 drop = new Array<string>(); //삭제
const add = new Array<string>(); //추가
......@@ -234,7 +234,7 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
console.log("NewSet", newSet);
//유지, 삭제, 추가 구분하기
const trdPart = subTract(oldSet, newSet);
const trdPart = SubTract(oldSet, newSet);
console.log("keep", trdPart.keep);
console.log("drop", trdPart.drop);
......@@ -294,7 +294,7 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
console.log("NewSet", newSet);
//유지, 삭제, 추가 구분하기
const trdPart = subTract(oldSet, newSet);
const trdPart = SubTract(oldSet, newSet);
//삭제
for (var i = 0; i < trdPart.drop.length; i++) {
......
......@@ -34,8 +34,11 @@ export const createFilesRow = async (
//Read
export const getPosts = async () => {
const posts = await Post.find().populate("file").sort({ date: -1 });
console.log(posts);
const posts = await Post.find()
.populate("file")
.populate("user")
.sort({ date: -1 });
console.log("file nickname", posts);
return posts;
};
......
......@@ -4,13 +4,11 @@ export interface IFileInfo {
originalfilename: string;
newfilename: string;
picturepath: string;
nickname?: string;
}
const schema = new Schema<IFileInfo>({
originalfilename: { type: String, unique: true },
newfilename: { type: String },
nickname: { 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