Skip to content

Commit 1068205

Browse files
committed
feat: 헤더 클릭 시 상단으로 스크롤
1 parent cbd1ab1 commit 1068205

File tree

9 files changed

+90
-43
lines changed

9 files changed

+90
-43
lines changed

src/components/Modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createPortal } from 'react-dom';
44
// import { spawn } from 'child_process';
55

66
export default function Modal() {
7-
const { modal, closeModal } = useModalStore();
7+
const { modal } = useModalStore();
88
if (!modal.isOpen) return null;
99
return createPortal(
1010
<div

src/components/MoreOptionsSelect.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ function MoreOptionsSelect({ items }: MoreOptionsSelectProps) {
2929
<div className="relative flex" ref={selectRef}>
3030
<button
3131
className="flex justify-center items-center cursor-pointer w-6 h-6"
32-
onClick={() => setIsSelectOpen((prev) => !prev)}
32+
onClick={(e) => {
33+
e.stopPropagation();
34+
setIsSelectOpen((prev) => !prev);
35+
}}
3336
>
3437
<img src={ellipsisIcon} alt="더보기" />
3538
</button>

src/layouts/Layout.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import HeaderWithBack from '@/layouts/header/HeaderWithBack';
55
import HeaderChat from '@/layouts/header/HeaderChat';
66
import { twMerge } from 'tailwind-merge';
77
import PostButton from '@/components/PostButton';
8+
import { useRef } from 'react';
89

910
function Layout() {
1011
const location = useLocation(); // 현재 URL 가져오기
@@ -47,16 +48,28 @@ function Layout() {
4748

4849
const hasPostButton = location.pathname === '/home' || location.pathname === '/mypage';
4950

51+
//헤더 클릭 시 스크롤
52+
const scrollContainerRef = useRef<HTMLDivElement>(null); // 스크롤 컨테이너 참조
53+
54+
const handleScrollToTop = () => {
55+
if (scrollContainerRef.current) {
56+
scrollContainerRef.current.scrollTo({ top: 0, behavior: 'smooth' });
57+
}
58+
};
59+
5060
return (
51-
<div className="relative max-w-[600px] min-w-[320px] w-full min-h-screen mx-auto bg-background flex flex-col">
61+
<div
62+
ref={scrollContainerRef}
63+
className="relative max-w-[600px] min-w-[320px] w-full h-screen mx-auto bg-background flex flex-col overflow-y-auto scroll"
64+
>
5265
{/* 헤더 */}
53-
{renderHeader()}
66+
<div onClick={handleScrollToTop}>{renderHeader()}</div>
5467

5568
{/* 메인 컨텐츠 영역 */}
5669
<div
5770
className={twMerge(
5871
'pt-[44px] flex-1 flex justify-center w-full px-3',
59-
// showNav && 'pb-[62px] ', // 하단 네비게이션 숨길때만 padding주기
72+
showNav && 'pb-[62px] ', // 하단 네비게이션 숨길때만 padding주기
6073
)}
6174
>
6275
<Outlet />

src/layouts/header/HeaderChat.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ function HeaderChat({ showLogo = false, showNickname = false }: HeaderChatProps)
5757

5858
{/* 나가기 버튼 */}
5959
<button
60-
onClick={() =>
60+
onClick={(e) => {
61+
e.stopPropagation();
62+
6163
openModal({
6264
title: '이 대화를 마무리할까요?',
6365
message: '채팅을 종료하면 다시 복구할 수 없습니다.',
@@ -69,8 +71,8 @@ function HeaderChat({ showLogo = false, showNickname = false }: HeaderChatProps)
6971
console.log('취소');
7072
closeModal();
7173
},
72-
})
73-
}
74+
});
75+
}}
7476
className="cursor-pointer"
7577
>
7678
<img src={exitIcon} alt="나가기" />

src/layouts/header/HeaderWithBack.tsx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { addBlockList } from '@/apis/blockList';
22
import MoreOptionsSelect from '@/components/MoreOptionsSelect';
33
import HedaerLayout from '@/layouts/header/HedaerLayout';
4+
import { useModalStore } from '@/store/modalStore';
5+
import { useSheetStore } from '@/store/sheetStore';
46
import backIcon from '@assets/icons/back-icon.svg';
57
import { useNavigate, useParams } from 'react-router';
68

@@ -13,21 +15,48 @@ interface HeaderWithBackProps {
1315
function HeaderWithBack({ showMoreOptions = false, text }: HeaderWithBackProps) {
1416
const navigate = useNavigate();
1517
const param = useParams();
18+
19+
const { openModal, closeModal } = useModalStore();
20+
const { currentRecord } = useSheetStore();
1621
// 임시함수
1722
const handleBlockUser = async () => {
18-
console.log(param.userId);
19-
if (param.userId) {
20-
const data = await addBlockList(param.userId);
21-
console.log(data);
23+
if (!param.userId || !currentRecord) {
24+
console.log('차단 실패');
25+
return;
2226
}
27+
28+
openModal({
29+
title: `${currentRecord?.nickName}님을 차단할까요?`,
30+
message: '차단된 사용자는 더이상 피드에 나타나지 않습니다',
31+
onConfirm: async () => {
32+
if (param.userId) {
33+
try {
34+
const data = await addBlockList(param.userId);
35+
closeModal();
36+
console.log(data);
37+
} catch (error) {
38+
console.log(error);
39+
}
40+
}
41+
},
42+
onCancel: () => {
43+
closeModal();
44+
},
45+
});
2346
};
2447

2548
return (
2649
<HedaerLayout>
2750
<div className="flex items-center justify-between w-full">
2851
{/* 뒤로가기 / 회원가입 */}
2952
<div className="gap-[10px] flex items-center">
30-
<button onClick={() => navigate(-1)} className="px-2 py-3 cursor-pointer">
53+
<button
54+
onClick={(e) => {
55+
e.stopPropagation();
56+
navigate(-1);
57+
}}
58+
className="px-2 py-3 cursor-pointer"
59+
>
3160
<img src={backIcon} alt="뒤로가기 아이콘" />
3261
</button>
3362
{text && <span className="h4-b text-primary-normal">{text}</span>}

src/pages/chat/Chat.tsx

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,31 @@ export default function Chat({}) {
1414
getChatList();
1515
}, []);
1616

17-
const mockData = [
18-
{
19-
chatroom_id: 3,
20-
nickname: '길동이',
21-
emotion: '행복한',
22-
spotify_id: 33,
23-
title: '라일락',
24-
artist: '아이유',
25-
album_image:
26-
'https://i.namu.wiki/i/L4gbrOjwTsNcvpsCq8b4P-3eX9Cs0lrIvwHxtFE7S5jaeMsbdelvBqCLMwe6AJJw2zBQqSI4wE0_Qn-EwaeZdnLvseFvt1w9dg-xo9KrFF_GacO_R7BnHI6XRyDDXvr-PHMmSEnqgcrzLjdbQF9obA.webp',
27-
created_at: '2025-02-19',
28-
comment: '흠흠',
29-
},
30-
{
31-
chatroom_id: 1,
32-
nickname: '철수',
33-
emotion: '우울한',
34-
spotify_id: 88,
35-
title: 'Blue Sky',
36-
artist: 'Cool Band',
37-
album_image: null,
38-
created_at: '2025-02-10',
39-
comment: '김밥',
40-
},
41-
];
17+
// const mockData = [
18+
// {
19+
// chatroom_id: 3,
20+
// nickname: '길동이',
21+
// emotion: '행복한',
22+
// spotify_id: 33,
23+
// title: '라일락',
24+
// artist: '아이유',
25+
// album_image:
26+
// 'https://i.namu.wiki/i/L4gbrOjwTsNcvpsCq8b4P-3eX9Cs0lrIvwHxtFE7S5jaeMsbdelvBqCLMwe6AJJw2zBQqSI4wE0_Qn-EwaeZdnLvseFvt1w9dg-xo9KrFF_GacO_R7BnHI6XRyDDXvr-PHMmSEnqgcrzLjdbQF9obA.webp',
27+
// created_at: '2025-02-19',
28+
// comment: '흠흠',
29+
// },
30+
// {
31+
// chatroom_id: 1,
32+
// nickname: '철수',
33+
// emotion: '우울한',
34+
// spotify_id: 88,
35+
// title: 'Blue Sky',
36+
// artist: 'Cool Band',
37+
// album_image: null,
38+
// created_at: '2025-02-10',
39+
// comment: '김밥',
40+
// },
41+
// ];
4242

4343
if (!chatList.length) {
4444
return (

src/pages/home/Home.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ function Home() {
119119
</h2>
120120
<EmotionFilter onEmotionClick={onEmotionClick} selectedEmotion={selectedEmotion} />
121121
</div>
122+
122123
{/* 메인카드 리스트 */}
123-
<div className="h-[calc(100vh-334px-env(safe-area-inset-bottom,16px))] overflow-y-auto scroll">
124+
<div className='flex-1'>
124125
{emotionRecords?.pages[0].records.length > 0 ? (
125126
<>
126127
<div className="flex flex-col items-center gap-2.5 pb-5 ">

src/pages/userprofile/UserProfile.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function UserProfile({ isMyPage }: { isMyPage: boolean }) {
141141
}, [inView]);
142142

143143
return (
144-
<div className="w-full h-[calc(100vh-112px-env(safe-area-inset-bottom,16px))] overflow-y-auto noScroll">
144+
<div className="w-full">
145145
<div className="flex flex-col items-center w-full h-full gap-4 py-4">
146146
<div className="flex flex-col items-center">
147147
<span className="h3-b">{userData?.data?.nickname}</span>

src/styles/index.css

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
@import '@styles/typography.css';
44
@import '@styles/scrollbar.css';
55

6-
7-
html {
6+
body {
87
overflow-x: hidden;
9-
overflow-y: hidden;
8+
/* overflow-y: hidden; */
109
}

0 commit comments

Comments
 (0)