-
Notifications
You must be signed in to change notification settings - Fork 3
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
[Feat/#60] 메인 페이지 뉴스 조회 API 연결 #62
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,11 @@ import { get } from '@apis/index'; | |
import { AxiosResponse } from 'axios'; | ||
import { getNewsResponse, newsList } from 'src/types/news'; | ||
|
||
export const getNews = async (): Promise<newsList[] | null> => { | ||
export const getNews = async (cursor?: number): Promise<newsList[] | null> => { | ||
try { | ||
const response: AxiosResponse<getNewsResponse> = await get('/news'); | ||
const response: AxiosResponse<getNewsResponse> = await get( | ||
`/news${cursor ? `?cursor=${cursor}` : ''}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
); | ||
return response.data.news; | ||
} catch (error) { | ||
console.log('error', error); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,12 @@ import { newsList } from 'src/types/news'; | |
import { getNews } from './api'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
export const useNews = () => | ||
export const useNews = (cursor: number) => | ||
useQuery<newsList[] | null>({ | ||
queryKey: ['news'], // 쿼리 키 | ||
queryFn: getNews, // API 함수 | ||
staleTime: 1000 * 60 * 5, // 5분 | ||
gcTime: 1000 * 60 * 10, // 10분 | ||
retry: 3, // 실패 시 재시도 횟수 | ||
queryKey: ['news', cursor], | ||
queryFn: () => getNews(cursor), | ||
staleTime: 1000 * 60 * 60, | ||
gcTime: 1000 * 60 * 60 * 12, | ||
retry: 3, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 쿼리 세팅 값들은 그냥 보편적으로 사용되는 세팅값인가요? 아니면 고려하고 설정한게 있나요?? 궁금해서 여쭤보는 것... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 개발자가 쿼리마다 적절하게 지정해주는 것으로 알고 있습니다!! |
||
refetchOnWindowFocus: false, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ export const TitleStyle = (isThreeLines: boolean) => (theme: Theme) => css` | |
color: ${theme.colors.gray500}; | ||
${theme.fonts.title07}; | ||
overflow: auto; | ||
word-break: keep-all; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 미친거니 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 왜그러니~~~~! |
||
} | ||
`; | ||
|
||
|
@@ -61,14 +62,15 @@ export const SkeletonText = (theme: Theme) => css` | |
display: block; | ||
width: 13.1rem; | ||
height: fit-content; | ||
min-height: 1.8rem; | ||
|
||
color: transparent; | ||
${theme.fonts.title07}; | ||
overflow: auto; | ||
} | ||
|
||
p::after { | ||
content: ''; | ||
content: 'dd'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 디버깅의 흔적인가요?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ㄷㄷ 야무지다 |
||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { HOMECARD_LIST } from '@constants/main/homeCardList'; | ||
import { newsList } from 'src/types/news'; | ||
|
||
export const mergeNewsWithImages = ( | ||
news: newsList[] | null | undefined, | ||
images: typeof HOMECARD_LIST, | ||
) => | ||
news?.map((item, index) => { | ||
const matchedImage = images[index % images.length]; | ||
return { | ||
...item, | ||
img: matchedImage ? matchedImage.img : null, | ||
}; | ||
}) || []; |
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.
디버깅의 흔적인가요??
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.
로그인 토큰 넣을 때 필요한데, 이번 합세에서는 헤더에 넣는 요청들이 없더라구요! 그래서 지웠습니다...ㅎ