Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature]게시글 삭제 수정 기능 구현 #80

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
4 changes: 3 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import CommentPage from "./pages/CommentPage";
import { Cookies } from "react-cookie";
import { initializeToken, isLogin } from "./data/store";
import { useDispatch } from "react-redux";
import NotionFix from "./pages/NotionFix";

const App = () => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -50,6 +51,7 @@ const App = () => {
<Route path="/map" element={<Location />} />
<Route path="/search" element={<SearchPage />} />
<Route path="/notifications" element={<NotificationPage />} />
<Route path="/notionFix/:id" element={<NotionFix />} />
<Route path="/notionAdd" element={<NotionAdd />} />
<Route path="/notion/:id" element={<NotionPage />} />
<Route path="/notion/:id/comments" element={<CommentPage />} />
Expand All @@ -59,4 +61,4 @@ const App = () => {
);
};

export default App;
export default App;
60 changes: 30 additions & 30 deletions src/components/NotionCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@ import React, { useState } from "react";
import Button from "./Button";

interface NotionCategoryProps {
onSelect: (category: string) => void;
onSelect: (category: string) => void;
}

const NotionCategory: React.FC<NotionCategoryProps> = ({ onSelect }) => {
const exerciseList = [
"자전거",
"야구",
"축구",
"테니스",
"농구",
"직접 입력",
];
const [activeButton, setActiveButton] = useState("야구");
const exerciseList = [
"자전거",
"야구",
"축구",
"테니스",
"농구",
"직접 입력",
];
const [activeButton, setActiveButton] = useState("");

const handleButtonClick = (item: string) => {
setActiveButton(item);
onSelect(item);
};
const handleButtonClick = (item: string) => {
setActiveButton(item);
onSelect(item);
};

return (
<div>
<div className="mb-10">
{exerciseList.map((item, index) => (
<Button
key={index}
label={item}
color={item === activeButton ? "green" : "grey"}
size="mid"
margin="btnMr"
onClick={() => handleButtonClick(item)}
/>
))}
</div>
</div>
);
return (
<div>
<div className="mb-10">
{exerciseList.map((item, index) => (
<Button
key={index}
label={item}
color={item === activeButton ? "green" : "grey"}
size="mid"
margin="btnMr"
onClick={() => handleButtonClick(item)}
/>
))}
</div>
</div>
);
};

export default NotionCategory;
23 changes: 23 additions & 0 deletions src/components/dist/NotionCategory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";
exports.__esModule = true;
var react_1 = require("react");
var Button_1 = require("./Button");
var NotionCategory = function (_a) {
var onSelect = _a.onSelect;
var exerciseList = [
"자전거",
"야구",
"축구",
"테니스",
"농구",
"직접 입력",
];
var _b = react_1.useState(""), activeButton = _b[0], setActiveButton = _b[1];
var handleButtonClick = function (item) {
setActiveButton(item);
onSelect(item);
};
return (react_1["default"].createElement("div", null,
react_1["default"].createElement("div", { className: "mb-10" }, exerciseList.map(function (item, index) { return (react_1["default"].createElement(Button_1["default"], { key: index, label: item, color: item === activeButton ? "green" : "grey", size: "mid", margin: "btnMr", onClick: function () { return handleButtonClick(item); } })); }))));
};
exports["default"] = NotionCategory;
2 changes: 2 additions & 0 deletions src/dist/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var CommentPage_1 = require("./pages/CommentPage");
var react_cookie_1 = require("react-cookie");
var store_1 = require("./data/store");
var react_redux_1 = require("react-redux");
var NotionFix_1 = require("./pages/NotionFix");
var App = function () {
var dispatch = react_redux_1.useDispatch();
var cookie = new react_cookie_1.Cookies();
Expand All @@ -47,6 +48,7 @@ var App = function () {
react_1["default"].createElement(react_router_dom_1.Route, { path: "/map", element: react_1["default"].createElement(LocationSetting_1["default"], null) }),
react_1["default"].createElement(react_router_dom_1.Route, { path: "/search", element: react_1["default"].createElement(SearchPage_1["default"], null) }),
react_1["default"].createElement(react_router_dom_1.Route, { path: "/notifications", element: react_1["default"].createElement(NotificationPage_1["default"], null) }),
react_1["default"].createElement(react_router_dom_1.Route, { path: "/notionFix/:id", element: react_1["default"].createElement(NotionFix_1["default"], null) }),
react_1["default"].createElement(react_router_dom_1.Route, { path: "/notionAdd", element: react_1["default"].createElement(NotionAdd_1["default"], null) }),
react_1["default"].createElement(react_router_dom_1.Route, { path: "/notion/:id", element: react_1["default"].createElement(NotionPage_1["default"], null) }),
react_1["default"].createElement(react_router_dom_1.Route, { path: "/notion/:id/comments", element: react_1["default"].createElement(CommentPage_1["default"], null) })),
Expand Down
114 changes: 68 additions & 46 deletions src/pages/NotionAdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,53 @@ const NotionAdd: React.FC = () => {
lat: number;
lng: number;
} | null>(null);
const [imageUrls, setImageUrls] = useState<string[]>([]);

const [channels, setChannels] = useState<Channel[]>([]);
const [isRegistered, setIsRegistered] = useState(false);
const [newPostId, setNewPostId] = useState<string | null>(null);

const [previewUrl, setPreviewUrl] = useState<string | null>(null);
const [imageFiles, setImageFiles] = useState<File[]>([]);
const [imageUrls, setImageUrls] = useState<string[]>([]);

const handleFileChange = useCallback(
async (e: ChangeEvent<HTMLInputElement>) => {
const files = e.target.files;
if (files) {
const newFiles = Array.from(files);
setImageFiles((prev) => [...prev, ...newFiles]);

const newUrls: string[] = [];
const formData = new FormData();

for (const file of newFiles) {
formData.append("file", file);
formData.append("upload_preset", UPLOAD_PRESET);

try {
const response = await fetch(
`https://api.cloudinary.com/v1_1/${CLOUD_NAME}/image/upload`,
{
method: "POST",
body: formData,
}
);
const data = await response.json();
newUrls.push(data.secure_url);
} catch (error) {
console.error("이미지 업로드 실패:", error);
}
}
setImageUrls((prev) => [...prev, ...newUrls]);
setFormData((prev) => ({
...prev,
images: [...prev.images, ...newUrls],
}));
}
},
[]
);

const [isRegistered, setIsRegistered] = useState(false);
const [newPostId, setNewPostId] = useState<string | null>(null);
const navigate = useNavigate();

const token = useSelector((state: any) => state.userToken);
Expand Down Expand Up @@ -126,42 +169,6 @@ const NotionAdd: React.FC = () => {
[formData]
);

const handleFileChange = useCallback(
async (e: ChangeEvent<HTMLInputElement>) => {
const files = e.target.files;
if (files) {
const newFiles = Array.from(files);
const newUrls: string[] = [];
const formData = new FormData();

for (const file of newFiles) {
formData.append("file", file);
formData.append("upload_preset", UPLOAD_PRESET);

try {
const response = await fetch(
`https://api.cloudinary.com/v1_1/${CLOUD_NAME}/image/upload`,
{
method: "POST",
body: formData,
}
);
const data = await response.json();
newUrls.push(data.secure_url);
} catch (error) {
console.error("이미지 업로드 실패:", error);
}
}
setImageUrls((prev) => [...prev, ...newUrls]);
setFormData((prev) => ({
...prev,
images: [...prev.images, ...newUrls],
}));
}
},
[]
);

const handleLocationClick = () => {
navigate("/map");
};
Expand Down Expand Up @@ -208,9 +215,10 @@ const NotionAdd: React.FC = () => {
throw new Error(`HTTP error : ${response.status}`);
}

navigate(`/`);
const data = await response.json();
console.log("Post 등록 완료:", data);
setNewPostId(data._id);
setNewPostId(data._id);
setIsRegistered(true);
resetForm();
} catch (error) {
Expand Down Expand Up @@ -244,7 +252,10 @@ const NotionAdd: React.FC = () => {

{/* 모임 인원 */}
<div>
<label htmlFor="meetingCapacity" className="flex font-bold text-xl mt-6">
<label
htmlFor="meetingCapacity"
className="flex font-bold text-xl mt-6"
>
모임 인원
</label>
<input
Expand All @@ -268,7 +279,10 @@ const NotionAdd: React.FC = () => {

{/* 모임 날짜 */}
<div>
<label htmlFor="meetingDate" className="flex font-bold text-xl mt-6">
<label
htmlFor="meetingDate"
className="flex font-bold text-xl mt-6"
>
모임 날짜
</label>
<input
Expand Down Expand Up @@ -339,7 +353,10 @@ const NotionAdd: React.FC = () => {

{/* 모임 장소 */}
<div>
<label htmlFor="meetingSpot" className="flex font-bold text-xl mt-6">
<label
htmlFor="meetingSpot"
className="flex font-bold text-xl mt-6"
>
모임 장소
</label>
<div
Expand All @@ -365,7 +382,10 @@ const NotionAdd: React.FC = () => {

{/* 모임 설명 */}
<div>
<label htmlFor="meetingInfo" className="flex font-bold text-xl mt-6">
<label
htmlFor="meetingInfo"
className="flex font-bold text-xl mt-6"
>
모임 설명
</label>
<input
Expand Down Expand Up @@ -437,15 +457,17 @@ const NotionAdd: React.FC = () => {
<div className="fixed inset-0 flex justify-center items-center backdrop-blur-sm bg-opacity-50">
<div className="bg-white p-5 border rounded-xl shadow-md">
<div className="flex justify-between items-center">
<p className="text-lg font-bold mr-4">모임이 성공적으로 등록되었습니다!</p>
<p className="text-lg font-bold mr-4">
모임이 성공적으로 등록되었습니다!
</p>
<Button
label="상세보기"
size="mid"
color="green"
onClick={() => {
setIsRegistered(false);
if (newPostId) {
navigate(`/notion/${newPostId}`);
navigate(`/notion/${newPostId}`);
}
}}
/>
Expand Down
Loading