Skip to content

Commit

Permalink
Merge pull request #52 from side-project-pokehub/Hun
Browse files Browse the repository at this point in the history
내가 찜한 포켓몬 리스트 페이지네이션으로 변경 및 카드 상세 보기 framer motion 적용
  • Loading branch information
cdm1263 authored Jan 13, 2024
2 parents bc97ad2 + cd3d063 commit 3f5a99c
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 10 deletions.
63 changes: 63 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"dompurify": "^3.0.6",
"file-saver": "^2.0.5",
"firebase": "^10.5.2",
"framer-motion": "^10.18.0",
"react-content-loader": "^6.2.1",
"react-dom": "^18.2.0",
"react-query": "^3.39.3",
Expand Down
2 changes: 1 addition & 1 deletion src/components/detail/Detail.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

&__comments {
margin-top: 50px;
margin: 50px 0 30px 0;
display: flex;
flex-direction: column;
justify-content: center;
Expand Down
8 changes: 7 additions & 1 deletion src/components/modal/CardModal.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@
cursor: pointer;
border: 3px solid #0f60ce;
border-radius: 10px;
background-color: inherit;
background-color: #0f60ce;
font-size: 24px;
color: #fff;

&:hover {
background-color: #fff;
color: #0f60ce;
}
}
}
52 changes: 48 additions & 4 deletions src/components/modal/CardModal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import {
motion,
useAnimation,
useMotionValue,
useTransform,
} from 'framer-motion';
import PokemonCard from '../card/PokemonCard';
import { Card } from '../mypage/Mycard';
import styles from './CardModal.module.scss';
Expand All @@ -16,6 +22,33 @@ interface CardModalProps {
const CardModal = ({ onModalToggle, cardData, isOpen }: CardModalProps) => {
const cardRef = useRef<HTMLDivElement>(null);

const x = useMotionValue(0);
const y = useMotionValue(0);
const rotateX = useTransform(y, [-1, 1], [-30, 30]);
const rotateY = useTransform(x, [-1, 1], [-30, 30]);

const controls = useAnimation();

const handleMouseMove = (e: MouseEvent<HTMLDivElement>) => {
if (cardRef.current) {
const rect = cardRef.current.getBoundingClientRect();
const offsetX = e.clientX - rect.left - rect.width / 2;
const offsetY = e.clientY - rect.top - rect.height / 2;

const xPercent = offsetX / (rect.width / 2);
const yPercent = offsetY / (rect.height / 2);

x.set(xPercent);
y.set(yPercent);
}
};
const handleMouseLeave = () => {
controls.start({
rotateX: 0,
rotateY: 0,
});
};

const card = cardData?.data;
const pokemonNickName = {
pokemonNickName1: card?.pokemonCardData[1],
Expand Down Expand Up @@ -53,20 +86,31 @@ const CardModal = ({ onModalToggle, cardData, isOpen }: CardModalProps) => {
<FiPlus size={20} className={styles.rotate} />
</div>
</div>
<div
<motion.div
ref={cardRef}
className={styles.modal__contents}
onClick={handleContentClick}
onMouseMove={handleMouseMove}
onMouseLeave={handleMouseLeave}
style={{ perspective: '1000px' }}
>
<div className={styles.modal__contents__close}></div>
<div className={styles.modal__contents}>
<motion.div
className={styles.modal__contents}
style={{
rotateX,
rotateY,
}}
initial={{ rotateX: 0, rotateY: 0 }}
animate={controls}
>
<PokemonCard
isOpen={isOpen}
pokemonCardData={card?.pokemonCardData[0]}
pokemonNickName={pokemonNickName}
/>
</div>
</div>
</motion.div>
</motion.div>
</div>
</div>
</div>
Expand Down
30 changes: 29 additions & 1 deletion src/components/mypage/MyLikedPokemon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,43 @@ import { useNavigate } from 'react-router-dom';
import useLikedStore from '@/store/useLikedStore';
import RenderPokemon from './RenderPokemon';
import { updateDocument } from '@/lib/firebaseQuery';
import { Pagination } from 'antd';
import { useState } from 'react';

const MyLikedPokemon = () => {
const { user } = useUserStore();
const { pokemonData } = useLikedStore();
const [currentPage, setCurrentPage] = useState(1);
const itemsPerPage = 12;

const navigate = useNavigate();

const indexOfLastItem = currentPage * itemsPerPage;
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
const currentItems = pokemonData.slice(indexOfFirstItem, indexOfLastItem);

const onCancelLiked = async (pokemonId: string | number) => {
if (user?.uid) {
await updateDocument(`/likes/${user.uid}`, {
pokemons: arrayRemove(pokemonId),
});

const newTotal = pokemonData.length - 1;
const maxPage = Math.ceil(newTotal / itemsPerPage);
if (currentPage > maxPage) {
setCurrentPage(maxPage > 0 ? maxPage : 1);
}
}
};

const onMoveToPokemonDetail = (pokemonId: string | number) => {
navigate(`/pokemon/${pokemonId}`);
};

const handlePageChange = (pageNumber: number) => {
setCurrentPage(pageNumber);
};

return (
<>
<div className={styles.myactive__right__container}>
Expand All @@ -39,7 +57,7 @@ const MyLikedPokemon = () => {
) : (
<>
<div className={styles.myactive__liked__box}>
{pokemonData.map((pokemon) => (
{currentItems.map((pokemon) => (
<RenderPokemon
key={pokemon.id}
pokemon={pokemon}
Expand All @@ -50,6 +68,16 @@ const MyLikedPokemon = () => {
</div>
</>
)}

<div className={styles.pagination}>
<Pagination
defaultCurrent={currentPage}
total={pokemonData.length}
pageSize={itemsPerPage}
onChange={handlePageChange}
hideOnSinglePage={true}
/>
</div>
</div>
</>
);
Expand Down
3 changes: 1 addition & 2 deletions src/components/mypage/Mypage.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@
border-radius: 10.067px;
border: 1px solid #ebebeb;
background: #fff;
overflow: auto;
}

&__liked__title {
Expand All @@ -395,7 +394,7 @@

&__liked__box {
padding: 0 29px 22px 29px;
height: auto;
height: 75%;
gap: 10px;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
Expand Down
19 changes: 18 additions & 1 deletion src/components/users/SocialLogin.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { MouseEvent } from 'react';
import { MouseEvent, useEffect } from 'react';
import { app } from '@/firebase';
import {
signInWithPopup,
GoogleAuthProvider,
GithubAuthProvider,
getAuth,
signOut,
browserSessionPersistence,
setPersistence,
} from 'firebase/auth';
import styles from './SocialLogin.module.scss';
import useUserStore from '@/store/useUsersStore';
Expand All @@ -22,6 +24,18 @@ const SocialLogin = ({ isOpen, setIsOpen }: SocialLoginProps) => {
const { user, setUser } = useUserStore();
const navigate = useNavigate();

useEffect(() => {
const setAuthPersistence = async () => {
try {
await setPersistence(auth, browserSessionPersistence);
} catch (error) {
console.error(error);
}
};

setAuthPersistence();
}, [auth]);

const onlLogin = async (e: MouseEvent<HTMLButtonElement>) => {
const target = e.target as HTMLButtonElement;
let name = target.name;
Expand All @@ -35,6 +49,9 @@ const SocialLogin = ({ isOpen, setIsOpen }: SocialLoginProps) => {

if (name === 'google') {
provider = new GoogleAuthProvider();
provider.setCustomParameters({
prompt: 'select_account',
});
} else if (name === 'github') {
provider = new GithubAuthProvider();
} else {
Expand Down

0 comments on commit 3f5a99c

Please sign in to comment.