Commit 2b496d1c authored by Lee Soobeom's avatar Lee Soobeom
Browse files

css 수정

parent 89ceb5ae
...@@ -37,7 +37,14 @@ export const App = () => { ...@@ -37,7 +37,14 @@ export const App = () => {
</RequireAuth> </RequireAuth>
} }
/> />
<Route path="admin" element={<RequireAuth><Admin /></RequireAuth>} /> <Route
path="admin"
element={
<RequireAuth>
<Admin />
</RequireAuth>
}
/>
<Route path="admin/:imgId" element={<ImgRewrite />} /> <Route path="admin/:imgId" element={<ImgRewrite />} />
<Route path="rewrite" element={<ImgRewrite />} /> <Route path="rewrite" element={<ImgRewrite />} />
</Route> </Route>
......
...@@ -46,7 +46,7 @@ export function MySlide({ slides }: num) { ...@@ -46,7 +46,7 @@ export function MySlide({ slides }: num) {
&lt; &lt;
</button> </button>
<div <div
className={`m-3 md:m-5 md:basis-4/5 flex flex-row relative w-full overflow-hidden`} className={`m-3 md:m-5 md:basis-4/5 flex flex-row w-full overflow-hidden`}
> >
{slides.slice(page - 1, page + 2).map((slide) => ( {slides.slice(page - 1, page + 2).map((slide) => (
<div key={Math.random()} className="min-w-full"> <div key={Math.random()} className="min-w-full">
......
...@@ -113,7 +113,7 @@ export default function Admin() { ...@@ -113,7 +113,7 @@ export default function Admin() {
.slice(i * limit, i * limit + limit) .slice(i * limit, i * limit + limit)
.map((picture, index: number) => ( .map((picture, index: number) => (
<div key={index}> <div key={index}>
<div className={`m-1 shrink-0 bg-gray-200 rounded shadow-md `}> <div className={`m-1 shrink-0 bg-white rounded shadow-md `}>
<img <img
src={ src={
"http://localhost:3000/images/" + picture.fileInfo.newfilename "http://localhost:3000/images/" + picture.fileInfo.newfilename
...@@ -122,8 +122,8 @@ export default function Admin() { ...@@ -122,8 +122,8 @@ export default function Admin() {
/> />
<p className="text-center text-xs">{picture.title}</p> <p className="text-center text-xs">{picture.title}</p>
</div> </div>
<div className="text-end"> <div className="text-center">
<button className="border-r-2 border-r-indigo-500 text-xs"> <button className="border-r-2 border-r-indigo-500 px-3 text-xs md:text-m">
<Link to={`/admin/${picture._id}`} state={picture}> <Link to={`/admin/${picture._id}`} state={picture}>
수정 수정
</Link> </Link>
...@@ -131,7 +131,7 @@ export default function Admin() { ...@@ -131,7 +131,7 @@ export default function Admin() {
<button <button
id={picture._id} id={picture._id}
onClick={handleDeleteClick} onClick={handleDeleteClick}
className="text-xs" className="text-xs md:text-m px-3"
> >
삭제 삭제
</button> </button>
...@@ -145,7 +145,7 @@ export default function Admin() { ...@@ -145,7 +145,7 @@ export default function Admin() {
return ( return (
<div> <div>
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
<div className="flex flex-wrap justify-center gap-3"> <div className="flex flex-wrap justify-center gap-3 bg-white md:shadow-lg rounded">
<div className="gap-3 md:flex "> <div className="gap-3 md:flex ">
<select <select
name="city" name="city"
...@@ -187,18 +187,18 @@ export default function Admin() { ...@@ -187,18 +187,18 @@ export default function Admin() {
<option value="zoo">동물원</option> <option value="zoo">동물원</option>
<option value="cycling">사이클링</option> <option value="cycling">사이클링</option>
</select> </select>
<div className="flex items-center justify-end gap-3"> <div className="flex items-center md:justify-end gap-3">
<input <input
type="file" type="file"
id="files" id="files"
className="hidden" className="hidden"
onChange={handleFileChange} onChange={handleFileChange}
></input> ></input>
<label htmlFor="files" className="border-2 m-5"> <label htmlFor="files" className="border-2 md:m-5">
이미지 선택 이미지 선택
</label> </label>
</div> </div>
<div className="flex items-center justify-end gap-3 mt-2 md:mt-0"> <div className="flex items-center md:justify-end gap-3 mt-2 md:mt-0">
<p>title :</p> <p>title :</p>
<input <input
name="title" name="title"
...@@ -215,6 +215,7 @@ export default function Admin() { ...@@ -215,6 +215,7 @@ export default function Admin() {
<div className="flex justify-center"> <div className="flex justify-center">
<MySlide key={Math.random()} slides={slides} /> <MySlide key={Math.random()} slides={slides} />
</div> </div>
<div className="bg-lime-100 h-48" />
</div> </div>
); );
} }
...@@ -6,7 +6,6 @@ import equals from "validator/lib/equals"; ...@@ -6,7 +6,6 @@ import equals from "validator/lib/equals";
import { catchErrors } from "../helpers"; import { catchErrors } from "../helpers";
import { MainimgType } from "../types"; import { MainimgType } from "../types";
export interface ImgState { export interface ImgState {
state: MainimgType; state: MainimgType;
} }
...@@ -30,7 +29,7 @@ export default function ImgRewrite() { ...@@ -30,7 +29,7 @@ export default function ImgRewrite() {
fileInfo: { originalfilename: "", newfilename: "" }, fileInfo: { originalfilename: "", newfilename: "" },
}); });
useEffect(() => { useEffect(() => {
console.log("수정 전 : ",imgdata); console.log("수정 전 : ", imgdata);
}, []); }, []);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
...@@ -63,44 +62,28 @@ export default function ImgRewrite() { ...@@ -63,44 +62,28 @@ export default function ImgRewrite() {
async function reWriteSubmit(event: FormEvent) { async function reWriteSubmit(event: FormEvent) {
event.preventDefault(); event.preventDefault();
if (confirm("수정하시겠습니까?") == true) { if (confirm("수정하시겠습니까?") == true) {
// try {
setError(""); setError("");
console.log("user data", imgdata); console.log("user data", imgdata);
// if (infoFormMatch(imgdata) === true) {
// setLoading(true);
// const res = await mainimgApi.updating(imgdata);
// console.log("clear", res);
// navigate("/admin", { replace: true });
// setSuccess(true);
// setError("");
const formdata = new FormData(); const formdata = new FormData();
formdata.append("id", imgdata._id) formdata.append("id", imgdata._id);
console.log(imgdata._id) console.log(imgdata._id);
formdata.append("city", imgdata.city); formdata.append("city", imgdata.city);
formdata.append("theme", imgdata.theme); formdata.append("theme", imgdata.theme);
formdata.append("title", imgdata.title); formdata.append("title", imgdata.title);
console.log(formdata) console.log(formdata);
if (!(file === undefined)) { if (!(file === undefined)) {
formdata.append("updatemainimg", file); formdata.append("updatemainimg", file);
console.log("formdata", formdata); console.log("formdata", formdata);
const res = await mainimgApi.updateimg(formdata,imgdata._id); const res = await mainimgApi.updateimg(formdata, imgdata._id);
navigate("/admin", { replace: true }); navigate("/admin", { replace: true });
console.log("확인 중 ", res); console.log("확인 중 ", res);
} } else {
else { formdata.append("updatemainimg", "");
formdata.append("updatemainimg",""); console.log("formdata", formdata);
console.log("formdata",formdata); const res = await mainimgApi.updateimg(formdata, imgdata._id);
const res = await mainimgApi.updateimg(formdata,imgdata._id);
navigate("/admin", { replace: true }); navigate("/admin", { replace: true });
console.log("확인 중 ", res); console.log("확인 중 ", res);
} }
// }
// } catch (error) {
// console.log("에러발생");
// catchErrors(error, setError);
// } finally {
// setLoading(false);
// }
} else { } else {
return false; return false;
} }
...@@ -124,7 +107,6 @@ export default function ImgRewrite() { ...@@ -124,7 +107,6 @@ export default function ImgRewrite() {
} }
} }
const cityChange = (event: React.ChangeEvent<HTMLSelectElement>) => { const cityChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
const city = event.currentTarget.value; const city = event.currentTarget.value;
const newUser = { ...imgdata, city: city }; const newUser = { ...imgdata, city: city };
...@@ -150,20 +132,22 @@ export default function ImgRewrite() { ...@@ -150,20 +132,22 @@ export default function ImgRewrite() {
const fileChange = (event: React.ChangeEvent<HTMLInputElement>) => { const fileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const url = event.currentTarget.value; const url = event.currentTarget.value;
const newUser = { ...imgdata, pic: { originalfilename: "", newfilename: url } }; const newUser = {
...imgdata,
pic: { originalfilename: "", newfilename: url },
};
setUrl(event.currentTarget.value); setUrl(event.currentTarget.value);
setImgData(newUser); setImgData(newUser);
}; };
return ( return (
<div> <div>
<form onSubmit={reWriteSubmit} className="px-10 md:px-40"> <div className="bg-white md:shadow-lg rounded py-24">
<table className="w-full "> <form onSubmit={reWriteSubmit} className="px-3 md:px-25">
<table className="m-auto">
<thead></thead> <thead></thead>
<tbody className=" border-separate border border-slate-400 "> <tbody>
<tr > <tr>
<td className="border border-slate-300 min-w-max"> <td className="border border-slate-300 px-5">도시이름</td>
도시이름
</td>
<td> <td>
<select <select
name="city" name="city"
...@@ -186,7 +170,7 @@ export default function ImgRewrite() { ...@@ -186,7 +170,7 @@ export default function ImgRewrite() {
</td> </td>
</tr> </tr>
<tr> <tr>
<td className="border border-slate-300 min-w-max"> <td className="border border-slate-300 min-w-max px-5">
테마이름 테마이름
</td> </td>
<td> <td>
...@@ -212,10 +196,8 @@ export default function ImgRewrite() { ...@@ -212,10 +196,8 @@ export default function ImgRewrite() {
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr className="items-center border border-slate-300">
<td className="border border-slate-300"> <td className="min-w-max px-7">이미지</td>
url
</td>
<td> <td>
<input <input
type="file" type="file"
...@@ -223,7 +205,7 @@ export default function ImgRewrite() { ...@@ -223,7 +205,7 @@ export default function ImgRewrite() {
className="hidden" className="hidden"
onChange={onUploadFile} onChange={onUploadFile}
></input> ></input>
<label htmlFor="files" className="border-2 m-5" > <label htmlFor="files" className="border-2">
이미지 선택 이미지 선택
</label> </label>
{imageSrc ? ( {imageSrc ? (
...@@ -233,18 +215,22 @@ export default function ImgRewrite() { ...@@ -233,18 +215,22 @@ export default function ImgRewrite() {
/> />
) : ( ) : (
<img <img
src={"http://localhost:3000/images/" + img.fileInfo.newfilename} src={
className="object-cover object-center h-full" "http://localhost:3000/images/" +
img.fileInfo.newfilename
}
className="object-cover object-center max-w-lg max-h-36"
/> />
)} )}
</td> </td>
</tr> </tr>
<tr> <tr>
<td className="border border-slate-300"> <td className="border border-slate-300 min-w-max px-9">
title title
</td> </td>
<td> <td>
<input className="border-2 border-sky-500 rounded w-full" <input
className="border-2 border-sky-500 rounded w-full"
onChange={titleChange} onChange={titleChange}
defaultValue={img.title} defaultValue={img.title}
/> />
...@@ -252,18 +238,21 @@ export default function ImgRewrite() { ...@@ -252,18 +238,21 @@ export default function ImgRewrite() {
</tr> </tr>
</tbody> </tbody>
</table> </table>
<div className="text-end"> <div className="text-center pt-10 whitespace-nowrap">
<button type="submit" className="border-2"> <button
type="submit"
className="border-2 sm:mr-3 md:mr-10 md:text-lg"
>
수정 수정
</button> </button>
<button className="border-2"> <button className="border-2 sm:mr-3 md:mr-10 md:text-lg">
<Link to={`/admin`}> <Link to={`/admin`}>취소</Link>
취소
</Link>
</button> </button>
</div> </div>
</form> </form>
<Outlet /> {/* <Outlet /> */}
</div>
<div className="bg-lime-100 h-12" />
</div> </div>
); );
}; }
...@@ -49,13 +49,13 @@ export default function Login() { ...@@ -49,13 +49,13 @@ export default function Login() {
return ( return (
<div className="flex flex-col items-center my-10"> <div className="flex flex-col items-center my-10">
<div className="bg-white w-1/2 md:w-1/3 my-8 text-center text-2xl"> <div className="w-1/2 md:w-1/3 my-8 text-center text-2xl font-semibold">
<Link to="/">로그인</Link> <Link to="/">로그인</Link>
</div> </div>
<div className="flex flex-col w-full md:w-3/5 p-8 md:p-4"> <div className="flex flex-col w-full md:w-3/5 p-8 md:p-4">
<form <form
onSubmit={handleSubmit} onSubmit={handleSubmit}
className="flex flex-col md:flex-row md:justify-around border-2 border-black rounded-xl p-8 gap-y-4" className="flex flex-col bg-white md:flex-row md:justify-around border-2 border-black rounded-xl p-8 gap-y-4"
> >
<div className="flex flex-col md:w-2/3 gap-2"> <div className="flex flex-col md:w-2/3 gap-2">
<input <input
...@@ -101,12 +101,13 @@ export default function Login() { ...@@ -101,12 +101,13 @@ export default function Login() {
</div> </div>
)} )}
<div className="flex justify-around m-4"> <div className="flex justify-around m-4">
<button className="bg-white "> <button>
<Link to="/signup">회원가입</Link> <Link to="/signup">회원가입</Link>
</button> </button>
</div> </div>
</div> </div>
</div> </div>
<div className="bg-lime-100 h-36" />
</div> </div>
); );
} }
...@@ -68,6 +68,7 @@ export default function Profile() { ...@@ -68,6 +68,7 @@ export default function Profile() {
}, []); }, []);
return ( return (
<div>
<div className="grid bg-white rounded shadow-lg mb-5"> <div className="grid bg-white rounded shadow-lg mb-5">
<form className="mx-24 " onSubmit={handleSubmit}> <form className="mx-24 " onSubmit={handleSubmit}>
<div className=" mt-7 text-2xl">프로필 수정</div> <div className=" mt-7 text-2xl">프로필 수정</div>
...@@ -154,5 +155,7 @@ export default function Profile() { ...@@ -154,5 +155,7 @@ export default function Profile() {
</div> </div>
</form> </form>
</div> </div>
<div className="bg-lime-100 h-4" />
</div>
); );
} }
...@@ -68,15 +68,16 @@ export default function Signup() { ...@@ -68,15 +68,16 @@ export default function Signup() {
} }
return ( return (
<div className="flex flex-col"> <div>
<div className="flex place-items-strat ml-2 mt-8 text-center text-2xl "> <div className="flex flex-col shadow-lg bg-white rounded">
<div className="grid place-items-center ml-2 mt-8 text-center text-2xl ">
<Link to="/">회원가입</Link> <Link to="/">회원가입</Link>
</div> </div>
<form onSubmit={handleSubmit} className="flex flex-col mt-16 gap-y-4"> <form onSubmit={handleSubmit} className="flex flex-col mt-16 gap-y-4">
<div className="flex flex-col "> <div className="flex flex-col px-32 pb-5">
<div className="border-0 border-y-2 border-black"> <div className="border-0 border-y-2 border-black">
<div className="h-16 flex "> <div className="h-16 flex">
<div className="whitespace-nowrap grid place-items-center w-32 lg:basis-1/5 shrink-0 border-0 border-r-2"> <div className="whitespace-nowrap grid place-items-center w-32 lg:basis-1/5 shrink-0 border-0 border-r-2">
이름 이름
</div> </div>
...@@ -149,5 +150,7 @@ export default function Signup() { ...@@ -149,5 +150,7 @@ export default function Signup() {
</div> </div>
</form> </form>
</div> </div>
<div className="bg-lime-100 h-36" />
</div>
); );
} }
...@@ -41,6 +41,10 @@ export default function BoardPage() { ...@@ -41,6 +41,10 @@ export default function BoardPage() {
}; };
const titleHandleClick = async (event: MouseEvent<HTMLButtonElement>) => { const titleHandleClick = async (event: MouseEvent<HTMLButtonElement>) => {
if (!user.isLoggedIn) {
alert("로그인이 필요합니다.");
navigate("/login", { replace: true });
} else {
const postId = event.currentTarget.id; const postId = event.currentTarget.id;
const newpost = posts?.find((element) => { const newpost = posts?.find((element) => {
if (element._id === postId) { if (element._id === postId) {
...@@ -53,6 +57,7 @@ export default function BoardPage() { ...@@ -53,6 +57,7 @@ export default function BoardPage() {
// console.log(res); // console.log(res);
setPosts(res); setPosts(res);
} }
}
}; };
const GoLogin = async (event: React.MouseEvent) => { const GoLogin = async (event: React.MouseEvent) => {
......
...@@ -96,6 +96,7 @@ export default function Body() { ...@@ -96,6 +96,7 @@ export default function Body() {
</div> </div>
</div> </div>
<Outlet /> <Outlet />
<div className="bg-lime-100 h-16" />
</div> </div>
// Body Page // Body Page
); );
......
...@@ -14,7 +14,7 @@ export default function Header() { ...@@ -14,7 +14,7 @@ export default function Header() {
}; };
// bg-gradient-to-t from-sky-200 // bg-gradient-to-t from-sky-200
return ( return (
<div className="flex flex-col bg-lime-100"> <div className="flex flex-col bg-lime-100 ">
<div className="flex flex-col md:px-14 lg:px-52 z-10 "> <div className="flex flex-col md:px-14 lg:px-52 z-10 ">
<div className="flex flex-col-reverse pt-3 pb-12 "> <div className="flex flex-col-reverse pt-3 pb-12 ">
<div className="flex mt-5 justify-between pr-3"> <div className="flex mt-5 justify-between pr-3">
...@@ -85,6 +85,7 @@ export default function Header() { ...@@ -85,6 +85,7 @@ export default function Header() {
<Outlet /> <Outlet />
</div> </div>
<div className="bg-right bg-cover z-0 absolute w-full h-44 overflow-hidden object-cover object-center bg-[url('https://a-static.besthdwallpaper.com/seom-punggyeong-ilreoseuteu-byeogji-3840x1200-81006_62.jpg')]"></div> <div className="bg-right bg-cover z-0 absolute w-full h-44 overflow-hidden object-cover object-center bg-[url('https://a-static.besthdwallpaper.com/seom-punggyeong-ilreoseuteu-byeogji-3840x1200-81006_62.jpg')]"></div>
<div className="bg-lime-100 h-12" />
</div> </div>
); );
} }
...@@ -7,7 +7,7 @@ type ThemeProps = { ...@@ -7,7 +7,7 @@ type ThemeProps = {
export default function Theme({ handleClick }: ThemeProps) { export default function Theme({ handleClick }: ThemeProps) {
const [active, setActive] = useState(0); const [active, setActive] = useState(0);
const onactive = "whitespace-nowrap px-5 text-sky-300 "; const onactive = "whitespace-nowrap px-5 text-lime-500 ";
const offactive = "whitespace-nowrap px-5 "; const offactive = "whitespace-nowrap px-5 ";
const clickActive = (a: number) => { const clickActive = (a: number) => {
...@@ -16,7 +16,7 @@ export default function Theme({ handleClick }: ThemeProps) { ...@@ -16,7 +16,7 @@ export default function Theme({ handleClick }: ThemeProps) {
return ( return (
<div className=" overflow-x-auto flex rounded py-2 md:py-4 md:pl-3 shadow-lg divide-x-2 bg-white"> <div className=" overflow-x-auto flex rounded py-2 md:py-4 md:pl-3 shadow-lg divide-x-2 bg-white">
<div onClick={() => clickActive(1)}> <div onClick={() => clickActive(1)} className="px-0 md:px-2">
<button <button
id={"surfing"} id={"surfing"}
onClick={handleClick} onClick={handleClick}
...@@ -25,7 +25,7 @@ export default function Theme({ handleClick }: ThemeProps) { ...@@ -25,7 +25,7 @@ export default function Theme({ handleClick }: ThemeProps) {
서핑 서핑
</button> </button>
</div> </div>
<div onClick={() => clickActive(2)}> <div onClick={() => clickActive(2)} className="px-0 md:px-2">
<button <button
id={"activity"} id={"activity"}
onClick={handleClick} onClick={handleClick}
...@@ -34,7 +34,7 @@ export default function Theme({ handleClick }: ThemeProps) { ...@@ -34,7 +34,7 @@ export default function Theme({ handleClick }: ThemeProps) {
액티비티 액티비티
</button> </button>
</div> </div>
<div onClick={() => clickActive(3)}> <div onClick={() => clickActive(3)} className="px-0 md:px-2">
<button <button
id={"camping"} id={"camping"}
onClick={handleClick} onClick={handleClick}
...@@ -43,7 +43,7 @@ export default function Theme({ handleClick }: ThemeProps) { ...@@ -43,7 +43,7 @@ export default function Theme({ handleClick }: ThemeProps) {
캠핑 캠핑
</button> </button>
</div> </div>
<div onClick={() => clickActive(4)}> <div onClick={() => clickActive(4)} className="px-0 md:px-2">
<button <button
id={"skiing"} id={"skiing"}
onClick={handleClick} onClick={handleClick}
...@@ -52,7 +52,7 @@ export default function Theme({ handleClick }: ThemeProps) { ...@@ -52,7 +52,7 @@ export default function Theme({ handleClick }: ThemeProps) {
스키 스키
</button> </button>
</div> </div>
<div onClick={() => clickActive(5)}> <div onClick={() => clickActive(5)} className="px-0 md:px-2">
<button <button
id={"boat"} id={"boat"}
onClick={handleClick} onClick={handleClick}
...@@ -61,7 +61,7 @@ export default function Theme({ handleClick }: ThemeProps) { ...@@ -61,7 +61,7 @@ export default function Theme({ handleClick }: ThemeProps) {
보트 보트
</button> </button>
</div> </div>
<div onClick={() => clickActive(6)}> <div onClick={() => clickActive(6)} className="px-0 md:px-2">
<button <button
id={"desert"} id={"desert"}
onClick={handleClick} onClick={handleClick}
...@@ -70,7 +70,7 @@ export default function Theme({ handleClick }: ThemeProps) { ...@@ -70,7 +70,7 @@ export default function Theme({ handleClick }: ThemeProps) {
사막 사막
</button> </button>
</div> </div>
<div onClick={() => clickActive(7)}> <div onClick={() => clickActive(7)} className="px-0 md:px-2">
<button <button
id={"golf"} id={"golf"}
onClick={handleClick} onClick={handleClick}
...@@ -79,7 +79,7 @@ export default function Theme({ handleClick }: ThemeProps) { ...@@ -79,7 +79,7 @@ export default function Theme({ handleClick }: ThemeProps) {
골프 골프
</button> </button>
</div> </div>
<div onClick={() => clickActive(8)}> <div onClick={() => clickActive(8)} className="px-0 md:px-2">
<button <button
id={"cave"} id={"cave"}
onClick={handleClick} onClick={handleClick}
...@@ -88,7 +88,7 @@ export default function Theme({ handleClick }: ThemeProps) { ...@@ -88,7 +88,7 @@ export default function Theme({ handleClick }: ThemeProps) {
동굴 동굴
</button> </button>
</div> </div>
<div onClick={() => clickActive(9)}> <div onClick={() => clickActive(9)} className="px-0 md:px-2">
<button <button
id={"history"} id={"history"}
onClick={handleClick} onClick={handleClick}
...@@ -97,7 +97,7 @@ export default function Theme({ handleClick }: ThemeProps) { ...@@ -97,7 +97,7 @@ export default function Theme({ handleClick }: ThemeProps) {
문화재 문화재
</button> </button>
</div> </div>
<div onClick={() => clickActive(10)}> <div onClick={() => clickActive(10)} className="px-0 md:px-2">
<button <button
id={"zoo"} id={"zoo"}
onClick={handleClick} onClick={handleClick}
...@@ -106,7 +106,7 @@ export default function Theme({ handleClick }: ThemeProps) { ...@@ -106,7 +106,7 @@ export default function Theme({ handleClick }: ThemeProps) {
동물원 동물원
</button> </button>
</div> </div>
<div onClick={() => clickActive(11)}> <div onClick={() => clickActive(11)} className="px-0 md:px-2">
<button <button
id={"cycling"} id={"cycling"}
onClick={handleClick} onClick={handleClick}
......
...@@ -72,11 +72,11 @@ export function IntoPost() { ...@@ -72,11 +72,11 @@ export function IntoPost() {
<div className="flex basis-1/2 whitespace-nowrap px-0.5 md:px-2"> <div className="flex basis-1/2 whitespace-nowrap px-0.5 md:px-2">
작성일 : {posts?.date.slice(0, 10)} 작성일 : {posts?.date.slice(0, 10)}
</div> </div>
<div className="flex hidden md:whitespace-nowrap md:px-2 "> <div className="md:flex hidden md:whitespace-nowrap md:px-2 ">
{" "} {" "}
{posts?.city} {posts?.city}
</div> </div>
<div className="flex hidden md:whitespace-nowrap md:px-2"> <div className="md:flex hidden md:whitespace-nowrap md:px-2">
{" "} {" "}
{posts?.theme} {posts?.theme}
</div> </div>
......
...@@ -12,11 +12,11 @@ export default function Post({ handleClick, post }: Props) { ...@@ -12,11 +12,11 @@ export default function Post({ handleClick, post }: Props) {
return ( return (
<div className="flex flex-row h-16 divide-x-2 border-2 border-solid"> <div className="flex flex-row h-16 divide-x-2 border-2 border-solid">
<div className="basis-full"> <div className="basis-full">
<Link to={`/post/${post._id}`} state={post}>
<button id={post._id} onClick={handleClick}> <button id={post._id} onClick={handleClick}>
<Link to={`/post/${post._id}`} state={post}>
{post.title} {post.title}
</button>
</Link> </Link>
</button>
</div> </div>
<div className="basis-3/12">{post.date.slice(0, 10)}</div> <div className="basis-3/12">{post.date.slice(0, 10)}</div>
<div className="basis-2/12">{post.counts}</div> <div className="basis-2/12">{post.counts}</div>
......
...@@ -18,8 +18,8 @@ export default function Posting() { ...@@ -18,8 +18,8 @@ export default function Posting() {
const [user, setUser] = useState<PostType>({ const [user, setUser] = useState<PostType>({
title: "", title: "",
text: "", text: "",
theme: "", theme: "theme",
city: "", city: "city",
date: "", date: "",
user: { user: {
_id: "", _id: "",
...@@ -107,11 +107,11 @@ export default function Posting() { ...@@ -107,11 +107,11 @@ export default function Posting() {
alert("사진을 첨부해 주세요."); alert("사진을 첨부해 주세요.");
setError("사진을 첨부해 주세요."); setError("사진을 첨부해 주세요.");
return false; return false;
} else if (equals(city, "city")) { } else if (equals(user.city, "city")) {
alert("도시를 선택해 주세요."); alert("도시를 선택해 주세요.");
setError("도시를 선택해 주세요."); setError("도시를 선택해 주세요.");
return false; return false;
} else if (equals(theme, "theme")) { } else if (equals(user.theme, "theme")) {
alert("테마를 선택해 주세요."); alert("테마를 선택해 주세요.");
setError("테마를 선택해 주세요."); setError("테마를 선택해 주세요.");
return false; return false;
...@@ -207,9 +207,9 @@ export default function Posting() { ...@@ -207,9 +207,9 @@ export default function Posting() {
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="city"
> >
<option value="질문종류">도시</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>
...@@ -226,9 +226,9 @@ export default function Posting() { ...@@ -226,9 +226,9 @@ export default function Posting() {
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="theme"
> >
<option value="질문종류">테마</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>
......
...@@ -22,6 +22,10 @@ export const authenticate = asyncWrap( ...@@ -22,6 +22,10 @@ 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;
console.log("req.user", req.user);
console.log("user.id", user.id);
console.log("userId", userId);
if (user && user.id === userId) { if (user && user.id === userId) {
return next(); return next();
} else { } else {
......
...@@ -70,11 +70,23 @@ export const updateMainimg = asyncWrap(async (reqExp, res) => { ...@@ -70,11 +70,23 @@ export const updateMainimg = asyncWrap(async (reqExp, res) => {
// const { id } = reqExp.params; // const { id } = reqExp.params;
const { id, theme, city, title } = req.body; const { id, theme, city, title } = req.body;
const { updatemainimg }: { updatemainimg: formidable.File } = req.files; const { updatemainimg }: { updatemainimg: formidable.File } = req.files;
console.log("전부 제대로", id,theme, city, title, updatemainimg) console.log("전부 제대로", id, theme, city, title, updatemainimg);
const img = await mainimgDb.updateOneMainimg(id, theme,city,title, updatemainimg); if (updateMainimg === undefined) {
const img = await mainimgDb.updateOneMainimg(id, theme, city, title);
res.json(img); return res.json(img);
}) } else {
const img = await mainimgDb.updateOneMainimg(
id,
theme,
city,
title,
updatemainimg
);
return res.json(img);
}
});
// const form = formidable({ // const form = formidable({
// uploadDir: "uploads", // uploadDir: "uploads",
// keepExtensions: true, // keepExtensions: true,
......
import { NextFunction, Request, Response } from "express"; import { NextFunction, Request, Response } from "express";
import formidable, { Fields, Files } from "formidable"; import formidable, { Fields, Files } from "formidable";
import { TypedRequestAuth } from "./auth.controller"; import { TypedRequestAuth } from "./auth.controller";
import equals from "validator/lib/equals";
import { asyncWrap } from "../helpers"; import { asyncWrap } from "../helpers";
import { postDb, userDb } from "../db"; import { postDb, userDb } from "../db";
import { TypedRequest } from "../types"; import { TypedRequest } from "../types";
import { Types } from "mongoose"; import { Types } from "mongoose";
export const userByPostId = ( export const userByPostId = async (
reqExp: Request, reqExp: Request,
res: Response, res: Response,
next: NextFunction, next: NextFunction,
postId: string postId: string
) => { ) => {
const req = reqExp as TypedRequest; const req = reqExp as TypedRequest;
req.user = userDb.findUserByPostId(postId);
req.user = await userDb.findUserByPostId(postId);
next(); next();
}; };
......
...@@ -44,26 +44,22 @@ export const updateOneMainimg = async ( ...@@ -44,26 +44,22 @@ export const updateOneMainimg = async (
theme: string, theme: string,
city: string, city: string,
title: string, title: string,
fileInfo: formidable.File fileInfo?: formidable.File
// originalfilename?: string | null,
// newfilename?: string
) => { ) => {
// const newMainimg = await Mainimg.findById(_Id) const newMainimg = await Mainimg.findById(_Id).populate<{
const newMainimg = await Mainimg.findById(_Id).populate<{ fileInfo: IFileInfo }>( fileInfo: IFileInfo;
"fileInfo" }>("fileInfo");
); // console.log("error2", newMainimg);
console.log("error2", newMainimg);
if (!newMainimg) { if (!newMainimg) {
throw new Error("mainimg가 존재하지 않습니다") throw new Error("mainimg가 존재하지 않습니다");
} }
if ( if (
fileInfo.originalFilename && fileInfo?.originalFilename &&
newMainimg?.fileInfo.originalfilename !== fileInfo.originalFilename newMainimg?.fileInfo.originalfilename !== fileInfo?.originalFilename
) { ) {
// 같지 않으면 기존의 파일을 디스크에서 삭제한 후 // 같지 않으면 기존의 파일을 디스크에서 삭제한 후
try { try {
console.log("picturepath", newMainimg.fileInfo.picturepath) // console.log("picturepath", newMainimg.fileInfo.picturepath)
await fs.unlink(newMainimg.fileInfo.picturepath); await fs.unlink(newMainimg.fileInfo.picturepath);
} catch (error) { } catch (error) {
console.log("error", error); console.log("error", error);
...@@ -76,44 +72,10 @@ export const updateOneMainimg = async ( ...@@ -76,44 +72,10 @@ export const updateOneMainimg = async (
await mainimgAvatar.save(); await mainimgAvatar.save();
} }
newMainimg.theme = theme; newMainimg.theme = theme;
newMainimg.city = city; newMainimg.city = city;
newMainimg.title = title; newMainimg.title = title;
await newMainimg.save(); await newMainimg.save();
console.log("mainimg updated", newMainimg); console.log("mainimg updated", newMainimg);
return newMainimg; return newMainimg;
} };
// if (!(newMainimg?.fileInfo === undefined)) {
// if (originalfilename === undefined) {
// await Mainimg.findByIdAndUpdate(newMainimg._id, {
// theme: theme,
// city: city,
// title: title,
// });
// console.log("errrror4");
// } else if (
// !(originalfilename === undefined) &&
// (!(theme === undefined) ||
// !(city === undefined) ||
// !(title === undefined))
// ) {
// await Mainimg.findByIdAndUpdate(newMainimg._id, {
// theme: theme,
// city: city,
// title: title,
// });
// await FileInfo.findByIdAndUpdate(newMainimg.fileInfo._id, {
// originalfilename: originalfilename,
// newfilename: newfilename,
// });
// console.log("error6");
// } else {
// await FileInfo.findByIdAndUpdate(newMainimg.fileInfo._id, {
// originalfilename: originalfilename,
// newfilename: newfilename,
// });
// console.log("error5", newfilename, originalfilename, theme, city, title);
// }
// } else console.log("error3", newMainimg);
// };
\ No newline at end of file
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