Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

도감페이지 로딩ui 적용 및 디자인 수정 #84

Merged
merged 5 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const App = () => {
}
/>
<Route
path="/cardEdit"
path="/cardedit"
element={
<RequireAuth>
<Card />
Expand Down
6 changes: 5 additions & 1 deletion src/components/cardMaker/CardEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ const CardEditPage = () => {
<SelectPokemonLike />
<SelectPokemonRandom />
</div>
<button className={styles.save_button} onClick={onSave}>
<button
disabled={!pokemonName?.length}
className={styles.save_button}
onClick={onSave}
>
저장하기
</button>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/components/cardMaker/cardEditPage.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
border: none;
cursor: pointer;
font-family: GmarketSansMedium;

&:disabled {
background-color: #dddddd;
}
}

.title {
Expand Down
35 changes: 20 additions & 15 deletions src/components/cardMaker/selectPokemon/SelectPokemonLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import { useCallback } from 'react';

interface SelectPokemonLayoutProps {
pokemonArray: (PokemonType | null)[];
range: number;
}

const SelectPokemonLayout = ({ pokemonArray }: SelectPokemonLayoutProps) => {
const SelectPokemonLayout = ({
pokemonArray,
range,
}: SelectPokemonLayoutProps) => {
const { setPokemonData, generateRandomNicknames } =
useSelectedPokemonForCard();

Expand All @@ -23,17 +27,17 @@ const SelectPokemonLayout = ({ pokemonArray }: SelectPokemonLayoutProps) => {

return (
<div className={styles.layout_wrapper}>
{pokemonArray.map((pokemonData, index) => (
{Array.from({ length: range }, (_, index) => (
<div
key={pokemonData ? pokemonData.id : index}
key={pokemonArray[index] ? pokemonArray[index]?.id : index}
className={styles.layout_container}
>
<div className={styles.image}>
{pokemonData ? (
{pokemonArray[index] ? (
<img
src={
pokemonData.id !== 1013
? pokemonData.sprites?.other?.['official-artwork']
pokemonArray[index]?.id !== 1013
? pokemonArray[index]?.sprites?.other?.['official-artwork']
?.front_default
: '/pokemonImg/그우린차.webp'
}
Expand All @@ -42,16 +46,17 @@ const SelectPokemonLayout = ({ pokemonArray }: SelectPokemonLayoutProps) => {
) : null}
</div>
<span>
{pokemonData ? reverseObject(POKEMON_NAME)[pokemonData.name] : ''}
{pokemonArray[index]
? reverseObject(POKEMON_NAME)[pokemonArray[index]!.name]
: ''}
</span>
{pokemonData ? (
<button
className={styles.border_button}
onClick={() => handlePokemonSelection(pokemonData)}
>
포켓몬 사용
</button>
) : null}
<button
disabled={!pokemonArray[index]}
className={styles.border_button}
onClick={() => handlePokemonSelection(pokemonArray[index])}
>
포켓몬 사용
</button>
</div>
))}
</div>
Expand Down
5 changes: 4 additions & 1 deletion src/components/cardMaker/selectPokemon/SelectPokemonLike.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ const SelectPokemonLike = () => {
>
<IoChevronBack />
</button>
<SelectPokemonLayout pokemonArray={likePokemonArray} />
<SelectPokemonLayout
pokemonArray={likePokemonArray}
range={POKEMONS_PER_PAGE}
/>
<button
className={styles.page_button}
onClick={nextSlide}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ const SelectPokemonRandom = () => {
<div className={styles.select_wrapper}>
<span className={styles.title}>랜덤 포켓몬</span>
<div className={styles.random_container}>
<SelectPokemonLayout pokemonArray={randomPokemons} />
<SelectPokemonLayout
pokemonArray={randomPokemons}
range={POKEMONS_PER_PAGE}
/>
<button className={styles.border_button} onClick={getRandomPokemon}>
랜덤
</button>
Expand Down
7 changes: 6 additions & 1 deletion src/components/dex/PokemonDex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import PokemonDexElement from './PokemonDexElement';
import Inner from '../Inner';
import useFilteredPokemonData from '@/hook/useFilteredPokemonData';
import useVisibleDataByScroll from '@/hook/useVisibleDataByScroll';
import Loading from '../loading/Loading';

const PokemonDex = () => {
const filteredData = useFilteredPokemonData();
const { filteredData, isLoading } = useFilteredPokemonData();
const visibleData = useVisibleDataByScroll(filteredData);

if (isLoading) {
return <Loading />;
}

return (
<Inner>
<ul className={styles.pokemon_grid}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const Header = () => {
도감
</div>
</Link>
<Link to="cardEdit">
<Link to="cardedit">
<div className={styles.nav__item}>
<FiPlusSquare size={31} />
카드 제작
Expand Down
2 changes: 1 addition & 1 deletion src/components/header/MobileNavMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const MobileNavMenu = () => {
</div>
</NavLink>
<NavLink
to="cardEdit"
to="cardedit"
className={({ isActive }) => (isActive ? styles.active : '')}
>
<div className={styles.nav__item__mobile}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/mypage/MobileMypageAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const MobileMypageAlert = ({ isOpen }: { isOpen: boolean }) => {
const navigate = useNavigate();

const onMovetoMakecard = () => {
navigate('/cardEdit');
navigate('/cardedit');
};
return (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/components/mypage/Mycard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const Mycard = () => {
const onMoveMakeCard = () => {
if (windowWidth <= 768) {
setIsAlert((prev) => !prev);
} else navigate('/cardEdit');
} else navigate('/cardedit');
};

const onModalToggle = (card?: Card) => {
Expand Down
13 changes: 6 additions & 7 deletions src/components/plate/FilterPlates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import useSelectedStore from '@/store/useSelectedStore';
import PlateHideButton from './PlateHideButton';
import { useState } from 'react';
import { AnimatePresence, motion } from 'framer-motion';
import useCalculateInnerWidth from '@/hook/useCalculateInnerWidth';

const FilterPlates = () => {
const koreanTypes = Object.values(POKEMON_TYPES);
const [isOpen, setIsOpen] = useState<boolean>(false);
const { selectedPlate, setSelectedPlate } = useSelectedStore();
const innerWidth = useCalculateInnerWidth();

const variants = {
open: { height: '200px' },
closed: { height: 0 },
open: { height: '200px', opacity: 1 },
closed: { height: 0, opacity: 0 },
};

const renderTypes = (types: string[]) =>
Expand Down Expand Up @@ -44,13 +46,12 @@ const FilterPlates = () => {
return (
<div className={styles.wrapper}>
<AnimatePresence>
{isOpen ? (
{isOpen && (
<motion.div
initial="closed"
animate="open"
exit="closed"
variants={variants}
transition={{ duration: 0.3 }}
variants={innerWidth <= 768 ? {} : variants}
className={styles.container}
>
<div className={styles.inner}>
Expand All @@ -62,8 +63,6 @@ const FilterPlates = () => {
</motion.div>
</div>
</motion.div>
) : (
<div></div>
)}
</AnimatePresence>
<PlateHideButton isOpen={isOpen} setIsOpen={setIsOpen} />
Expand Down
8 changes: 5 additions & 3 deletions src/hook/useFilteredPokemonData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import useSelectedStore from '@/store/useSelectedStore';
import useSearchInputText from '@/store/useSearchInputText';

const useFilteredPokemonData = () => {
const { data: allPokemonData } = useGetAllPokemon(1017);
const { data: allPokemonData, isLoading } = useGetAllPokemon(1017);
const { selectedPlate } = useSelectedStore();
const { inputText } = useSearchInputText();
const reversedPokemonNameObject = reverseObject(POKEMON_NAME);

return useMemo(() => {
const filteredData = useMemo(() => {
if (!allPokemonData) return [];

return allPokemonData.filter((data: PokemonType) => {
if (inputText) {
return reversedPokemonNameObject[data?.name]?.includes(inputText);
}
if (!selectedPlate.length) {
return data;
return true;
}
const { types } = data;
return selectedPlate.every((plate: string) =>
Expand All @@ -32,6 +32,8 @@ const useFilteredPokemonData = () => {
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [allPokemonData, inputText, selectedPlate]);

return { filteredData, isLoading };
};

export default useFilteredPokemonData;
Loading