Skip to content

Commit

Permalink
Merge branch 'dev' into feat/Map-Yorkie
Browse files Browse the repository at this point in the history
  • Loading branch information
hughesgoon authored Aug 19, 2024
2 parents 4266aee + ebd0741 commit 1b42ec0
Show file tree
Hide file tree
Showing 72 changed files with 1,284 additions and 891 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"scripts": {
"start": "react-scripts start",
"start:windows": "set HTTPS=true&&set SSL_CRT_FILE=./localhost.pem&&set SSL_KEY_FILE=./localhost-key.pem&&npm run start",
"start:windows": "set HTTPS=true&&set SSL_CRT_FILE=./cert/localhost.pem&&set SSL_KEY_FILE=./cert/localhost-key.pem&&npm run start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
Expand Down
34 changes: 34 additions & 0 deletions src/apis/auth/useLogOutMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useMutation } from 'react-query';
import instance from '../instance';
import { BaseResponse } from '../../types/BaseResponse';
import { LoginSuccess } from '../../types/auth/login';
import { ResponseCode } from '../../types/enum/ResponseCode';
import useRegisterStore from '../../stores/registerStore';
import { useNavigate } from 'react-router-dom';

export const useLogOutMutation = (prevUrl: string) => {
const { resetStatus } = useRegisterStore();
const navigate = useNavigate();

const mutation = useMutation({
mutationFn: async () => {
return await instance.post<BaseResponse<LoginSuccess>>(`/logout`);
},
onSuccess: (response) => {
const respone = response.data;

if (respone.code === ResponseCode.SUCCESS) {
resetStatus();
}
navigate(prevUrl);
},
onError: () => {
console.log('로그아웃 실패');
navigate(prevUrl);
},
});

return mutation;
};

export default useLogOutMutation;
26 changes: 17 additions & 9 deletions src/apis/auth/useSignUpMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import useRegisterStore from '../../stores/registerStore';
import { useNavigate } from 'react-router-dom';

