Skip to content

Commit

Permalink
feat: Remove users and posts with a score of 0 (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjeongmin committed May 30, 2024
1 parent 4188e5f commit 454d351
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 39 deletions.
11 changes: 5 additions & 6 deletions src/app/pages/main-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ export function MainPage() {
const [createdMarkers, setCreatedMarkers] = useState<naver.maps.Marker[]>([]);

useEffect(() => {
if (map == null) return;
if (map == null || recommendationMates == null) return;

recommendationMates?.data.forEach(mate => {
recommendationMates.forEach(mate => {
fromAddrToCoord({ query: mate.location }).then(res => {
const address = res.shift();
if (address == null) return;
Expand All @@ -209,7 +209,7 @@ export function MainPage() {
setCreatedMarkers(prev => prev.concat(marker));
});
});
}, [map, recommendationMates?.data, router]);
}, [map, recommendationMates, router]);

useEffect(() => {
if (map == null) return () => {};
Expand Down Expand Up @@ -271,16 +271,15 @@ export function MainPage() {
{auth?.user?.name}님의 추천 메이트
</styles.mateRecommendationTitle>
<styles.mateRecommendationRow>
{recommendationMates?.data != null &&
recommendationMates.data.length > 0 ? (
{recommendationMates != null && recommendationMates.length > 0 ? (
<>
<CircularButton
direction="left"
disabled={false}
onClick={handleScrollLeft}
/>
<styles.mateRecommendation ref={scrollRef}>
{recommendationMates.data.map(
{recommendationMates.map(
({
memberId,
score,
Expand Down
11 changes: 5 additions & 6 deletions src/app/pages/mobile/mobile-main-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ export function MobileMainPage() {
const [createdMarkers, setCreatedMarkers] = useState<naver.maps.Marker[]>([]);

useEffect(() => {
if (map == null) return;
if (map == null || recommendationMates == null) return;

recommendationMates?.data.forEach(mate => {
recommendationMates.forEach(mate => {
fromAddrToCoord({ query: mate.location }).then(res => {
const address = res.shift();
if (address == null) return;
Expand All @@ -202,7 +202,7 @@ export function MobileMainPage() {
setCreatedMarkers(prev => prev.concat(marker));
});
});
}, [map, recommendationMates?.data, router]);
}, [map, recommendationMates, router]);

useEffect(() => {
if (map == null) return () => {};
Expand Down Expand Up @@ -263,10 +263,9 @@ export function MobileMainPage() {
<styles.mateRecommendationTitle>
<h1>{auth?.user?.name}님의 추천 메이트</h1>
</styles.mateRecommendationTitle>
{recommendationMates?.data != null &&
recommendationMates.data.length > 0 ? (
{recommendationMates != null && recommendationMates.length > 0 ? (
<styles.mateRecommendation>
{recommendationMates.data.map(
{recommendationMates.map(
({
memberId,
score,
Expand Down
15 changes: 7 additions & 8 deletions src/app/pages/mobile/mobile-shared-posts-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ export function MobileSharedPostsPage() {

useEffect(() => {
if (selected === 'hasRoom' && sharedPosts != null) {
setTotalPageCount(sharedPosts.data.totalPages);
setTotalPageCount(sharedPosts.totalPages);
} else if (selected === 'dormitory' && dormitorySharedPosts != null) {
setTotalPageCount(dormitorySharedPosts.data.totalPages);
setTotalPageCount(dormitorySharedPosts.totalPages);
}
}, [selected, dormitorySharedPosts, sharedPosts]);

Expand All @@ -227,8 +227,8 @@ export function MobileSharedPostsPage() {
{selected === 'hasRoom' || selected === 'dormitory' ? (
<>
<styles.posts>
{posts?.data != null && posts.data.content.length > 0 ? (
posts?.data.content.map(post => (
{posts != null && posts.data.length > 0 ? (
posts.data.map(post => (
<PostCard
key={post.id}
post={post}
Expand All @@ -245,7 +245,7 @@ export function MobileSharedPostsPage() {
</styles.noRecommendation>
)}
</styles.posts>
{posts?.data.content.length !== 0 && (
{posts?.data.length !== 0 && (
<styles.pagingRow>
<styles.CircularButton
direction="left"
Expand Down Expand Up @@ -292,9 +292,8 @@ export function MobileSharedPostsPage() {
</>
) : (
<styles.cards>
{recommendationMates?.data != null &&
recommendationMates.data.length > 0 ? (
recommendationMates.data.map(
{recommendationMates != null && recommendationMates.length > 0 ? (
recommendationMates.map(
({
memberId,
score,
Expand Down
23 changes: 10 additions & 13 deletions src/app/pages/shared-posts-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ export function SharedPostsPage() {

useEffect(() => {
if (selected === 'hasRoom' && sharedPosts != null) {
setTotalPageCount(sharedPosts.data.totalPages);
setTotalPageCount(sharedPosts.totalPages);
} else if (selected === 'dormitory' && dormitorySharedPosts != null) {
setTotalPageCount(dormitorySharedPosts.data.totalPages);
setTotalPageCount(dormitorySharedPosts.totalPages);
}
}, [selected, dormitorySharedPosts, sharedPosts]);

Expand All @@ -221,7 +221,7 @@ export function SharedPostsPage() {
cardOption: filter.cardType ?? 'my',
filter: derivedFilter,
page,
}).then(res => res.data),
}).then(res => res),
});
} else if (selected === 'dormitory') {
queryClient.prefetchQuery({
Expand All @@ -238,7 +238,7 @@ export function SharedPostsPage() {
cardOption: filter.cardType ?? 'my',
filter: derivedFilter,
page,
}).then(res => res.data),
}).then(res => res),
});
}
}
Expand All @@ -262,15 +262,15 @@ export function SharedPostsPage() {
);
}

if (posts?.data == null || posts.data.content.length === 0) {
if (posts == null || posts.data.length === 0) {
return (
<styles.noRecommendation>
<p>추천되는 게시글이 없습니다.</p>
</styles.noRecommendation>
);
}

return posts?.data.content.map(post => (
return posts.data.map(post => (
<PostCard
key={post.id}
post={post}
Expand Down Expand Up @@ -307,18 +307,15 @@ export function SharedPostsPage() {
);
}

if (
recommendationMates?.data == null ||
recommendationMates.data.length === 0
) {
if (recommendationMates == null || recommendationMates.length === 0) {
return (
<styles.noRecommendation>
<p>추천되는 메이트가 없습니다.</p>
</styles.noRecommendation>
);
}

return recommendationMates.data.map(
return recommendationMates.map(
({ memberId, score, nickname, location, profileImageUrl, options }) => (
<Link href={`/profile/${memberId}`} key={memberId}>
<UserCard
Expand All @@ -334,7 +331,7 @@ export function SharedPostsPage() {
</Link>
),
);
}, [isMatesLoading, recommendationMates?.data]);
}, [isMatesLoading, recommendationMates]);

return (
<styles.container>
Expand All @@ -356,7 +353,7 @@ export function SharedPostsPage() {
{selected === 'hasRoom' || selected === 'dormitory' ? (
<>
<styles.posts>{renderPosts}</styles.posts>
{posts != null && posts.data.content.length !== 0 && (
{posts != null && posts.data.length !== 0 && (
<styles.pagingRow>
<styles.CircularButton
direction="left"
Expand Down
2 changes: 1 addition & 1 deletion src/features/profile/profile.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const getRecommendMates = async (cardOption: CardType) => {
const res = await axios.get<GetRecommendMatesDTO>(
`/maru-api/profile/recommend?cardOption=${cardOption}`,
);
return res.data;
return res.data.data.filter(mate => mate.score > 0);
};

export const patchProfileImage = async (fileName: string) =>
Expand Down
2 changes: 1 addition & 1 deletion src/features/profile/profile.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const useRecommendMates = ({
}) =>
useQuery({
queryKey: ['/profile/recommend', cardOption],
queryFn: async () => await getRecommendMates(cardOption),
queryFn: async () => await getRecommendMates(cardOption).then(res => res),
enabled,
});

Expand Down
10 changes: 8 additions & 2 deletions src/features/shared/shared.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export const getSharedPosts = async ({
return `${baseURL}?${encodeURI(query)}&cardOption=${cardOption}`;
};

return await axios.get<GetSharedPostsDTO>(getURI());
return await axios.get<GetSharedPostsDTO>(getURI()).then(res => ({
totalPages: res.data.data.totalPages,
data: res.data.data.content,
}));
};

export const createSharedPost = async (postData: SharedPostProps) =>
Expand Down Expand Up @@ -85,7 +88,10 @@ export const getDormitorySharedPosts = async ({
return `${baseURL}?${encodeURI(query)}&cardOption=${cardOption}`;
};

return await axios.get<GetDormitorySharedPostsDTO>(getURI());
return await axios.get<GetDormitorySharedPostsDTO>(getURI()).then(res => ({
totalPages: res.data.data.totalPages,
data: res.data.data.content,
}));
};

export const createDormitorySharedPost = async (postData: SharedPostProps) =>
Expand Down
4 changes: 2 additions & 2 deletions src/features/shared/shared.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ export const useSharedPosts = ({
filter: debounceFilter,
search,
page,
}).then(response => response.data),
}).then(res => res),
enabled,
});
};
Expand Down Expand Up @@ -477,7 +477,7 @@ export const useDormitorySharedPosts = ({
filter: debounceFilter,
search,
page,
}).then(response => response.data),
}).then(res => res),
enabled,
});
};
Expand Down

0 comments on commit 454d351

Please sign in to comment.