Skip to content

Commit cc4547c

Browse files
committed
fix: typeError해결
1 parent d6b9eff commit cc4547c

5 files changed

Lines changed: 22 additions & 11 deletions

File tree

src/lib/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios from "axios";
2-
import useUserStore from "../store/useUserStore";
2+
// import useUserStore from "../store/useUserStore";
33
const api = axios.create({
44
baseURL: "https://techfork.shop",
55
});

src/pages/home/HomePage.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ import {
2121
useGetRecommendPostList,
2222
usePostRecommendPostList,
2323
} from "../../lib/recommendation";
24+
import type { InterestTypeDto } from "../../types/my";
2425

2526
export const HomePage = () => {
2627
const [selectedTab, setSelectedTab] = useState(0); // 0 = 기업별 게시글
2728
const [modal, setModal] = useState(false);
2829
const { companies, toggleCompany } = useCompanyStore();
29-
// console.log(companies);
30-
3130
const companyQuery = useInfiniteCompaniesPosts({
3231
companies,
3332
});
@@ -57,6 +56,7 @@ export const HomePage = () => {
5756

5857
//회사 불러오기
5958
const { data: companyData } = useGetCompany();
59+
console.log(companyData);
6060

6161
const infiniteRef = useRef<HTMLDivElement | null>(null);
6262

@@ -70,9 +70,10 @@ export const HomePage = () => {
7070
const isFetchingNextPage = infiniteQuery?.isFetchingNextPage;
7171

7272
const { data: myInterest } = useGetMyInterest();
73+
console.log(myInterest);
7374

7475
useEffect(() => {
75-
if (!infiniteRef.current || !hasNextPage) return;
76+
if (!infiniteRef.current || !hasNextPage || !fetchNextPage) return;
7677
const observer = new IntersectionObserver(entries => {
7778
if (entries[0].isIntersecting && !isFetchingNextPage) {
7879
fetchNextPage();
@@ -91,7 +92,7 @@ export const HomePage = () => {
9192
return data?.flatMap((page: PostResponseDto) => page.data.posts) ?? [];
9293
})();
9394

94-
console.log(posts);
95+
// console.log(posts);
9596

9697
//게시글
9798
const maxCompany = companyData.companies.slice(0, 8);
@@ -116,7 +117,7 @@ export const HomePage = () => {
116117
<div className=" body-sb-14">선택된 기업:</div>
117118
{companies.map(company => {
118119
const matchedCompany = companyData.companies.find(
119-
item => item.company === company,
120+
(item: CompanyType) => item.company === company,
120121
);
121122

122123
return (
@@ -171,7 +172,7 @@ export const HomePage = () => {
171172
<>
172173
<div className=" flex gap-2 flex-wrap py-4">
173174
<p className="body-r-14 mr-2">나의 관심 분야:</p>
174-
{myInterest.map(item =>
175+
{myInterest.map((item: InterestTypeDto) =>
175176
TagCodeToLabel(item.category, item.keywords).map(label => (
176177
<SelectionBtn key={`${item.category}-${label}`}>
177178
{label}
@@ -192,6 +193,7 @@ export const HomePage = () => {
192193

193194
<ul className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-4">
194195
{posts.map(item => {
196+
const isSelected = selectedTab === 1;
195197
return (
196198
<CardItem
197199
company={item.company}
@@ -201,7 +203,7 @@ export const HomePage = () => {
201203
title={item.title}
202204
thumbnailUrl={item.thumbnailUrl}
203205
url={item.url}
204-
id={item.id}
206+
id={isSelected ? item.postId : item.id}
205207
isBookmarked={item.isBookmarked}
206208
/>
207209
);

src/shared/CardItem.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ export const CardItem = forwardRef<HTMLLIElement, CardItemProps>(
2525
//북마크 추가
2626
const handleSubmitPostBookmark = usePostBookmark();
2727
const handleSubmitDeleteBookmark = useDeleteBookmark();
28-
const handleClick = e => {
28+
const handleClick = (e: React.MouseEvent) => {
2929
e.stopPropagation();
3030
e.preventDefault();
31+
if (!id) return;
3132
if (isBookmarked) {
32-
handleSubmitDeleteBookmark.mutate(id ?? 0);
33+
handleSubmitDeleteBookmark.mutate(id);
3334
} else {
34-
handleSubmitPostBookmark.mutate(id ?? 0);
35+
handleSubmitPostBookmark.mutate(id);
3536
}
3637
};
3738

src/types/my.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//나와맞는게시글
2+
3+
export type InterestTypeDto = {
4+
category: string;
5+
keywords: string[];
6+
};

src/types/post.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ export type CardItemProps = {
3333
logoUrl: string;
3434
thumbnailUrl: string;
3535
publishedAt?: string;
36+
isBookmarked: boolean;
3637
viewCount: number;
3738
keywords?: string[];
39+
postId?: number;
3840
};
3941

4042
export type PageParamType = {

0 commit comments

Comments
 (0)