Skip to content

Conversation

@HongbiKo
Copy link
Contributor

@HongbiKo HongbiKo commented Dec 20, 2024

#️⃣연관된 이슈

#22

📝작업 내용

메인 페이지 작업

  1. 메인페이지 태그리스트 검색바 디자인 수정 cf2cd1d c832f3f
  2. 페이지네이션 추가 6af12c6
  3. 메인페이지 페이지에서 전반적인 api 통신하도록 수정 17d87ef 0eed3c6 7afea10
  4. 데이터 fetch하는 부분 따로 파일로 빼서 분기 4f02a2d
  • 태그를 아무것도 누르지 않았을때 전체 게시글 보이기

Screen Shot 2024-12-20 at 10 16 56 PM

  • 태그 하나만 선택했을때 해당 태그 관련 게시글 보이기

Screen Shot 2024-12-20 at 10 14 30 PM

  • 태그 중복 선택했을때 중복 태그한 게시글 보이기

Screen Shot 2024-12-20 at 10 14 20 PM

💬리뷰 요구사항(선택)

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요

동현님과 얘기해봐야겠지만, 검색했을때 게시글이 나오는 기능은 시간이 없어서 안될듯합니다,,! 나중에 도전해보겠습니다:)

많이 늦어서 죄송합니다..!

@HongbiKo HongbiKo added ✨ Feature 기능 개발 🎨 Html&css 마크업 & 스타일링 📬 API 서버 API 통신 🔨 Refactor 코드 리팩토링 🙋‍♂️ Question Further information is requested labels Dec 20, 2024
Comment on lines 11 to 45
const fetchPostsByTags = async (selectedTags: number[]) => {
const params = new URLSearchParams();
selectedTags.forEach((tag) => {
params.append('tags', tag.toString());
});

const response = await axios.get('/api/main/tags', {
params
});
console.log('tagsposts', response.data); // html 형식으로 날아옴
return response.data;
};

const useMainData = (selectedTags: number[]) => {
const location = useLocation();
const params = new URLSearchParams(location.search);

const { data, isLoading, error } = useQuery({
queryKey: ['mainData', location.search, selectedTags],
queryFn: () =>
fetchMainData({
currentPage: params.get('page') ? Number(params.get('page')) : 1,
limit: 20,
}),
enabled: selectedTags.length === 0
});

return {
posts: data?.posts,
tags: data?.tags,
pagination: data?.pagination,
isLoading,
error,
};
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 훅이나 fetch문은 외부에서 관리하면 컴포넌트가 조금 더 보기 편해질 것 같아요.
DM 드렸던대로 하나의 useQuery문 안에서 해결하는 방법을 적용해보면 더 좋을 것 같고요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네! 멘토님의 조언 덕분에 잘 해결해나가고 있습니다! 감사합니다:)

const params = new URLSearchParams(location.search);

const { data, isLoading, error } = useQuery({
queryKey: ['mainData', location.search, selectedTags],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

queryKey는 둘 중 하나만 있어도 되지 않을까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵! 지금 멘토님 말대로 열심히 수정해보겠습니다:)

params.append('tags', tag.toString());
});

const response = await axios.get('/api/main/tags', {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗!!! 얘 api요청이 아니에요!!!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

멘토님 ㅠㅠㅠㅠ 이거때문에 ㅠㅠㅠㅠ 어제,, 몇시간을 허비했네요 ㅠㅠ 감사해요

@HongbiKo HongbiKo changed the title Feature/22 메인페이지 태그리스트,페이지네이션,게시물 Feature/22 메인페이지 태그리스트,페이지네이션,게시물(최종pr) Dec 20, 2024
@HongbiKo HongbiKo marked this pull request as ready for review December 20, 2024 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📬 API 서버 API 통신 ✨ Feature 기능 개발 🎨 Html&css 마크업 & 스타일링 🙋‍♂️ Question Further information is requested 🔨 Refactor 코드 리팩토링

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants