Skip to content

Commit

Permalink
feat: Change title font, Add a toast message when connecting to chat
Browse files Browse the repository at this point in the history
  • Loading branch information
cjeongmin committed May 30, 2024
1 parent c5bab7e commit 3475e03
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/app/globals.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@import url('https://fonts.googleapis.com/css2?family=Baloo+2:[email protected]&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:[email protected]&display=swap');
@import url('https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/static/pretendard.min.css');

Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/error-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const styles = {

title: styled.p`
color: var(--Main-1, #e15637);
font-family: 'Baloo 2';
font-family: 'Pretendard';
font-size: 1.875rem;
font-style: normal;
font-weight: 700;
Expand Down
29 changes: 24 additions & 5 deletions src/components/FloatingChatting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ChattingRoom } from './chat/ChattingRoom';
import { useAuthValue, useUserData } from '@/features/auth';
import { chatOpenState, type GetChatRoomDTO } from '@/features/chat';
import { useIsMobile } from '@/shared/mobile';
import { useToast } from '@/features/toast';

const styles = {
chattingButton: styled.div`
Expand Down Expand Up @@ -74,7 +75,7 @@ const styles = {
background: var(--background, #f7f6f9);
`,
title: styled.span`
font-family: 'Baloo 2';
font-family: 'Pretendard';
font-size: 1.575rem;
font-style: normal;
font-weight: 700;
Expand Down Expand Up @@ -140,6 +141,8 @@ interface Message {
}

function FloatingChattingBox() {
const { createToast } = useToast();

const [isChatRoomOpen, setIsChatRoomOpen] = useState<boolean>(false);
const [chatRooms, setChatRooms] = useState<ChatRoom[]>([]);
const [message, setMessage] = useState<Message>();
Expand Down Expand Up @@ -170,10 +173,15 @@ function FloatingChattingBox() {
heartbeatOutgoing: 4000,
});
setStompClient(stomp);
stomp.activate();

stomp.onConnect = () => {
console.log('WebSocket 연결이 열렸습니다.');
createToast({
message: '채팅 연결에 성공했습니다.',
option: {
duration: 3000,
},
});

stomp.subscribe(`/roomList/${userId}`, frame => {
try {
const newMessage: Message = JSON.parse(frame.body);
Expand All @@ -183,8 +191,19 @@ function FloatingChattingBox() {
}
});
};

stomp.onWebSocketError = () => {
createToast({
message: '연결에 실패했습니다. 다시 시도합니다.',
option: {
duration: 3000,
},
});
};

stomp.activate();
} catch (error) {
console.error('채팅 생성 중 오류가 발생했습니다:', error);
console.error('채팅 생성 중 오류가 발생했습니다:', error);
}
};

Expand All @@ -197,7 +216,7 @@ function FloatingChattingBox() {
stompClient.deactivate();
}
};
}, [auth?.accessToken, userId]);
}, [auth?.accessToken]);

useEffect(() => {
if (data !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/NavigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const styles = {
`,
title: styled.h1`
color: var(--Main-1, #e15637);
font-family: 'Baloo 2';
font-family: 'Pretendard';
font-size: 1.875rem;
font-style: normal;
font-weight: 700;
Expand Down
23 changes: 21 additions & 2 deletions src/components/chat/ChattingRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SenderMessage } from './SenderMessage';

import { useAuthValue } from '@/features/auth';
import { useEnterChatRoom, useExitChatRoom } from '@/features/chat';
import { useToast } from '@/features/toast';

const styles = {
container: styled.div`
Expand Down Expand Up @@ -187,6 +188,8 @@ export function ChattingRoom({
lastTime: string;
onRoomClick: React.Dispatch<React.SetStateAction<boolean>>;
}) {
const { createToast } = useToast();

const [messages, setMessages] = useState<Content[]>([]);
const [inputMessage, setInputMessage] = useState('');
const [stompClient, setStompClient] = useState<Client | null>(null);
Expand Down Expand Up @@ -234,10 +237,15 @@ export function ChattingRoom({
heartbeatOutgoing: 4000,
});
setStompClient(stomp);
stomp.activate();

stomp.onConnect = () => {
console.log('WebSocket 연결이 열렸습니다.');
createToast({
message: `[${roomName}] 방 연결에 성공했습니다.`,
option: {
duration: 3000,
},
});

stomp.subscribe(`/room/${roomId}`, frame => {
try {
setTime(new Date().toISOString());
Expand All @@ -249,6 +257,17 @@ export function ChattingRoom({
}
});
};

stomp.onWebSocketError = () => {
createToast({
message: '연결에 실패했습니다. 다시 시도합니다.',
option: {
duration: 3000,
},
});
};

stomp.activate();
} catch (error) {
console.error('채팅 룸 생성 중 오류가 발생했습니다:', error);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/chat/MobileChattingBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const styles = {
background: var(--background, #f7f6f9);
`,
title: styled.span`
font-family: 'Baloo 2';
font-family: 'Pretendard';
font-size: 1.575rem;
font-style: normal;
font-weight: 700;
Expand Down

0 comments on commit 3475e03

Please sign in to comment.