Skip to content
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
2 changes: 2 additions & 0 deletions src/pages/join/SignUp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import LocationStep from "./components/LocationStep";
import OwnerStep from "./components/OwnerStep";
import GoHome from "./components/GoHome";
import { signup } from "@apis/member/signup";
import useAuthStore from "@/store/authStore";

const SignUpPage = () => {
const [step, setStep] = useState(1);
Expand Down Expand Up @@ -37,6 +38,7 @@ const SignUpPage = () => {
};
try {
await signup(finalData);
useAuthStore.getState().completeSignup();
setStep((prev) => prev + 1);
} catch (error) {
console.error("회원가입 실패:", error);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/join/components/GoHome.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ImgDone } from "@assets/svgs/signup";
import BackIcon from "/svgs/Ic_Arrow_Left.svg";
import BackIcon from "/svgs/common/Ic_Arrow_Left.svg";

const GoHome = ({ onNext, onBack }) => {
const handleSubmit = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/join/components/LocationStep.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useRef } from "react";
import XIcon from "/svgs/Ic_X_Btn.svg";
import BackIcon from "/svgs/Ic_Arrow_Left.svg";
import XIcon from "/svgs/common/Ic_X_Btn.svg";
import BackIcon from "/svgs/common/Ic_Arrow_Left.svg";
import { IcCheck, IcNonCheck } from "@assets/svgs/signup";
import useBottomOffset from "../hooks/useBottomOffset";

Expand Down
20 changes: 8 additions & 12 deletions src/pages/join/components/NameStep.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useRef } from "react";
import XIcon from "/svgs/Ic_X_Btn.svg";
import BackIcon from "/svgs/Ic_Arrow_Left.svg";
import XIcon from "/svgs/common/Ic_X_Btn.svg";
import BackIcon from "/svgs/common/Ic_Arrow_Left.svg";
import useBottomOffset from "../hooks/useBottomOffset";

