Commit 5827bf35 authored by 백승민's avatar 백승민
Browse files

rewrite working

parent e7e8eef0
...@@ -2,7 +2,7 @@ import React from "react"; ...@@ -2,7 +2,7 @@ import React from "react";
import { BrowserRouter, Route, Routes } from "react-router-dom"; import { BrowserRouter, Route, Routes } from "react-router-dom";
import "tailwindcss/tailwind.css"; import "tailwindcss/tailwind.css";
import { IntoPost } from "./post/intopost"; import { IntoPost } from "./post/intopost";
import { Login, Profile, RequireAuth, Signup, Admin } from "./auth"; import { Login, Profile, RequireAuth, Signup, Admin, ImgRewrite } from "./auth";
import { Header, Body } from "./home"; import { Header, Body } from "./home";
import { Board } from "./board"; import { Board } from "./board";
import Posting from "./post/posting"; import Posting from "./post/posting";
...@@ -39,6 +39,7 @@ export const App = () => { ...@@ -39,6 +39,7 @@ export const App = () => {
} }
/> />
<Route path="admin" element={<Admin />} /> <Route path="admin" element={<Admin />} />
<Route path="rewrite" element={<ImgRewrite/>}/>
</Route> </Route>
</Route> </Route>
</Routes> </Routes>
......
...@@ -8,7 +8,7 @@ export const mainimg = async (mainimg: MainimgType) => { ...@@ -8,7 +8,7 @@ export const mainimg = async (mainimg: MainimgType) => {
}; };
export const delmainimg = async (_id : string) => { export const delmainimg = async (_id : string) => {
const { data } = await axios.delete(`${baseUrl}/mainimg`); const { data } = await axios.delete(`${baseUrl}/mainimg/${_id}`);
return data; return data;
}; };
......
import React, { FormEvent, useEffect, useState, MouseEvent } from "react"; import React, { FormEvent, useEffect, useState, MouseEvent } from "react";
import { Link } from "react-router-dom";
import { mainimgApi } from "../apis"; import { mainimgApi } from "../apis";
import { catchErrors } from "../helpers"; import { catchErrors } from "../helpers";
import { MainimgType } from "../types"; import { MainimgType } from "../types";
import { MySlide } from "./adminslide"; import { MySlide } from "./adminslide";
export default function Admin() { export default function Admin() {
// 이미지 전체 불러오기
const [getimgs, setGetimgs] = useState<MainimgType[]>([]); const [getimgs, setGetimgs] = useState<MainimgType[]>([]);
async function imgsData() { async function imgsData() {
const imgs = await mainimgApi.getmainimg(); const imgs = await mainimgApi.getmainimg();
// console.log("ㅑㅡㅎ", imgs)
setGetimgs(imgs) setGetimgs(imgs)
}; };
...@@ -18,6 +18,7 @@ export default function Admin() { ...@@ -18,6 +18,7 @@ export default function Admin() {
imgsData(); imgsData();
}, []); }, []);
// 이미지 추가하기
const [addimg, setAddimg] = useState<MainimgType>({ const [addimg, setAddimg] = useState<MainimgType>({
_id: "", _id: "",
theme: "", theme: "",
...@@ -27,7 +28,8 @@ export default function Admin() { ...@@ -27,7 +28,8 @@ export default function Admin() {
}); });
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [error, setError] = useState(""); const [error, setError] = useState("");
const [success, setSuccess] = useState(false); const [addSuccess, setAddSuccess] = useState(false);
const [delSuccess, setDelSuccess] = useState(false);
function handleSelectChange(event: React.ChangeEvent<HTMLSelectElement>) { function handleSelectChange(event: React.ChangeEvent<HTMLSelectElement>) {
const { name, value } = event.currentTarget; const { name, value } = event.currentTarget;
...@@ -38,7 +40,6 @@ export default function Admin() { ...@@ -38,7 +40,6 @@ export default function Admin() {
setAddimg({ ...addimg, [name]: value }); setAddimg({ ...addimg, [name]: value });
} }
// console.log("asdafsdfs", getimgs)
async function handleSubmit(event: FormEvent) { async function handleSubmit(event: FormEvent) {
event.preventDefault(); event.preventDefault();
try { try {
...@@ -47,9 +48,8 @@ export default function Admin() { ...@@ -47,9 +48,8 @@ export default function Admin() {
setLoading(true); setLoading(true);
const res = await mainimgApi.mainimg(addimg); const res = await mainimgApi.mainimg(addimg);
console.log("서버연결됬나요", res); console.log("서버연결됬나요", res);
setSuccess(true); setAddSuccess(true);
setError(""); setError("");
alert("img 추가되었습니다");
} catch (error) { } catch (error) {
console.log("에러발생"); console.log("에러발생");
catchErrors(error, setError); catchErrors(error, setError);
...@@ -58,17 +58,33 @@ export default function Admin() { ...@@ -58,17 +58,33 @@ export default function Admin() {
} }
} }
// if (success) { if (addSuccess) {
// alert("img 추가되었습니다"); alert("img 추가되었습니다");
// } }
// 이미지 삭제하기
async function handleDeleteClick(event: MouseEvent<HTMLButtonElement>) { async function handleDeleteClick(event: MouseEvent<HTMLButtonElement>) {
const picId = event.currentTarget.id; try {
console.log(picId) if (confirm("삭제하시겠습니까?") == true) {
const res = await mainimgApi.delmainimg(picId); const picId = event.currentTarget.id;
console.log("delete img", res); console.log("picId : ", picId)
alert("img 삭제되었습니다.") const res = await mainimgApi.delmainimg(picId);
console.log("delete img", res);
setDelSuccess(true);
setError("");
} else {
return false;
}
}
catch (error) {
console.log("에러발생");
catchErrors(error, setError);
} finally {
setLoading(false);
};
}; };
if (delSuccess) {
alert("img 삭제되었습니다");
}
let limit = 15; let limit = 15;
const numPages = Math.ceil(getimgs.length / 15); const numPages = Math.ceil(getimgs.length / 15);
...@@ -85,9 +101,16 @@ export default function Admin() { ...@@ -85,9 +101,16 @@ export default function Admin() {
/> />
<p className="text-center text-xs">{pic.title}</p> <p className="text-center text-xs">{pic.title}</p>
</div> </div>
<button id={pic._id} onClick={handleDeleteClick}> <div className="text-end">
삭제 <button className="border-r-2 border-r-indigo-500 text-xs">
</button> <Link to="/rewrite">
수정
</Link>
</button>
<button id={pic._id} onClick={handleDeleteClick} className="text-xs">
삭제
</button>
</div>
</div> </div>
))] ))]
slides.push(k); slides.push(k);
...@@ -107,16 +130,16 @@ export default function Admin() { ...@@ -107,16 +130,16 @@ export default function Admin() {
onChange={handleSelectChange} onChange={handleSelectChange}
> >
<option value="질문종류">도시</option> <option value="질문종류">도시</option>
<option value="Seoul">서울</option> <option value="서울">서울</option>
<option value="Busan">부산</option> <option value="부산">부산</option>
<option value="Incheon">인천</option> <option value="인천">인천</option>
<option value="Daegoo">대구</option> <option value="대구">대구</option>
<option value="Kwangjoo">광주</option> <option value="광주">광주</option>
<option value="Daejeon">대전</option> <option value="대전">대전</option>
<option value="Woolsan">울산</option> <option value="울산">울산</option>
<option value="Sejong">세종</option> <option value="세종">세종</option>
<option value="Dokdo">독도</option> <option value="독도">독도</option>
<option value="Jeju">제주</option> <option value="제주">제주</option>
</select> </select>
<select <select
name="theme" name="theme"
...@@ -126,18 +149,18 @@ export default function Admin() { ...@@ -126,18 +149,18 @@ export default function Admin() {
onChange={handleSelectChange} onChange={handleSelectChange}
> >
<option value="질문종류">테마</option> <option value="질문종류">테마</option>
<option value="cycling">사이클링</option> <option value="사이클링">사이클링</option>
<option value="surfing">서핑</option> <option value="서핑">서핑</option>
<option value="activity">액티비티</option> <option value="액티비티">액티비티</option>
<option value="camping">캠핑</option> <option value="캠핑">캠핑</option>
<option value="sking">스키</option> <option value="스키">스키</option>
<option value="boat">보트</option> <option value="보트">보트</option>
<option value="desert">사막</option> <option value="사막">사막</option>
<option value="golf">골프</option> <option value="골프">골프</option>
<option value="cave">동굴</option> <option value="동굴">동굴</option>
<option value="history">문화재</option> <option value="문화재">문화재</option>
<option value="zoo">동물원</option> <option value="동물원">동물원</option>
<option value="cycling">사이클링</option> <option value="사이클링">사이클링</option>
</select> </select>
<div className="flex items-center justify-end gap-3"> <div className="flex items-center justify-end gap-3">
<p>url :</p> <p>url :</p>
......
import React, { FormEvent, useEffect, useState, MouseEvent } from "react";
import { Link, Outlet } from "react-router-dom";
import { mainimgApi } from "../apis";
import { catchErrors } from "../helpers";
import { MainimgType } from "../types";
import { MySlide } from "./adminslide";
export default function ImgRewrite() {
// 이미지 수정
return (
<div>
<div>
</div>
<Outlet/>
</div>
);
};
...@@ -3,3 +3,4 @@ export { default as Signup } from "./signup"; ...@@ -3,3 +3,4 @@ export { default as Signup } from "./signup";
export { default as Profile } from "./profile"; export { default as Profile } from "./profile";
export { RequireAuth } from "./RequireAuth"; export { RequireAuth } from "./RequireAuth";
export { default as Admin } from "./admin"; export { default as Admin } from "./admin";
export {default as ImgRewrite} from "./imgrewrite"
...@@ -7,6 +7,9 @@ router ...@@ -7,6 +7,9 @@ router
.route("/") .route("/")
.get(authCtrl.requireLogin, mainimgCtrl.getMainimg) .get(authCtrl.requireLogin, mainimgCtrl.getMainimg)
.post(authCtrl.requireLogin, mainimgCtrl.createMainimg) .post(authCtrl.requireLogin, mainimgCtrl.createMainimg)
router
.route("/:imgId")
.delete(authCtrl.requireLogin, mainimgCtrl.deleteMainimg) .delete(authCtrl.requireLogin, mainimgCtrl.deleteMainimg)
......
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