Skip to content

Commit

Permalink
fix, 로딩이 계속 떠 있는 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jaewoongs committed Jun 22, 2024
1 parent 6002fa0 commit e6815e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/components/templates/TeamRecommend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useCallback, useState } from 'react';
import { RecommendUserQueryOptions, useRecommendUserQuery } from '#/hooks/use-recommend';
import { RecommendFilter } from './TeamRecommend/RecommendFilter';
import { UserCardList } from './TeamRecommend/UserCardList';
import { Loading } from '../atoms';

export const TeamRecommend = () => {
const [options, setOptions] = useState<RecommendUserQueryOptions>({
Expand All @@ -17,6 +16,7 @@ export const TeamRecommend = () => {
mutate: mutateCachedUsers,
isValidating,
setSize,
isLoading,
} = useRecommendUserQuery(options);

const queryTrigger = useCallback(() => setSize((s) => s + 1), [setSize]);
Expand Down Expand Up @@ -46,17 +46,19 @@ export const TeamRecommend = () => {
[mutateCachedUsers, users]
);

if (!users) return <Loading />;
return (
<>
<RecommendFilter defaultOptions={options} trigger={setOptions} />
<UserCardList
users={users?.flat()}
isLoadingUsers={isValidating}
hasNext={users[users.length - 1].length > 0}
queryTrigger={queryTrigger}
mutateCachedLike={mutateCachedLike}
/>
{users && (
<UserCardList
users={users?.flat()}
isLoadingUsers={isValidating}
hasNext={users[users.length - 1].length > 0}
queryTrigger={queryTrigger}
mutateCachedLike={mutateCachedLike}
isLoading={isLoading}
/>
)}
</>
);
};
4 changes: 3 additions & 1 deletion src/components/templates/TeamRecommend/UserCardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface UserCardListProps {
isLiked: boolean | Promise<boolean>,
optimisticIsLiked: boolean
) => void;
isLoading: boolean;
}

export const UserCardList = ({
Expand All @@ -34,6 +35,7 @@ export const UserCardList = ({
hasNext,
queryTrigger,
mutateCachedLike,
isLoading,
}: UserCardListProps) => {
const observerRef = useRef<HTMLDivElement>(null);

Expand Down Expand Up @@ -74,7 +76,7 @@ export const UserCardList = ({
mutateCachedLike={mutateCachedLike}
/>
))}
{hasNext && <Loading ref={observerRef} />}
{isLoading && <Loading ref={observerRef} />}
</GridBlock>
</>
);
Expand Down

0 comments on commit e6815e0

Please sign in to comment.