Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chat-trans
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenway
chat-trans
Commits
b85c93fd
Commit
b85c93fd
authored
Aug 10, 2023
by
chenway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
17c911b3
Pipeline
#158821
passed with stages
in 1 minute 29 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
51 deletions
+56
-51
App.js
src/App.js
+2
-2
ChatTrans.js
src/Components/ChatTrans.js
+54
-49
No files found.
src/App.js
View file @
b85c93fd
import
React
from
'react'
;
import
React
from
'react'
;
import
{
Route
,
Routes
}
from
"react-router-dom"
;
import
{
Route
,
Routes
}
from
"react-router-dom"
;
import
Chat
from
'./Components/Chat
'
;
import
Chat
Trans
from
'./Components/ChatTrans
'
;
import
Kodi
from
'./Components/Kodi'
;
import
Kodi
from
'./Components/Kodi'
;
function
App
()
{
function
App
()
{
...
@@ -8,7 +8,7 @@ function App() {
...
@@ -8,7 +8,7 @@ function App() {
<
Routes
>
<
Routes
>
<
Route
path
=
"/"
element
=
{
<
Kodi
/>
}
/>
<
Route
path
=
"/"
element
=
{
<
Kodi
/>
}
/>
<
Route
path
=
"/web"
element
=
{
<
Kodi
/>
}
/>
<
Route
path
=
"/web"
element
=
{
<
Kodi
/>
}
/>
<
Route
path
=
"/chat"
element
=
{
<
Chat
/>
}
/
>
<
Route
path
=
"/chat"
element
=
{
<
Chat
Trans
/>
}
/
>
<
/Routes
>
<
/Routes
>
);
);
}
}
...
...
src/Components/Chat.js
→
src/Components/Chat
Trans
.js
View file @
b85c93fd
// import Chat, { Bubble, useMessages } from '@chatui/core';
// import '@chatui/core/dist/index.css';
import
{
useState
}
from
"react"
;
import
{
useState
}
from
"react"
;
import
{
import
{
Button
,
Button
,
...
@@ -7,51 +9,25 @@ import {
...
@@ -7,51 +9,25 @@ import {
FormLabel
,
FormLabel
,
Navbar
,
Navbar
,
Row
,
Row
,
ListGroup
}
from
"react-bootstrap"
;
}
from
"react-bootstrap"
;
import
io
from
"socket.io-client"
;
import
io
from
"socket.io-client"
;
import
"../App.css"
;
import
"../App.css"
;
// import Chatbox from "./Chatbox";
let
messageBox
=
document
.
querySelector
(
"#message-box"
);
// const url = 'https://8788-103-84-218-44.ngrok-free.app'
const
url
=
'https://staging.strk-ai-support.ngrok.app/'
const
url
=
'https://staging.strk-ai-support.ngrok.app/'
// const url = 'http://localhost:8000'
// const url = 'http://localhost:8000'
const
socket
=
io
(
url
,
{
const
socket
=
io
(
url
,
{
extraHeaders
:
{
extraHeaders
:
{
"ngrok-skip-browser-warning"
:
"
123
"
,
"ngrok-skip-browser-warning"
:
"
"
,
},
},
});
});
// socket.emit("join", {
// username: "test",
// room: "default",
// });
socket
.
on
(
"connect"
,
(
data
)
=>
{
socket
.
on
(
"connect"
,
(
data
)
=>
{
console
.
log
(
data
);
console
.
log
(
data
);
});
});
socket
.
on
(
"send msg"
,
function
(
data
)
{
function
ChatTrans
()
{
console
.
log
(
data
);
console
.
log
(
socket
.
id
);
let
msg
=
null
;
let
msgbox
=
document
.
createElement
(
"div"
);
msgbox
.
className
=
"row"
;
msg
=
`
<div class="col">
<div class="tag z-depth-3">
<span class="teal-text"><b>
${
data
.
user
}
</b>:
${
data
.
message
}
</span>
</div>
</div>`
;
msgbox
.
innerHTML
=
msg
;
messageBox
.
appendChild
(
msgbox
);
messageBox
.
scrollTop
=
messageBox
.
scrollHeight
;
});
function
Chat
()
{
const
[
languageSupport
,
setLanguageSupport
]
=
useState
(
"English"
);
const
[
languageSupport
,
setLanguageSupport
]
=
useState
(
"English"
);
const
[
languageUser
,
setLanguageUser
]
=
useState
(
"Simple Chinese"
);
const
[
languageUser
,
setLanguageUser
]
=
useState
(
"Simple Chinese"
);
const
[
userMessage
,
setUserMessage
]
=
useState
(
""
);
const
[
userMessage
,
setUserMessage
]
=
useState
(
""
);
...
@@ -59,11 +35,20 @@ function Chat() {
...
@@ -59,11 +35,20 @@ function Chat() {
const
[
supportName
,
setSupportName
]
=
useState
(
""
);
const
[
supportName
,
setSupportName
]
=
useState
(
""
);
const
[
userName
,
setUserName
]
=
useState
(
""
);
const
[
userName
,
setUserName
]
=
useState
(
""
);
const
sendUserMessage
=
(
event
,
user
)
=>
{
const
[
userMessages
,
setUserMessages
]
=
useState
([]);
if
(
!
supportName
||
!
userName
)
{
const
[
supportMessages
,
setSupportMessages
]
=
useState
([]);
alert
(
"Please enter user name and support name"
);
return
;
socket
.
on
(
"send msg"
,
function
(
data
)
{
let
messge
=
data
.
user
+
": "
+
data
.
message
;
if
(
data
.
user
===
"user"
)
{
setSupportMessages
([...
supportMessages
,
messge
]);
}
else
{
setUserMessages
([...
userMessages
,
messge
]);
}
}
});
const
sendUserMessage
=
(
event
,
user
)
=>
{
if
(
userMessage
)
{
if
(
userMessage
)
{
socket
.
emit
(
"send msg"
,
{
socket
.
emit
(
"send msg"
,
{
user
:
"user"
,
user
:
"user"
,
...
@@ -72,17 +57,13 @@ function Chat() {
...
@@ -72,17 +57,13 @@ function Chat() {
languageUser
:
languageUser
,
languageUser
:
languageUser
,
});
});
setUserMessage
(
""
);
setUserMessage
(
""
);
setUserMessages
([...
userMessages
,
"user: "
+
userMessage
]);
}
else
{
}
else
{
alert
(
"Message cannot be empty"
);
alert
(
"Message cannot be empty"
);
}
}
};
};
const
sendSupportMessage
=
(
event
,
user
)
=>
{
const
sendSupportMessage
=
(
event
,
user
)
=>
{
if
(
!
supportName
||
!
userName
)
{
alert
(
"Please enter user name and support name"
);
return
;
}
if
(
supportMessage
)
{
if
(
supportMessage
)
{
socket
.
emit
(
"send msg"
,
{
socket
.
emit
(
"send msg"
,
{
user
:
"support"
,
user
:
"support"
,
...
@@ -91,6 +72,7 @@ function Chat() {
...
@@ -91,6 +72,7 @@ function Chat() {
languageUser
:
languageUser
,
languageUser
:
languageUser
,
});
});
setSupportMessage
(
""
);
setSupportMessage
(
""
);
setSupportMessages
([...
supportMessages
,
"support: "
+
supportMessage
]);
}
else
{
}
else
{
alert
(
"Message cannot be empty"
);
alert
(
"Message cannot be empty"
);
}
}
...
@@ -112,12 +94,20 @@ function Chat() {
...
@@ -112,12 +94,20 @@ function Chat() {
}
}
}
}
const
onUserKeyDown
=
function
(
e
)
{
if
(
e
.
keyCode
==
13
)
{
sendUserMessage
(
e
,
"user"
);
}
};
const
onSupportKeyDown
=
function
(
e
)
{
if
(
e
.
keyCode
==
13
)
{
sendSupportMessage
(
e
,
"support"
);
}
};
return
(
return
(
<
Container
>
<
Container
>
<
Navbar
bg
=
"dark"
variant
=
"dark"
>
<
Navbar
.
Brand
href
=
"#home"
>
Chat
Room
<
/Navbar.Brand
>
<
Navbar
.
Collapse
className
=
"justify-content-end"
><
/Navbar.Collapse
>
<
/Navbar
>
<
Row
>
<
Row
>
<
Col
>
<
Col
>
<
FormLabel
>
user
name
<
/FormLabel
>
<
FormLabel
>
user
name
<
/FormLabel
>
...
@@ -171,8 +161,8 @@ function Chat() {
...
@@ -171,8 +161,8 @@ function Chat() {
value
=
{
userMessage
}
value
=
{
userMessage
}
onChange
=
{(
e
)
=>
setUserMessage
(
e
.
target
.
value
)}
onChange
=
{(
e
)
=>
setUserMessage
(
e
.
target
.
value
)}
placeholder
=
"Enter message"
placeholder
=
"Enter message"
onKeyDown
=
{(
e
)
=>
onUserKeyDown
(
e
)
}
/
>
/
>
<
Button
onClick
=
{(
e
)
=>
sendUserMessage
(
e
,
"user"
)}
>
Send
<
/Button
>
<
/Col
>
<
/Col
>
<
Col
>
<
Col
>
<
FormLabel
>
support
<
/FormLabel
>
<
FormLabel
>
support
<
/FormLabel
>
...
@@ -182,22 +172,37 @@ function Chat() {
...
@@ -182,22 +172,37 @@ function Chat() {
>
>
<
option
value
=
"English"
>
English
<
/option
>
<
option
value
=
"English"
>
English
<
/option
>
<
option
value
=
"Simplified Chinese"
>
Simplified
Chinese
<
/option
>
<
option
value
=
"Simplified Chinese"
>
Simplified
Chinese
<
/option
>
{
/* add other languages here */
}
<
/Form.Control
>
<
/Form.Control
>
<
Form
.
Control
<
Form
.
Control
type
=
"text"
type
=
"text"
value
=
{
supportMessage
}
value
=
{
supportMessage
}
onChange
=
{(
e
)
=>
setSupportMessage
(
e
.
target
.
value
)}
onChange
=
{(
e
)
=>
setSupportMessage
(
e
.
target
.
value
)}
placeholder
=
"Enter message"
placeholder
=
"Enter message"
onKeyDown
=
{(
e
)
=>
onSupportKeyDown
(
e
)
}
/
>
/
>
<
Button
onClick
=
{(
e
)
=>
sendSupportMessage
(
e
,
"support"
)}
>
Send
<
/Button
>
<
/Col
>
<
/Col
>
<
Row
>
<
Col
>
<
ListGroup
variant
=
"flush"
>
{
userMessages
.
map
((
message
,
index
)
=>
(
<
ListGroup
.
Item
key
=
{
index
}
>
{
message
}
<
/ListGroup.Item
>
))}
<
/ListGroup
>
<
/Col
>
<
Col
>
<
ListGroup
variant
=
"flush"
>
{
supportMessages
.
map
((
message
,
index
)
=>
(
<
ListGroup
.
Item
key
=
{
index
}
>
{
message
}
<
/ListGroup.Item
>
))}
<
/ListGroup
>
<
/Col
>
<
/Row
>
<
/Row
>
<
/Row
>
<
/Container
>
<
/Container
>
);
);
}
}
export
default
Chat
;
export
default
Chat
Trans
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment