Skip to content

Commit

Permalink
refactor: 리뷰 수정사항 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
brgndyy committed Jul 19, 2024
1 parent 8bf81ef commit 20baeee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/carousel/Carousel.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ export const SlideWrapper = styled.div`

interface SlideTrackProps {
currentIndex: number;
isAnimating: boolean;
isSliding: boolean;
}

export const SlideTrack = styled.ul<SlideTrackProps>`
display: flex;
flex-direction: row;
position: relative;
transform-style: preserve-3d;
transition: ${({ isAnimating }) => (isAnimating ? 'transform 400ms ease-in-out' : 'none')};
transition: ${({ isSliding }) => (isSliding ? 'transform 400ms ease-in-out' : 'none')};
transform: ${({ currentIndex }) => `translateX(-${currentIndex * 100}%)`};
padding: 0;
margin: 0;
Expand Down
12 changes: 3 additions & 9 deletions frontend/src/components/carousel/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@ import type { PropsWithChildren } from 'react';
import * as S from './Carousel.styled';

export default function Carousel({ children }: PropsWithChildren) {
const {
carouselItems,
trackRef,
currentIndex,
isAnimating,
handleNextSlide,
handlePreviousSlide,
} = useCarousel({ children });
const { carouselItems, trackRef, currentIndex, isSliding, handleNextSlide, handlePreviousSlide } =
useCarousel({ children });

return (
<S.Container>
<S.SlideWrapper>
<S.SlideTrack ref={trackRef} currentIndex={currentIndex} isAnimating={isAnimating}>
<S.SlideTrack ref={trackRef} currentIndex={currentIndex} isSliding={isSliding}>
{carouselItems.map((item, index) => (
<S.Slide key={`original-${index}`}>{item}</S.Slide>
))}
Expand Down
16 changes: 8 additions & 8 deletions frontend/src/hooks/useCarousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import React, { useState, useRef, useEffect } from 'react';
const useCarousel = ({ children }: PropsWithChildren) => {
const carouselItems = React.Children.toArray(children);
const carouselItemLength = carouselItems.length;
const [currentIndex, setCurrentIndex] = useState(1);
const [isAnimating, setIsAnimating] = useState(false);
const [currentIndex, setCurrentIndex] = useState(0);
const [isSliding, setIsSliding] = useState(false);
const trackRef = useRef<HTMLUListElement>(null);

const handleTransitionEnd = () => {
Expand All @@ -14,7 +14,7 @@ const useCarousel = ({ children }: PropsWithChildren) => {
} else if (currentIndex === 0) {
setCurrentIndex(carouselItemLength);
}
setIsAnimating(false);
setIsSliding(false);
};

useEffect(() => {
Expand All @@ -28,15 +28,15 @@ const useCarousel = ({ children }: PropsWithChildren) => {
}, [currentIndex, carouselItemLength]);

Check warning on line 28 in frontend/src/hooks/useCarousel.ts

View workflow job for this annotation

GitHub Actions / build-and-test

React Hook useEffect has a missing dependency: 'handleTransitionEnd'. Either include it or remove the dependency array

const handleNextSlide = () => {
if (!isAnimating) {
setIsAnimating(true);
if (!isSliding) {
setIsSliding(true);
setCurrentIndex((prevIndex) => prevIndex + 1);
}
};

const handlePreviousSlide = () => {
if (!isAnimating) {
setIsAnimating(true);
if (!isSliding) {
setIsSliding(true);
setCurrentIndex((prevIndex) => prevIndex - 1);
}
};
Expand All @@ -45,7 +45,7 @@ const useCarousel = ({ children }: PropsWithChildren) => {
carouselItems,
trackRef,
currentIndex,
isAnimating,
isSliding,
handleNextSlide,
handlePreviousSlide,
};
Expand Down

0 comments on commit 20baeee

Please sign in to comment.