https://feelvieact.netlify.app/genre/movie/16
프로그래스바
const calculateProgress = () => {
return !listLoading ? 0 : 100;
};
<div className="progress"
style={{
width: `${props.progress}%`,
}}
></div>
장르 탭 선택 후 url 변경
const genreChange = async (itemId) => {
setListLoading(true);
setProgressState(true);
setGenreNumber(itemId);
navigate(`/genre/${type}/${itemId}`);
};
정렬 선택 + 이미지 없을 시
const SortClick = async (event) => {
try {
setSelectedValue(event.target.value);
setProgressState(true);
setListLoading(true);
let genreUrl;
switch (event.target.value) {
case 'popularityDesc' :
genreUrl = await movieApi.genrePopularDesc(type, genreNumber);
break;
case 'popularityAsc' :
genreUrl = await movieApi.genrePopularAsc(type, genreNumber);
break;
case 'dateDesc' :
genreUrl = await movieApi.genreDateDesc(type, genreNumber);
break;
case 'dateAsc' :
genreUrl = await movieApi.genreDateAsc(type, genreNumber);
break;
default:
break;
}
setGenreList(genreUrl.data.results);
} catch (error) {
console.log(error)
} finally {
setProgressState(false);
setListLoading(false);
}
}
useEffect(() => {
async function fetchApi() {
setProgressState(true);
setListLoading(true);
try {
const genre = await movieApi.genreTitle(type);
setGenreTitle(genre.data.genres);
if (number === 'All') {
const popular = await movieApi.popular(type);
setGenreList(popular.data.results);
setGenreNumber(number);
} else {
const genreUrl = await movieApi.genreList(type, genreNumber);
setGenreList(genreUrl.data.results);
}
setProgressState(false);
setListLoading(false);
} catch (error) {
console.log(error)
}
}
fetchApi();
}, [type, genreNumber]);
리스트 더보기
const listMoreBtn = () => {
setLoading(true);
ListMore();
}
const ListMore = debounce(() => {
const nextPage = page + 1;
const PageData = async () => {
try {
if (number === 'All') {
const popularScroll = await movieApi.popularScroll(type, nextPage);
setGenreList((prevGenreList) => [...prevGenreList, ...popularScroll.data.results]);
} else {
const genreUrlScroll = await movieApi.genreScroll(type, genreNumber, nextPage);
setGenreList((prevGenreList) => [...prevGenreList, ...genreUrlScroll.data.results]);
}
} finally {
setLoading(false);
}
};
setPage(nextPage);
PageData();
}, 1000);