export const useSignUpMutation = (prevUrl: string) => {
const { setLogIn } = useRegisterStore();
const { setLogIn, setIsIdDuplicate } = useRegisterStore();
const navigate = useNavigate();

const mutation = useMutation({
Expand All @@ -21,27 +21,35 @@ export const useSignUpMutation = (prevUrl: string) => {
);
},
onSuccess: (response) => {
const respone = response.data;
const responseData = response.data;

if (respone.code === ResponseCode.LOGGED_IN) {
if (responseData.code === ResponseCode.SUCCESS) {
console.log('새로운 사용자, 회원가입 성공!');

const profileId = respone.result.profileId;
const imgUrl = respone.result.imgUrl;
const accessToken = respone.result.accessToken;
const profileId = responseData.result.profileId;
const imgUrl = responseData.result.imgUrl;
const accessToken = responseData.result.accessToken;
setLogIn(profileId, imgUrl, accessToken);

instance.defaults.headers.common['Authorization'] =
`Bearer ${accessToken}`; //로그인 된 유저에 대하여 모든 api 호출에 accesstoken 포함시키는 코드

if (prevUrl === '/') navigate('/timeline');
else navigate(prevUrl);
return;
}
if (responseData.code === ResponseCode.ALREADY_EXIST_PROFILE_ID) {
//중복된 profileId인 경우
console.log('사용 중인 아이디');
setIsIdDuplicate(true);
navigate(`${prevUrl + '?authState=signup'}`);
return;
} else {
//회원가입 오류
console.log('회원가입 실패');
navigate(`${prevUrl === '/' ? prevUrl : prevUrl + '?authState=login'}`);
return;
}

if (prevUrl === '/') navigate('/timeline');
else navigate(prevUrl);
},
onError: () => {
console.log('회원가입 실패');
Expand Down
2 changes: 1 addition & 1 deletion src/apis/follow/getFollowing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BaseResponse } from "../../types/BaseResponse";

export const getFollowing = async () => {
try{
const response = await instance.get<BaseResponse<FollowingType>>('following')
const response = await instance.get<BaseResponse<FollowingType>>('/following')
console.log('response', response)
return response.data.result || undefined
} catch (error) {
Expand Down
23 changes: 23 additions & 0 deletions src/apis/follow/unFollow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import instance from "../instance";
import { FollowType } from "../../types/follow/FollowType";

export const unFollow = async (follow: FollowType): Promise<FollowType> => {
const { followingId } = follow;

console.log(follow);

try {
const result = await instance.delete(`/unfollow`, {
params: { followingId }
});

console.log(result);

// Axios의 응답 객체에서 실제 데이터를 추출하여 반환
return result.data as FollowType;

} catch (error) {
console.error("Unfollow request failed", error);
throw error; // 에러가 발생한 경우 상위로 전달
}
};
22 changes: 22 additions & 0 deletions src/apis/follow/useDeleteUnFollow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useMutation, useQueryClient } from "react-query";
import { unFollow } from "./unFollow";
import { FollowType } from "../../types/follow/FollowType";

export const useDeleteUnFollow = () => {
const queryClient = useQueryClient();

const mutation = useMutation({
mutationFn: async (follow: FollowType) => {
console.log(follow)
return await unFollow(follow)
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey : ['unfollowData']});
},
onError: (error :Error) => {
console.log('Unfollow request failed', error);
},
});

return mutation;
}
4 changes: 3 additions & 1 deletion src/apis/follow/useGetFollowing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { FollowingType } from "../../types/follow/FollowingType";
export const fetchFollowing = async (token:string| undefined): Promise<FollowingType | undefined> => {
try {
if(token) {
return await getFollowing();
const result = await getFollowing();
console.log(result)
return result;
} else {
return undefined;
}
Expand Down
1 change: 0 additions & 1 deletion src/apis/follow/usePostFollow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// src/apis/follow/usePostFollow.ts
import { useMutation, useQueryClient } from 'react-query';
import instance from '../instance';
import { FollowType } from '../../types/follow/FollowType';
Expand Down
2 changes: 0 additions & 2 deletions src/apis/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ instance.interceptors.request.use(
) {
config.headers['Authorization'] = `Bearer ${state.accessToken}`;
}
console.log('axios config : ', config);
return config;
},
(error) => {
Expand All @@ -30,7 +29,6 @@ instance.interceptors.request.use(
// 응답 인터셉터
instance.interceptors.response.use(
(response) => {
console.log('response: ', response);
return response;
},
// (error) => {
Expand Down
31 changes: 30 additions & 1 deletion src/apis/keywords/keywordMap.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
import instance from "../instance";
import { APIKeywordMapType } from "../../types/keywords/APIKeywordMapType";
import { BaseResponse } from "../../types/BaseResponse";
import { KeywordType } from "../../types/keywords/KeywordType";
import { MapsType } from "../../types/keywords/MapsType";

export const keywordMap = async (keyword:string) => {
try {
const response = await instance.get<BaseResponse<APIKeywordMapType[] | undefined>>(`home/map/keyword`, {
params: { keyword }
})
return response.data.result;

const results = response.data.result?.map((item) => {
const newKeyword:KeywordType = {
id: Math.random(),
title: keyword,
selected:false,
}

const newMaps: MapsType[] = item.maps.map((map) => {
const keywords: KeywordType[] = map.mapKeywords.map((title, index) => ({
id: index,
title: title,
selected: false,
}));

return {
...map,
mapKeywords: keywords,
};
});

return {
keyword: newKeyword,
maps: newMaps,
};
});

return results;
}catch(error) {
console.error('Error fetching data:', error);
return undefined;
Expand Down
2 changes: 0 additions & 2 deletions src/apis/mapData/exploreMap.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import instance from "../instance";
import { ExploreMapType } from "../../types/mapData/ExploreMapType";
import { BaseResponse } from "../../types/BaseResponse";
import { KeywordType } from "../../types/keywords/KeywordType";
import { APIExploreMapType } from "../../types/mapData/APIExploreMapType ";
Expand All @@ -20,7 +19,6 @@ export const exploreMap = async (searchType:string, size: number, page:number) =
title: title,
selected: false,
}));
console.log('newKeyword:', newKeyword);

return {
...item,
Expand Down
4 changes: 2 additions & 2 deletions src/apis/mapData/followingMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { BaseResponse } from "../../types/BaseResponse";

export const followingMap = async () => {
try {
const response = await instance.get<BaseResponse<FollowingMapType[] | undefined>>('/home/map')
console.log('followingmap:', response)
const response = await instance.get<BaseResponse<FollowingMapType[] | undefined>>('/home/map');
console.log(response)
return response.data.result;
} catch (error) {
console.error('Error fetching data:',error);
Expand Down
1 change: 0 additions & 1 deletion src/apis/mapData/getExploreMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { exploreMap } from "./exploreMap";
export const getExploreMap = async(searchType:string, size: number, page:number) => {
try{
const response = await exploreMap(searchType,size,page);
console.log(response)
return response;
} catch (error) {
console.error('Error fetching random map:',error);
Expand Down
11 changes: 11 additions & 0 deletions src/apis/mapData/getSearchMap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { searchMap } from "./searchMap";

export const getSearchMap = async (searchType:string, searchWord:string,size: number, page:number) => {
try{
const response = await searchMap(searchType,searchWord,size,page);
return response;
} catch (error) {
console.error('Error fetching random map:',error);
return undefined;
}
}
34 changes: 34 additions & 0 deletions src/apis/mapData/searchMap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import instance from "../instance";
import { BaseResponse } from "../../types/BaseResponse";
import { APIExploreMapType } from "../../types/mapData/APIExploreMapType ";
import { KeywordType } from "../../types/keywords/KeywordType";

export const searchMap = async (searchType: string, searchWord:string,size:number,page:number) => {
try {
const response = await instance.get<BaseResponse<APIExploreMapType[] | undefined>> (`/map/search`, {
params: {
searchType,
searchWord,
size,
page
}
})

const results = response.data.result?.map((item) => {
const newKeyword : KeywordType[]= item.keyword.map((title: string, index) => ({
id: index,
title: title,
selected: false,
}));
return {
...item,
keyword: newKeyword,
};
});

return results;
} catch(error) {
console.error('Error fetchgin data:',error);
return undefined;
}
}
File renamed without changes
8 changes: 8 additions & 0 deletions src/assets/btn_logout.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/assets/ico_font_alert.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/assets/ico_profile_edit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 0 additions & 8 deletions src/assets/logout.svg

This file was deleted.

8 changes: 5 additions & 3 deletions src/components/explore/ErrorPage.module.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
.errorPageRoot {
width: 1382px;
height: 855px;
width: 100%;
height: calc(100vh - 181px);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center; /* 텍스트를 중앙 정렬 */
}

.text {
color: #767d86;
font-size: 18px;
font-style: normal;
font-weight: 400;
line-height: 150%;
text-align: center;
}
8 changes: 6 additions & 2 deletions src/components/explore/ErrorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ interface ErrorPageProps {
const ErrorPage: React.FC<ErrorPageProps> = ({ text }) => {
return (
<div className={styles.errorPageRoot}>
{text && <span>'{text}'지도를 찾을 수 없어요.</span>}
<span>다른 검색어를 시도해 주세요.</span>
{text && (
<div className = {styles.text}>
<p>'{text}'지도를 찾을 수 없어요.</p>
<p>다른 검색어를 시도해 주세요.</p>
</div>
)}
</div>
);
};
Expand Down
Loading

0 comments on commit 1b42ec0

Please sign in to comment.