-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from KTB-Hackathon-GoLang/dev
Test: 소켓통신 테스트
- Loading branch information
Showing
6 changed files
with
154 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { instance } from "./instance"; | ||
|
||
export const chatJoin = async () => { | ||
try { | ||
const res = await instance.post(`/api/chatrooms/join`, { | ||
username: localStorage.getItem("username"), | ||
chatroomUUID: localStorage.getItem("chatroomUUID"), | ||
}); | ||
console.log(res); | ||
return res; | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { instance } from "./instance"; | ||
|
||
export const postDetailAnother = async ({ relationship, chatroomDetails }) => { | ||
try { | ||
const res = await instance.post(`/api/chatrooms/details/join`, { | ||
chatroomUUID: localStorage.getItem("chatroomUUID"), | ||
chatroomDetails, | ||
relationship, | ||
}); | ||
return res; | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import * as S from "./style"; | ||
import CHAT_LAYOUT from "@/assets/ChatLayout.png"; | ||
import REL_GOLANG from "@/assets/relationGolang.svg"; | ||
import { useState } from "react"; | ||
import { CHOOSE_TEXT } from "@/constant/chatSetting"; | ||
import { Header } from "@/components/Header/Header"; | ||
import { postDetailAnother } from "@/api/postDetailAnother"; | ||
import { chatJoin } from "@/api/chatJoin"; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
const relation = ["커플", "친구", "가족", "기타"]; | ||
const sendRelation = ["COUPLE", "FRIEND", "FAMILY", "ETC"]; | ||
|
||
export const ChatAnother = () => { | ||
const navigate = useNavigate(); | ||
const [selectedBox, setSelectedBox] = useState([false, false, false, false]); | ||
const [selectedNum, setSelectedNum] = useState(null); | ||
const [chatDetails, setChatDetails] = useState(""); // 상태 추가 | ||
|
||
const handleSelect = (index) => { | ||
const box = [false, false, false, false]; | ||
box[index] = true; | ||
setSelectedBox(box); | ||
setSelectedNum(index); | ||
}; | ||
|
||
const handleInputChange = (event) => { | ||
setChatDetails(event.target.value); // 입력된 값을 상태에 저장 | ||
}; | ||
|
||
const handleSubmit = async () => { | ||
if (selectedNum !== null && chatDetails.trim() !== "") { | ||
const res = await postDetailAnother({ | ||
chatroomDetails: chatDetails, // 입력된 값 사용 | ||
relationship: sendRelation[selectedNum], | ||
}); | ||
if (res.data.success) { | ||
console.log( | ||
`https://golang-ktb.site/chatting/peer/${localStorage.getItem( | ||
"chatroomUUID" | ||
)}` | ||
); | ||
const res = await chatJoin(); | ||
if (res.data.success) { | ||
navigate(`/chatting/peer/${localStorage.getItem("chatroomUUID")}`); | ||
} | ||
} | ||
} else { | ||
alert("모든 필드를 채워주세요."); | ||
} | ||
}; | ||
|
||
return ( | ||
<S.Layout | ||
style={{ | ||
backgroundImage: `url(${CHAT_LAYOUT})`, | ||
backgroundSize: "cover", | ||
backgroundPosition: "center", | ||
}} | ||
> | ||
<Header color="black" isBack={true}> | ||
2인 채팅 | ||
</Header> | ||
|
||
<img src={REL_GOLANG} /> | ||
{CHOOSE_TEXT.map((text, index) => ( | ||
<S.Text key={index}>{text}</S.Text> | ||
))} | ||
<S.RelationLayout> | ||
{relation.map((text, index) => ( | ||
<S.SelectBox | ||
onClick={() => handleSelect(index)} | ||
key={index} | ||
$isCheckd={selectedBox[index]} | ||
> | ||
{text} | ||
</S.SelectBox> | ||
))} | ||
</S.RelationLayout> | ||
<S.StyledInput | ||
maxLength={300} | ||
rows={7} | ||
placeholder="상대와의 갈등 상황을 입력해주세요." | ||
value={chatDetails} | ||
onChange={handleInputChange} // 입력 핸들러 추가 | ||
/> | ||
<S.CustomBtn onClick={handleSubmit}> | ||
<S.Text color="white">Start Chatting</S.Text> | ||
</S.CustomBtn> | ||
</S.Layout> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters