Skip to content
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
20 changes: 5 additions & 15 deletions src/components/Carousel/Carousel.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import { useState, useEffect } from 'react';
import styles from './Carousel.module.scss';
import RecipientCard from '../RecipientCard/RecipientCard';
import useWindowWidth from '../../hooks/useWindowWidth';

export default function Carousel({ recipients }) {
const [index, setIndex] = useState(0);
const [offsetX, setOffsetX] = useState({}); // xμ’Œν‘œ
const [startX, setstartX] = useState(0); // 클릭 μ‹œμž‘ μ’Œν‘œ - ν„°μΉ˜ 슀크둀
const [offsetX, setOffsetX] = useState({}); // μΊλŸ¬μ…€ xμ’Œν‘œ
const [startX, setstartX] = useState(0); // ν„°μΉ˜ 슀크둀 μ‹œμž‘ xμ’Œν‘œ
const [isBouncing, setBouncing] = useState(false); // μΊλŸ¬μ…€ 끝이면 bouncing λͺ¨μ…˜
const [windowWidth, setWindowWidth] = useState(window.innerWidth);
const isDesktop = windowWidth > 1200;

useEffect(() => {
function handleResize() {
setWindowWidth(window.innerWidth);
}
window.addEventListener('resize', handleResize);
return () => {
window.removeEventListener('resize', handleResize);
};
}, []);
const isDesktop = useWindowWidth() > 1200;

// μΊλŸ¬μ…€ λ²„νŠΌ μž‘λ™κ³Όμ •: button onclick --> settingIndex(), setIndex --> useEffect( setOffsetX(),[index] ): xμ’Œν‘œ μƒνƒœ μ—…λ°μ΄νŠΈ: μΊλŸ¬μ…€ 이동
useEffect(() => {
Expand Down Expand Up @@ -48,7 +38,7 @@ export default function Carousel({ recipients }) {

if (!isNext) {
if (index === 0) {
setBouncing(true); //μΊλŸ¬μ…€ 끝 -> setBounce(띠용)
setBouncing(true);
return;
} else if (index > 0) {
settingIndex('back');
Expand Down
30 changes: 20 additions & 10 deletions src/components/RecipientCard/RecipientCard.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import styles from './RecipientCard.module.scss';
import RecentMessages from '../RecentMessages/RecentMessages';
import TopReactions from '../TopReactions/TopReactions';
import { useNavigate } from 'react-router-dom';

//μΊλŸ¬μ…€ λ‚΄λΆ€ μš”μ†Œ - μΉ΄λ“œ μ»΄ν¬λ„ŒνŠΈ
export default function RecipientCard({ Recipient }) {
const {
id,
Expand All @@ -15,6 +15,13 @@ export default function RecipientCard({ Recipient }) {
backgroundImageURL,
} = Recipient;
const navigate = useNavigate();
const [isDragging, setIsDragging] = useState(false);

function handleCardClick() {
if (!isDragging) {
navigate(`/post/${id}`);
}
}

return (
<div
Expand All @@ -26,24 +33,27 @@ export default function RecipientCard({ Recipient }) {
}
: {}
}
onClick={() => navigate(`/post/${id}`)}
onClick={handleCardClick}
onMouseDown={() => setIsDragging(false)}
onTouchStart={() => setIsDragging(false)}
onMouseMove={() => setIsDragging(true)}
onTouchMove={() => setIsDragging(true)}
>
{backgroundColor === 'blue' && <div className={styles.triangle} />}
<h3
className={`${styles['card__h3']} ${backgroundImageURL ? styles.white : ''}`}
>{`To. ${name}`}</h3>
<RecentMessages
messages={recentMessages}
count={messageCount}
></RecentMessages>
>
{`To. ${name}`}
</h3>
<RecentMessages messages={recentMessages} count={messageCount} />
<div
className={`${styles['card__writer-count']} ${backgroundImageURL && styles.white}`}
>
<span className={styles['card__count']}>{messageCount}</span>
<span>λͺ…이 μž‘μ„±ν–ˆμ–΄μš”!</span>
</div>
<div className={styles['card__centerline']}></div>
<TopReactions reactions={topReactions}></TopReactions>
<div className={styles['card__centerline']} />
<TopReactions reactions={topReactions} />
</div>
);
}
14 changes: 14 additions & 0 deletions src/hooks/useWindowWidth.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useState, useEffect } from 'react';

export default function useWindowWidth() {
const [windowWidth, setWindowWidth] = useState(window.innerWidth);

useEffect(() => {
function handleResize() {
setWindowWidth(window.innerWidth);
}
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);
return windowWidth;
}