Skip to content

Commit 2052704

Browse files
committed
[feat]알림 SSE기능
1 parent 8de2150 commit 2052704

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

src/domains/main/api/useSSENotification.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export function useSSENotification(isLoggedIn: boolean) {
1010
// 로그인 안 했으면 연결 안 함
1111
if (!isLoggedIn) {
1212
if (eventSourceRef.current) {
13-
console.log('🔌 로그아웃으로 인한 SSE 연결 종료');
1413
eventSourceRef.current.close();
1514
eventSourceRef.current = null;
1615
isConnectingRef.current = false;
@@ -20,12 +19,10 @@ export function useSSENotification(isLoggedIn: boolean) {
2019

2120
// 이미 연결 중이거나 연결되어 있으면 중복 방지
2221
if (isConnectingRef.current || eventSourceRef.current) {
23-
console.log('⚠️ 이미 SSE 연결 중 또는 연결됨');
2422
return;
2523
}
2624

2725
isConnectingRef.current = true;
28-
console.log('🔌 SSE 연결 시작...');
2926

3027
const eventSource = new EventSource(`${getApi}/me/subscribe`, {
3128
withCredentials: true,
@@ -34,30 +31,23 @@ export function useSSENotification(isLoggedIn: boolean) {
3431
eventSourceRef.current = eventSource;
3532

3633
eventSource.onopen = () => {
37-
console.log('✅ SSE 연결 성공!');
3834
isConnectingRef.current = false;
3935
};
4036

41-
eventSource.onmessage = (event) => {
42-
console.log('📢 새 알림 도착:', event.data);
37+
eventSource.onmessage = () => {
4338
setHasNewNotification(true);
4439
};
4540

46-
eventSource.onerror = (error) => {
47-
console.error('❌ SSE 에러:', error);
48-
console.log('연결 상태:', eventSource.readyState);
49-
41+
eventSource.onerror = () => {
5042
isConnectingRef.current = false;
5143

5244
if (eventSource.readyState === EventSource.CLOSED) {
53-
console.log('🔄 SSE 연결이 닫혔습니다');
5445
eventSourceRef.current = null;
5546
}
5647
};
5748

5849
// cleanup 함수
5950
return () => {
60-
console.log('🔌 컴포넌트 언마운트로 인한 SSE 연결 종료');
6151
if (eventSourceRef.current) {
6252
eventSourceRef.current.close();
6353
eventSourceRef.current = null;

src/domains/main/components/mainSlide/components/mobile/MobileAbv.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ function MobileAbv() {
5353
<h2 className="text-xl sm:text-2xl font-black text-white">내 알콜도수 UP</h2>
5454
<button
5555
type="button"
56-
className={clsx(`block z-1 duration-300 sm:hidden`, isClick ? 'rotate-[135deg]' : 'rotate-0')}
56+
className={clsx(
57+
`block z-1 duration-300 sm:hidden`,
58+
isClick ? 'rotate-[135deg]' : 'rotate-0'
59+
)}
5760
onClick={() => setIsClick(!isClick)}
5861
>
5962
<Add />

src/shared/components/header/HeaderBtn.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ import { useRouter } from 'next/navigation';
66
import tw from '@/shared/utills/tw';
77
import { useAuthStore } from '@/domains/shared/store/auth';
88
import { setPreLoginPath } from '@/domains/shared/auth/utils/setPreLoginPath';
9-
import { useState } from 'react';
9+
import { useState } from 'react';
1010
import LogoutConfirm from '@/domains/login/components/LogoutConfirm';
1111
import { useSSENotification } from '@/domains/main/api/useSSENotification';
1212

13-
1413
function HeaderBtn({ pathname }: { pathname: string }) {
1514
const { isLoggedIn } = useAuthStore();
1615
const router = useRouter();
1716
const [logoutModalOpen, setLogoutModalOpen] = useState(false);
18-
19-
20-
const {hasNewNotification,clearNotification} = useSSENotification(isLoggedIn)
17+
18+
const { hasNewNotification, clearNotification } = useSSENotification(isLoggedIn);
2119

2220
const navButtons = [
2321
{
@@ -26,7 +24,7 @@ const {hasNewNotification,clearNotification} = useSSENotification(isLoggedIn)
2624
className: pathname === '/mypage/my-alarm' ? 'text-tertiary' : 'text-current',
2725
hiddenMobile: true,
2826
onClick: () => {
29-
clearNotification()
27+
clearNotification();
3028
router.push('/mypage/my-alarm');
3129
},
3230
showBadge: true,

0 commit comments

Comments
 (0)