-
Notifications
You must be signed in to change notification settings - Fork 6
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
[FE] Refactor/#365 API 요청 로직 분리 및 컴포넌트 분리 #368
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
e986138
rename: 2 Depth 컴포넌트 디렉토리 구조 변경
semnil5202 8c2474b
refactor: 서버와 지도 GET API 요청 로직 분리
semnil5202 d55705d
refactor: 서버와 로그인 GET API 분리
semnil5202 ce98032
refactor: api 요청 로직 에러 핸들링 추가 및 명시적으로 조건문 지정
semnil5202 15ab15d
fix: 누락된 api 수정 적용
semnil5202 813abba
rename: 사용하지 않는 svg 제거 및 오타 수정
semnil5202 2546e27
refactor: 타입명 코드 컨벤션에 맞게 모두 변경
semnil5202 f941846
refactor: api get 요청 로직 커스텀 훅으로 분리
semnil5202 1ad8b58
feat: usePost api 요청 커스텀 훅 생성
semnil5202 dac9544
feat: usePut api 요청 커스텀 훅 생성
semnil5202 e6c0e85
feat: useDelete api 요청 커스텀 훅 생성
semnil5202 85090f4
remove: 사용하지 않는 페이지 컴포넌트 제거
semnil5202 b0225e8
fix: delete 요청을 두 번씩 날리는 오류 수정
semnil5202 580bfdd
refactor: Home 컴포넌트 뎁스 줄임 및 fetchGet 적용
semnil5202 8876235
remove: 불필요한 페이지 컴포넌트 제거
semnil5202 cd0efd1
refactor: bookmark 페이지 및 관련 컴포넌트 관심사 분리
semnil5202 d1c9fe5
rename: 불필요한 페이지 제거 및 페이지명 변경
semnil5202 9120741
refactor: 누락된 타입 프로퍼티 추가
semnil5202 73f3602
fix: 유효하지 않은 주소를 클릭 시 에러 토스트를 띄우는 기능 수정
semnil5202 da84f79
rename: Topic Card 컴포넌트를 담는 상위 컨테이너 컴포넌트 명 변경
semnil5202 d0f66dc
design: myInfo의 사용자 성명 font weight 수정
semnil5202 bd7f45d
style: 불필요한 import 제거 및 공백 수정
semnil5202 a7043b2
refactor: 중복되는 역할의 컴포넌트 제거 후 재사용
semnil5202 a7f7838
refactor: 잘못된 에러 메시지 수정
semnil5202 9387a24
design: 내가 만든 지도가 없을 경우 사용자에게 알림 문구 더 친화적으로 수정
semnil5202 35685c1
refactor: 중복 컴포넌트 제거 및 TopicCardList 재사용 반영
semnil5202 0b84692
refactor: 10m 이내로 핀이 찍힐 확률을 줄이면서 사용성을 개선할 수 있는 줌 Limit 수정
semnil5202 973904b
rename: 스켈레톤 컴포넌트 불규칙했던 디렉토리 구조 통일
semnil5202 5384aa0
rename: NotFound 페이지 컴포넌트 디렉토리 위치 조정
semnil5202 45b165e
refactor: usePost를 success message 대신 onSuccess 함수 받도록 변경
semnil5202 7d708be
refactor: 모달용 토픽 카드 컴포넌트 제거 후 기존 토픽카드에 타입 프롭 추가
semnil5202 95f27be
refactor: put, delete api 요청 hook interface 조정
semnil5202 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { deleteApi } from '../apis/deleteApi'; | ||
import useToast from '../hooks/useToast'; | ||
import { ContentTypeType } from '../types/Api'; | ||
|
||
interface fetchDeleteProps { | ||
url: string; | ||
contentType?: ContentTypeType; | ||
} | ||
|
||
const useDelete = () => { | ||
const { showToast } = useToast(); | ||
|
||
const fetchDelete = async ( | ||
{ url, contentType }: fetchDeleteProps, | ||
errorMessage: string, | ||
onSuccess: () => void, | ||
) => { | ||
try { | ||
await deleteApi(url, contentType); | ||
|
||
if (onSuccess) { | ||
onSuccess(); | ||
} | ||
} catch (e) { | ||
showToast('error', errorMessage); | ||
} | ||
}; | ||
|
||
return { fetchDelete }; | ||
}; | ||
|
||
export default useDelete; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { getApi } from '../apis/getApi'; | ||
import useToast from '../hooks/useToast'; | ||
|
||
const useGet = () => { | ||
const { showToast } = useToast(); | ||
|
||
const fetchGet = async <T>( | ||
url: string, | ||
errorMessage: string, | ||
onSuccess: (responseData: T) => void, | ||
) => { | ||
try { | ||
const responseData = await getApi<T>(url); | ||
onSuccess(responseData); | ||
} catch (e) { | ||
showToast('error', errorMessage); | ||
} | ||
}; | ||
|
||
return { fetchGet }; | ||
}; | ||
|
||
export default useGet; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { postApi } from '../apis/postApi'; | ||
import useToast from '../hooks/useToast'; | ||
import { ContentTypeType } from '../types/Api'; | ||
|
||
interface fetchPostProps { | ||
url: string; | ||
payload: {}; | ||
contentType?: ContentTypeType; | ||
} | ||
|
||
const usePost = () => { | ||
const { showToast } = useToast(); | ||
|
||
const fetchPost = async ( | ||
{ url, payload, contentType }: fetchPostProps, | ||
errorMessage: string, | ||
onSuccess?: () => void, | ||
) => { | ||
try { | ||
const responseData = await postApi(url, payload, contentType); | ||
|
||
if (onSuccess) { | ||
onSuccess(); | ||
} | ||
|
||
return responseData; | ||
} catch (e) { | ||
showToast('error', errorMessage); | ||
} | ||
}; | ||
|
||
return { fetchPost }; | ||
}; | ||
|
||
export default usePost; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { putApi } from '../apis/putApi'; | ||
import useToast from '../hooks/useToast'; | ||
import { ContentTypeType } from '../types/Api'; | ||
|
||
interface fetchPutProps { | ||
url: string; | ||
payload: {}; | ||
contentType?: ContentTypeType; | ||
} | ||
|
||
const usePut = () => { | ||
const { showToast } = useToast(); | ||
|
||
const fetchPut = async ( | ||
{ url, payload, contentType }: fetchPutProps, | ||
errorMessage: string, | ||
onSuccess?: () => void, | ||
) => { | ||
try { | ||
const responseData = await putApi(url, payload, contentType); | ||
|
||
if (onSuccess) { | ||
onSuccess(); | ||
} | ||
|
||
return responseData; | ||
} catch (e) { | ||
showToast('error', errorMessage); | ||
} | ||
}; | ||
|
||
return { fetchPut }; | ||
}; | ||
|
||
export default usePut; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export const getLoginApi = async <T>(url: string) => { | ||
const response = await fetch(url, { | ||
method: 'GET', | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
}); | ||
|
||
if (response.status >= 400) { | ||
throw new Error('[KAKAO] GET 요청에 실패했습니다.'); | ||
} | ||
|
||
const responseData: T = await response.json(); | ||
|
||
return responseData; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
export const getMapApi = (url: string) => | ||
fetch(url, { | ||
export const getMapApi = async <T>(url: string) => { | ||
const response = await fetch(url, { | ||
method: 'GET', | ||
headers: { | ||
'Content-type': 'application/json', | ||
'content-type': 'application/json', | ||
}, | ||
}) | ||
.then((data) => { | ||
return data.json(); | ||
}) | ||
.catch((error) => { | ||
throw new Error(`${error.message}`); | ||
}); | ||
}); | ||
|
||
if (response.status >= 400) { | ||
throw new Error('[MAP] GET 요청에 실패했습니다.'); | ||
} | ||
|
||
const responseData: T = await response.json(); | ||
|
||
return responseData; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
세인 이 부분에서
'Content-Type': '${contentType || 'application/json'}'
이 부분을'content-type': 'application/json'
과 if문으로 나누신 이유가 있을까요?!!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사실 취향 차이인 것 같습니다만, userToken if 블록과 통일성을 위해서 contentType도 분리해보았습니다. 로직상으로는 차이가 없지만 가독성 측면에서 좀 더 낫지 않나 싶어서 위와 같이 변경하였는데 패트릭은 어떠신가요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
처음에 봤을 때는 'Content-Type':
${contentType || 'application/json'}
, 이 부분이 더 낫다고 생각했는데 세인의 의도를 알고나니 if문을 사용해 통일성을 가져가는 것도 좋은 것 같습니다 ! 굿!