Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ipgo into fix/#511
  • Loading branch information
HyeryongChoi committed Oct 19, 2023
2 parents 509552e + 78b06e0 commit b51b249
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
20 changes: 13 additions & 7 deletions frontend/src/components/Food/FoodList/FoodList.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
import { Suspense } from 'react';
import { styled } from 'styled-components';

import { useInfiniteFoodListScroll } from '@/hooks/food/useInfiniteFoodListScroll';

import FoodItem from '../FoodItem/FoodItem';

const FoodList = () => {
const { foodList, hasNextPage, targetRef } = useInfiniteFoodListScroll();
const { foodList, hasNextPage, targetRef, isLoading, isFetching } = useInfiniteFoodListScroll();

if (!foodList) return null;
if (!foodList) return <Skeleton />;

const hasResult = Boolean(foodList.length);

return (
<FoodListWrapper>
{hasResult ? (
<FoodListContainer>
{foodList.map(food => (
<FoodItem key={food.id} {...food} />
))}
</FoodListContainer>
<>
<FoodListContainer>
{foodList.map(food => (
<Suspense key={food.id} fallback={<FoodItem.Skeleton />}>
<FoodItem {...food} />
</Suspense>
))}
</FoodListContainer>
{isFetching && <Skeleton />}
</>
) : (
<NoResultContainer>
<NoResultText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const Chart = (props: PropsWithChildren<ChartProps>) => {
<ChartLayout>
{chartInfo.map(({ name, percentage }) => (
<Data key={name}>
<DataName>{name}</DataName>
<DataName $width={Number(name) ? 'initial' : '26%'}>{name}</DataName>
<Bar>
<BarBackground />
<BarData percentage={percentage} />
Expand Down Expand Up @@ -120,10 +120,10 @@ const Data = styled.div`
justify-content: space-between;
`;

const DataName = styled.div`
const DataName = styled.div<{ $width?: number | string }>`
overflow: hidden;
max-width: 28%;
width: ${({ $width = '26%' }) => (typeof $width === 'string' ? $width : `${$width}px`)};
font-size: 1.2rem;
font-weight: 500;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/hooks/query/food.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const useFoodListInfiniteQuery = (payload: Parameter<typeof getFoodList>)
queryKey: [QUERY_KEY.petFoods, Object.values(payload).join()],
queryFn: ({ pageParam = { ...payload, size: String(SIZE_PER_PAGE) } }) =>
getFoodList(pageParam),
suspense: false,
getNextPageParam: (lastFoodListRes, allFoodListRes) => {
const [lastFood] = lastFoodListRes.petFoods.slice(-1);

Expand Down
2 changes: 2 additions & 0 deletions frontend/src/pages/FoodDetail/FoodDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ const BrandIconInfo = styled.p`
`;

const StandardToolTip = styled.button`
position: relative;
display: flex;
gap: 0.8rem;
align-items: center;
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/pages/Landing/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ const Landing = () => {
</BannerSection>
<ListSection>
<FilterBottomSheet />
<Suspense fallback={<FoodList.Skeleton />}>
<FoodList />
</Suspense>
<FoodList />
</ListSection>
</Layout>
</Template>
Expand Down

0 comments on commit b51b249

Please sign in to comment.