Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Style] chatting bubble 컴포넌트 제작 및 소켓 라이브러리 설치 #65

Merged
merged 4 commits into from
Nov 1, 2023
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
93 changes: 82 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@
"dependencies": {
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@stomp/stompjs": "^7.0.0",
"@tanstack/react-query": "^4.36.1",
"@types/stompjs": "^2.3.7",
"axios": "^1.5.1",
"d3": "^7.8.5",
"emotion-reset": "^3.0.1",
"framer-motion": "^10.16.4",
"http-proxy-middleware": "^2.0.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.47.0",
"react-icons": "^4.11.0",
"react-router-dom": "^6.16.0",
"react-spinners": "^0.13.8",
"react-toastify": "^9.1.3",
"zustand": "^4.4.4",
"zustand-persist": "^0.4.0",
"react-spinners": "^0.13.8"
"zustand-persist": "^0.4.0"
},
"devDependencies": {
"@rushstack/eslint-config": "^3.4.1",
Expand Down
10 changes: 10 additions & 0 deletions setupProxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createProxyMiddleware } from 'http-proxy-middleware'

module.exports = (app) => {
app.use(
createProxyMiddleware('/api/chat-stomp', {
target: process.env.VITE_BASE_URL,
ws: true,
}),
)
}
Comment on lines +1 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 라이브러리가 하는 역할을 간단하게 설명해줄 수 있나요~~??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vite.config.ts는 protocol: wss로 되어있던데 여기는 ws: true로 해야하는 건가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setupProxy.ts 파일은 제가 cra 환경에서 세팅해줬던 파일인데 vite에서는 vite.config.ts에서 사전 세팅을 해줘야 하는 것 같더라구요! 그래서 혹시 몰라 둘다 해줬는데 채팅 구현해보면서 해당 파일은 필요가 없으면 삭제하려고 했습니다!!
ws:true로 한 이유는 wss:true 로 하니까 에러가 나서 일단 에러 안 나는 방향으로 커밋한겁니다ㅎㅎ

Copy link
Contributor

@wukdddang wukdddang Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아~ 좋습니다 ㅎㅎ 수고하셨습니당 👍👍👍

42 changes: 42 additions & 0 deletions src/components/common/ChattingText/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import styled from '@emotion/styled'
import { type HTMLAttributes, type ReactNode } from 'react'

import { type TextType, theme } from '@/styles/theme'
/**
* @param as Text 컴포넌트의 종류 : 'span' | 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'div';
* @param typo Typo theme 선택
* @param color Palette theme 선택
*/

export interface TextProps extends HTMLAttributes<HTMLDivElement> {
as?: 'span' | 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'div'
typo: TextType['typo']
color?: TextType['color']
children: ReactNode
}

export type TextPropsKey = 'typo' | 'color'

export const ChattingText = ({
typo = 'Body_16',
as = 'h1',
color,
children,
...props
}: TextProps) => {
return (
<StyledText typoKey={typo} as={as} colorKey={color} {...props}>
{children}
</StyledText>
)
}

const StyledText = styled.span<{
typoKey: TextType['typo']
colorKey?: TextType['color']
}>`
white-space: pre-wrap;
color: ${({ colorKey }) => {
return colorKey && theme.palette[colorKey]
}};
`
83 changes: 83 additions & 0 deletions src/components/common/chattingBubble/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import styled from '@emotion/styled'
import { ComponentProps } from 'react'

import { ChattingText } from '@/components/common/ChattingText'
import { FlexBox } from '@/components/common/Flexbox'
import { palette } from '@/styles/palette'
import { type KeyOfPalette, type KeyOfTypo } from '@/styles/theme'

interface ChattingBubbleProps extends ComponentProps<'div'> {
isMyChat?: boolean
message: string
time: string
messageTypo?: KeyOfTypo
messageColor?: KeyOfPalette
timeTypo?: KeyOfTypo
timeColor?: KeyOfPalette
color?: KeyOfPalette
}

/**
* @param isMychat : 내 채팅인지, 상대방의 채팅인지 여부 / 기본 : false
* @param message : 메시지 내용
* @param time : 메시지 작성 시간
* @param messageType : message에 적용할 typo
* @param messageColor: message에 적용시킬 color
* @param timeType : time에 적용할 typo
* @param timeColor : time에 적용할 color
*/

const ChattingBubble = ({
isMyChat = false,
message,
time,
messageTypo = 'Body_12',
messageColor = 'BLACK',
timeTypo = 'Caption_11',
timeColor = 'GRAY500',
...props
}: ChattingBubbleProps) => {
return (
<BubbleContainer
justify={'flex-start'}
gap={10}
fullWidth={true}
isMyChat={isMyChat}
{...props}
>
<StyledText isMyChat={isMyChat}>
<MessageText typo={'Body_20'} color={messageColor} {...props}>
{message}
</MessageText>
</StyledText>
<TimeText typo={'Body_20'} color={timeColor} {...props}>
{time}
</TimeText>
</BubbleContainer>
)
}

const BubbleContainer = styled(FlexBox)<{ isMyChat: boolean }>`
justify-content: ${(props) => props.isMyChat && 'flex-end'};
`

const StyledText = styled.div<{
isMyChat: boolean
}>`
border-radius: 10px;
background-color: ${palette.WHITE};
padding: 7px 12px;
word-wrap: break-word;
order: ${(props) => (props.isMyChat ? '2' : '1')};
`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오... order를 사용해서 해결하셨네요 기발합니다 ㅎㅎ 👍👍


const TimeText = styled(ChattingText)`
order: 1;
line-height: 150%;
`

const MessageText = styled(ChattingText)`
line-height: 150%;
`

export default ChattingBubble
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// "typeRoots":["./node_modules/@types","./types"],
"module": "ESNext",
"skipLibCheck": true,
"types": ["node","vite/client"],

/* Bundler mode */
"moduleResolution": "bundler",
Expand Down
Loading