Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function App() {
<Route path="/chat" element={<ChatPage />} />
<Route path="/chat/room/:id" element={<ChatRoomPage />} />
<Route path="/chat/room/buy/:id" element={<ChatRoomBuyPage />} />
<Route path="/chat/room/final" element={<ChatRoomFinalPage />} />
<Route path="/chat/room/final/:id" element={<ChatRoomFinalPage />} />
<Route path="/post/detail/:id" element={<PostingDetailPage />} />
<Route path="/post/create" element={<PostingCreatePage />} />
<Route path="/mypage" element={<MyPage />} />
Expand Down
3 changes: 1 addition & 2 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ api.interceptors.request.use(
async (config) => {
try {
const tokenData = localStorage.getItem("access_token");
console.log(tokenData);
if (tokenData) {
config.headers["Authorization"] = `Bearer ${tokenData}`;
}
Expand Down Expand Up @@ -83,4 +82,4 @@ export const put = (url, data) => api.put(url, data);
export const del = (url, data) => api.delete(url, data);

// PATCH 요청
export const patch = (url, data) => api.patch(url, data);
export const patch = (url, data, config = {}) => api.patch(url, data, config);
12 changes: 12 additions & 0 deletions src/api/mypage-controller/profileGet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { get } from "./../index";
// 장소 데이터 가져오기
export const getProfile = async () => {
try {
const response = await get("/api/v1/user/mypage/me");

return response.data;
} catch (error) {
console.error("getPlaces API 실패:", error);
throw error;
}
};
25 changes: 25 additions & 0 deletions src/api/mypage-controller/profilePatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { patch } from "../index";

// 프로필 업데이트
export const patchProfile = async (name, introduction, profileImage) => {
try {
const formData = new FormData();
formData.append("name", name);
formData.append("introduction", introduction);
if (profileImage) {
formData.append("profileImage", profileImage);
}
console.log(name, introduction, profileImage);

const response = await patch("/user/my/update-profile", formData, {
headers: {
"Content-Type": "multipart/form-data",
},
});

return response.message;
} catch (error) {
console.error("프로필 업데이트 실패:", error);
throw error;
}
};
30 changes: 15 additions & 15 deletions src/components/ItemModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ const ItemModal = ({ isOpen, onClose, item }) => {

if (liked) {
// 이미 좋아요 상태라면 → 취소 요청
setLiked(false);
// const res = await unlikeSpace(spaceId);
//setLiked(false);
const res = await unlikeSpace(spaceId);

// if (res?.data?.isLiked !== undefined) {
// setLiked(res.data.isLiked);
// } else {
// setLiked(false);
// }
if (res?.data?.isLiked !== undefined) {
setLiked(res.data.isLiked);
} else {
setLiked(false);
}
} else {
setLiked(true);
// 좋아요 상태가 아니라면 → 생성 요청
// const res = await likeSpace(spaceId);
// if (res?.data?.isLiked !== undefined) {
// setLiked(res.data.isLiked);
// } else {
// setLiked(true);
// }
//setLiked(true);
//좋아요 상태가 아니라면 → 생성 요청
const res = await likeSpace(spaceId);
if (res?.data?.isLiked !== undefined) {
setLiked(res.data.isLiked);
} else {
setLiked(true);
}
}
} catch (error) {
console.error("좋아요 토글 에러:", error);
Expand Down
38 changes: 9 additions & 29 deletions src/pages/chatPage/ChatPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,21 @@
import React, { useState } from "react";
import styled from "styled-components";
import { useNavigate } from "react-router-dom";

// 더미 데이터
const dummyData = [
{
id: 1,
name: "홍길동",
lastMessage: "안녕하세요! 오늘 보시나요?",
time: "방금 전",
unreadCount: 3,
profile: "https://via.placeholder.com/40",
buildingImage: "https://via.placeholder.com/50",
timestamp: new Date(2024, 7, 15, 10, 20), // 정렬용 timestamp
},
{
id: 2,
name: "김철수",
lastMessage: "네 내일 괜찮습니다.",
time: "1시간 전",
unreadCount: 0,
profile: "https://via.placeholder.com/40",
buildingImage: "https://via.placeholder.com/50",
timestamp: new Date(2024, 7, 15, 9, 10),
},
];

import { useChatStore } from "../../stores/chatStore";
const ChatPage = () => {
const navigate = useNavigate();
const [activeSort, setActiveSort] = useState("newest");
const { chats, setUnreadCount } = useChatStore();

// 정렬 함수
const getSortedList = () => {
switch (activeSort) {
case "newest": // 최신순
return [...dummyData].sort((a, b) => b.timestamp - a.timestamp);
return [...chats].sort((a, b) => b.timestamp - a.timestamp);
case "oldest": // 오래된 순
return [...dummyData].sort((a, b) => a.timestamp - b.timestamp);
return [...chats].sort((a, b) => a.timestamp - b.timestamp);
default:
return dummyData;
return chats;
}
};

Expand Down Expand Up @@ -101,7 +78,10 @@ const ChatPage = () => {
{sortedList.map((item) => (
<ChatItem
key={item.id}
onClick={() => navigate(`/chat/room/${item.id}`)}
onClick={() => {
navigate(`/chat/room/${item.id}`);
setUnreadCount(item.id); // ✅ 함수 호출
}}
>
<ProfileImg src={item.profile} alt="profile" />
<ChatInfo>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/chatPage/ChatRoomBuyPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ const ChatRoomBuyPage = () => {
setStep((prev) => prev + 1);
}
if (step === 2) {
navigate("/chat/room/final");
navigate(`/chat/room/final/${id}`);
}
}}
>
Expand Down
10 changes: 7 additions & 3 deletions src/pages/chatPage/ChatRoomFinalPage.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useNavigate } from "react-router-dom";
import { useNavigate, useParams } from "react-router-dom";
import styled from "styled-components";
import LeftArrowIcon from "../../assets/icons/leftArrowIconBlack.svg";
import BuyCheckIcon from "../../assets/icons/buyCheckIcon.svg";

import useHistoryStore from "../../stores/useHistoryStore";
const ChatRoomFinalPage = () => {
const { reverseAddReservation, moveToOngoing } = useHistoryStore();
const { roomId } = useParams();
const navigate = useNavigate();

return (
Expand All @@ -26,7 +28,9 @@ const ChatRoomFinalPage = () => {
<HomeBox>
<HomeButton
onClick={() => {
navigate("/home");
navigate("/home", { state: { roomId } });
reverseAddReservation();
moveToOngoing();
}}
>
홈으로 가기
Expand Down
Loading
Loading