Skip to content

Commit

Permalink
feature-075: lazy loading 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
gs0428 committed Feb 17, 2024
1 parent 1810a97 commit f706fa7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
10 changes: 3 additions & 7 deletions src/pages/CategoryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { IVideoProps } from 'types/videos';
import { sortVideos } from '@/utils/sortVideos';
import { CardContainer } from '@/styles/category/Card.style';
import VideoSelectMenu from '@/components/category/VideoSelectMenu';
import DefaultMenu from '@/components/category/DefaultMenu';
import { putVideoToOtherCategory } from '@/apis/category';
import handleVideo from '@/utils/handleVideo';
import CategoryPageSkeleton from '@/components/skeleton/CategoryPageSkeleton';
Expand All @@ -19,10 +18,12 @@ const CategoryTitle = React.lazy(
() => import('@/components/category/CategoryTitle'),
);
const Card = React.lazy(() => import('@/components/category/Card'));
const DefaultMenu = React.lazy(
() => import('@/components/category/DefaultMenu'),
);

const CategoryPage = () => {
const params = useParams();
const [isLoading, setIsLoading] = useState(true);
const [name, setName] = useState('');
const [menus, setMenus] = useState<ISubFolderProps[] | ITagProps[]>([]);
const [videos, setVideos] = useState<IVideoProps[]>([]);
Expand All @@ -44,7 +45,6 @@ const CategoryPage = () => {
setMenus,
setName,
setVideos,
setIsLoading,
);
setCheckedVideos([]);
}, [categories, params.sub_folder, params.top_folder]);
Expand Down Expand Up @@ -79,14 +79,10 @@ const CategoryPage = () => {
setMenus,
setName,
setVideos,
setIsLoading,
);
}
};

if (isLoading)
return <CategoryPageSkeleton isSubSkeleton={!!params.sub_folder} />;

return (
<Suspense
fallback={<CategoryPageSkeleton isSubSkeleton={!!params.sub_folder} />}
Expand Down
3 changes: 0 additions & 3 deletions src/utils/handleVideo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const handleVideo = async (
>,
setName: React.Dispatch<React.SetStateAction<string>>,
setVideos: React.Dispatch<React.SetStateAction<IVideoProps[]>>,
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>,
) => {
setIsLoading(true);
if (!topCategoryId) {
await getRecentVideos().then((res) => {
setVideos(res.result.videos);
Expand Down Expand Up @@ -42,7 +40,6 @@ const handleVideo = async (
setVideos(res.isSuccess ? res.result.videos : []);
});
}
setIsLoading(false);
};

export default handleVideo;

0 comments on commit f706fa7

Please sign in to comment.