File tree Expand file tree Collapse file tree
src/pages/Chats/MatchingRoom Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { useSocket } from '@context/SocketProvider' ;
2+
13import { ResponseButton , ResponseContainer } from './styles' ;
24
35export interface ResponseMessageProps {
6+ matchingId : number ;
47 requestStatus : 'accepted' | 'rejected' | 'pending' ;
58}
69
7- const ResponseMessage : React . FC < ResponseMessageProps > = ( { requestStatus } ) => {
10+ const ResponseMessage : React . FC < ResponseMessageProps > = ( { matchingId, requestStatus } ) => {
11+ const socket = useSocket ( 'matching' ) ;
12+ const isPending = requestStatus === 'pending' ;
13+
14+ const handlebuttonClick = ( status : 'accept' | 'reject' ) => {
15+ if ( socket ) {
16+ socket . emit ( 'patchMatching' , { id : matchingId , requestStatus : status } ) ;
17+ }
18+ } ;
19+
820 return (
921 < ResponseContainer >
10- { ( requestStatus === 'pending' || 'accepted' ) && < ResponseButton > 거절</ ResponseButton > }
11- { ( requestStatus === 'pending' || 'rejected' ) && < ResponseButton > 수락</ ResponseButton > }
22+ { ( requestStatus === 'pending' || requestStatus === 'rejected' ) && (
23+ < ResponseButton $isPending = { isPending } onClick = { ( ) => handlebuttonClick ( 'reject' ) } >
24+ 거절
25+ </ ResponseButton >
26+ ) }
27+ { ( requestStatus === 'pending' || requestStatus === 'accepted' ) && (
28+ < ResponseButton $isPending = { isPending } onClick = { ( ) => handlebuttonClick ( 'accept' ) } >
29+ 수락
30+ </ ResponseButton >
31+ ) }
1232 </ ResponseContainer >
1333 ) ;
1434} ;
Original file line number Diff line number Diff line change @@ -6,7 +6,8 @@ export const ResponseContainer = styled.div`
66 justify-content: flex-end;
77` ;
88
9- export const ResponseButton = styled . button `
9+ export const ResponseButton = styled . button < { $isPending : boolean } > `
10+ cursor: ${ ( { $isPending } ) => `${ $isPending ? 'pointer' : 'default' } ` } ;
1011 padding: 0.4rem 0.8rem;
1112 margin: 0.5rem 0;
1213 background-color: #f2f2f2;
Original file line number Diff line number Diff line change @@ -62,7 +62,8 @@ const MatchingRoom: React.FC = () => {
6262 } ;
6363
6464 const getNewMatching = ( data : MatchingData ) => {
65- console . log ( data ) ;
65+ if ( JSON . stringify ( data ) === '{}' ) return ;
66+ setAllMatchings ( [ ...allMatchings , data ] ) ;
6667 } ;
6768
6869 if ( socket ) {
@@ -98,7 +99,7 @@ const MatchingRoom: React.FC = () => {
9899 return (
99100 < div key = { matching . id } >
100101 < MatchingMessage { ...matching } />
101- < ResponseMessage requestStatus = { matching . requestStatus } />
102+ < ResponseMessage matchingId = { matching . id } requestStatus = { matching . requestStatus } />
102103 </ div >
103104 ) ;
104105 } )
You can’t perform that action at this time.
0 commit comments