const NameStep = ({ onNext, onBack }) => {
Expand All @@ -21,13 +21,11 @@ const NameStep = ({ onNext, onBack }) => {
onSubmit={handleSubmit}
className="flex flex-col justify-start mt-48 bg-white h-screen overflow-auto relative"
>
<button
onClick={onBack}
className="absolute top-6 left-4 sm:top-8 sm:left-6 z-10"
aria-label="뒤로가기"
>
<img src={BackIcon} alt="뒤로가기 버튼" className="w-6 h-6" />
</button>
<div className="fixed top-20 left-1/2 -translate-x-1/2 w-full max-w-[760px] px-4 sm:px-6 z-50">
<button onClick={onBack} aria-label="뒤로가기" className="w-8 h-8">
<img src={BackIcon} alt="뒤로가기 버튼" className="w-8 h-8" />
</button>
</div>

<section className="px-8">
<h1 className="h1 text-gray-12">이름을 입력해주세요.</h1>
Expand Down Expand Up @@ -79,9 +77,7 @@ const NameStep = ({ onNext, onBack }) => {
type="submit"
disabled={!name.trim()}
className={`w-full py-6 text-center b1 ${
name.trim()
? "bg-primary-8 text-white"
: "bg-gray-4 text-white"
name.trim() ? "bg-primary-8 text-white" : "bg-gray-4 text-white"
}`}
>
확인
Expand Down
2 changes: 1 addition & 1 deletion src/pages/join/components/OwnerStep.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from "react";
import BackIcon from "/svgs/Ic_Arrow_Left.svg";
import BackIcon from "/svgs/common/Ic_Arrow_Left.svg";
import { IcCheck, IcUnselected } from "@assets/svgs/signup";

const OwnerStep = ({ onNext, onBack }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/join/components/ProfileImageStep.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from "react";
import BackIcon from "/svgs/Ic_Arrow_Left.svg";
import BackIcon from "/svgs/common/Ic_Arrow_Left.svg";
import {
IcCheck,
ImgOrange,
Expand Down
1 change: 1 addition & 0 deletions src/pages/kakaoAuth/kakaoAuth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const KakaoAuth = () => {
if (isNewUser) {
navigate("/signup");
} else {
useAuthStore.getState().completeSignup(); // 기존 유저라면 바로 가입 완료
navigate("/");
}
} catch (err) {
Expand Down
14 changes: 11 additions & 3 deletions src/pages/map/MapPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,15 @@ const MapPage = () => {
const handleMarkerClick = async (place) => {
try {
const preview = await getCompanyPreview(place.id);
setSelectedPlace({ ...place, ...preview });

let liked = false;
const isAuthenticated = await useAuthStore.getState().checkAuth();
if (isAuthenticated) {
const likedList = await getLikedCompanies();
liked = likedList.some((c) => c.companyId === place.id);
}

setSelectedPlace({ ...place, ...preview, liked });
} catch (err) {
console.error("프리뷰 불러오기 실패:", err);
}
Expand Down Expand Up @@ -190,8 +198,8 @@ const MapPage = () => {
<img
src={
showOnlyLiked
? "/svgs/Ic_Heart_Fill.svg"
: "/svgs/Ic_Heart-Empty.svg"
? "/svgs/common/Ic_Heart_Fill.svg"
: "/svgs/common/Ic_Heart-Empty.svg"
}
alt="찜 필터"
className="w-6 h-6"
Expand Down
2 changes: 1 addition & 1 deletion src/pages/map/components/IntroModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const IntroModal = ({ onClose }) => {
aria-label="닫기"
>
<img
src="/svgs/Ic_X.svg"
src="/svgs/common/Ic_X.svg"
alt="닫기"
className="w-6 h-6 sm:w-7 sm:h-7"
/>
Expand Down
7 changes: 5 additions & 2 deletions src/pages/map/components/PlaceBottomSheet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,17 @@ const PlaceBottomSheet = ({
className="absolute top-3 right-3 p-2 z-10"
aria-label="닫기"
>
<img src="/svgs/Ic_X.svg" alt="닫기 버튼" className="w-6 h-6" />
<img
src="/svgs/common/Ic_X.svg"
alt="닫기 버튼"
className="w-6 h-6"
/>
</button>
</div>
)}

<PlaceContent
place={place}
liked={place.liked}
onToggleLike={onToggleLike}
showMapLink={isExpanded}
/>
Expand Down
12 changes: 7 additions & 5 deletions src/pages/map/components/PlaceContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,9 @@ const PlaceContent = ({ place, onToggleLike, showMapLink = true }) => {
<p className="b4 flex items-center gap-2 mt-1">
<span className="flex items-center text-primary-8 font-bold">
<FireIcon className="w-4 h-4 mr-1" />
{temperature}도
</span>
<span className="text-gray-12 b6">
방문자 리뷰 {reviewCount}
{temperature.toFixed(0)}도
</span>
<span className="text-gray-12 b6">방문자 리뷰 {reviewCount}</span>
</p>
</div>
</div>
Expand Down Expand Up @@ -176,7 +174,11 @@ const PlaceContent = ({ place, onToggleLike, showMapLink = true }) => {
className="w-14 h-14 flex items-center justify-center rounded-md bg-gray-2"
>
<img
src={liked ? "/svgs/Ic_Heart_Fill.svg" : "/svgs/Ic_Heart-Empty.svg"}
src={
liked
? "/svgs/common/Ic_Heart_Fill.svg"
: "/svgs/common/Ic_Heart-Empty.svg"
}
alt="좋아요 버튼"
className="w-6 h-6"
/>
Expand Down
25 changes: 7 additions & 18 deletions src/pages/map/hooks/useToggleLike.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,21 @@ export const useToggleLike = ({
return;
}

const currentPlace = placesWithDistance.find((p) => p.id === targetId);
const currentPlace =
placesWithDistance.find((p) => p.id === targetId) || selectedPlace;

if (!currentPlace || isProcessing) return;

setIsProcessing(true);
setLoading(true);

try {
// 서버 liked 상태 확인 (불일치 방지용)
// 서버 liked 상태 확인
const likedList = await getLikedCompanies();
const isActuallyLiked = likedList.some(
(c) => String(c.companyId) === String(targetId),
);

// 로컬 상태와 서버 상태 불일치 시 보정
if (currentPlace.liked !== isActuallyLiked) {
const corrected = placesWithDistance.map((p) =>
p.id === targetId ? { ...p, liked: isActuallyLiked } : p,
);
setPlacesWithDistance(corrected);
if (selectedPlace?.id === targetId) {
setSelectedPlace({
...selectedPlace,
liked: isActuallyLiked,
});
}
}

// 서버 상태 기준으로 실제 토글 실행
if (isActuallyLiked) {
await unlikeCompany(targetId);
Expand All @@ -69,12 +57,13 @@ export const useToggleLike = ({
setPlacesWithDistance(updated);

if (selectedPlace?.id === targetId) {
setSelectedPlace({
const newSelected = {
...selectedPlace,
liked: !isActuallyLiked,
distance: currentPlace.distance,
formattedDistance: currentPlace.formattedDistance,
});
};
requestAnimationFrame(() => setSelectedPlace(newSelected));
}

if (setFilteredPlaces) {
Expand Down
41 changes: 22 additions & 19 deletions src/pages/search/SearchPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import { formatDistance } from "../map/utils/formatDistance";
import { getCompanyPreview } from "@apis/company/getCompanyPreview";
import { useCompanyData } from "./hooks/useCompanyData";
import { useUserCoords } from "./hooks/useUserCoords";
import useAuthStore from "@/store/authStore";
import HaveToLoginModal from "@components/common/HaveToLoginModal";
import MapViewer from "./components/MapViewer";
import { useToggleLike } from "../map/hooks/useToggleLike";
import useAuthStore from "@/store/authStore";
import { getLikedCompanies } from "@/apis/company/getLikedCompanies";

const LOCAL_STORAGE_KEY = "recentSearches";

Expand All @@ -21,32 +22,29 @@ const SearchPage = () => {
const [isSearched, setIsSearched] = useState(false);
const [selectedPlace, setSelectedPlace] = useState(null);
const [moveToCurrentLocation, setMoveToCurrentLocation] = useState(false);

const [isBottomSheetExpanded, setIsBottomSheetExpanded] = useState(false);
const [isBottomSheetVisible, setIsBottomSheetVisible] = useState(false);
const [step, setStep] = useState(1);
const [showLoginModal, setShowLoginModal] = useState(false);
const [bottomSheetHeight, setBottomSheetHeight] = useState(220);
const [isDesktop, setIsDesktop] = useState(false);

const { companies: allPlaces } = useCompanyData();
const userCoords = useUserCoords();

useEffect(() => {
const updateSize = () => {
setIsDesktop(window.innerWidth >= 1024);
};
const updateSize = () => setIsDesktop(window.innerWidth >= 1024);
updateSize();
window.addEventListener("resize", updateSize);
return () => window.removeEventListener("resize", updateSize);
}, []);

const { companies: allPlaces, loading: isCompanyLoading } = useCompanyData();
const userCoords = useUserCoords();
const isLoggedIn = useAuthStore((state) => state.isLoggedIn);

useEffect(() => {
const stored = localStorage.getItem(LOCAL_STORAGE_KEY);
if (stored) {
setRecentSearches(JSON.parse(stored));
setStep(JSON.parse(stored).length > 0 ? 2 : 1);
const parsed = JSON.parse(stored);
setRecentSearches(parsed);
setStep(parsed.length > 0 ? 2 : 1);
}
}, []);

Expand All @@ -63,7 +61,6 @@ const SearchPage = () => {

const filteredPlaces = useMemo(() => {
if (!isSearched || !keyword.trim()) return [];

const searchText = keyword.toLowerCase();

return allPlaces
Expand Down Expand Up @@ -91,10 +88,7 @@ const SearchPage = () => {
};
})
.filter(Boolean)
.sort((a, b) => {
if (a.distance == null || b.distance == null) return 0;
return a.distance - b.distance;
});
.sort((a, b) => (a.distance ?? 0) - (b.distance ?? 0));
}, [allPlaces, keyword, isSearched, userCoords]);

useEffect(() => {
Expand All @@ -118,7 +112,6 @@ const SearchPage = () => {
setKeyword(text);
setIsSearched(true);
setStep(4);

setSelectedPlace(null);
setIsBottomSheetVisible(false);
setIsBottomSheetExpanded(false);
Expand All @@ -130,15 +123,24 @@ const SearchPage = () => {
const handleSelectPlace = async (place) => {
try {
const preview = await getCompanyPreview(place.id);

// 찜 여부 재확인
let liked = false;
const isAuthenticated = await useAuthStore.getState().checkAuth();
if (isAuthenticated) {
const likedList = await getLikedCompanies();
liked = likedList.some((c) => c.companyId === place.id);
}

const enriched = {
...place,
...preview,
liked: preview.isSaved ?? false,
liked,
};
setSelectedPlace(enriched);
setIsBottomSheetVisible(true);
setIsBottomSheetExpanded(false);
setStep?.(5); // SearchPage인 경우
setStep?.(5);
} catch (err) {
console.error("기업 상세 정보 불러오기 실패:", err);
}
Expand Down Expand Up @@ -223,6 +225,7 @@ const SearchPage = () => {
showEmptyMessage={true}
/>
)}

{step === 5 && (
<div className="relative w-full h-screen">
<MapViewer
Expand Down
2 changes: 1 addition & 1 deletion src/pages/search/components/RecentSearchList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const RecentSearchList = ({ recentSearches, onSearch, setRecentSearches }) => {
}}
>
<img
src="/svgs/Ic_X.svg"
src="/svgs/common/Ic_X.svg"
alt="삭제"
className="w-4 h-4 opacity-60"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/search/components/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const SearchBar = ({ keyword, setKeyword, onSearch, onFocus }) => {
return (
<div className="flex items-center space-x-2">
<button onClick={() => navigate(-1)} className="shrink-0">
<img src="/svgs/Ic_Arrow_Left.svg" alt="뒤로가기" className="w-6 h-6" />
<img src="/svgs/common/Ic_Arrow_Left.svg" alt="뒤로가기" className="w-6 h-6" />
</button>

<div className="flex-grow h-12 px-4 flex items-center justify-between bg-white rounded-2xl border border-gray-300">
Expand Down
13 changes: 1 addition & 12 deletions src/pages/search/hooks/useMapViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const useMapViewer = ({
}

onMarkerClick?.(place);
console.log("marker");
},
[onMarkerClick, showOnlyLiked],
);
Expand Down Expand Up @@ -79,20 +80,8 @@ const useMapViewer = ({

window.naver.maps.Event.addListener(marker, "click", () => {
handleMarkerClick(place);
console.log("marker");
});
});

if (markerPosition) {
new window.naver.maps.Marker({
position: new window.naver.maps.LatLng(
markerPosition.lat,
markerPosition.lng,
),
map: mapInstance.current,
icon: createMarkerIcon(true),
});
}
});
}, [
userCoords,
Expand Down
Loading