Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SWLab UI
Project
Project
Details
Activity
Releases
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
hyeryung
SWLab UI
Commits
b2b93a79
Commit
b2b93a79
authored
Aug 20, 2024
by
minseok.park
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update chat.js
parent
51d161f6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
6 deletions
+17
-6
08-chat.js
src/js/08-chat.js
+17
-6
No files found.
src/js/08-chat.js
View file @
b2b93a79
...
...
@@ -10,6 +10,7 @@
let
INIT
=
false
let
isComposing
=
false
let
isLoading
=
false
const
openIconPath
=
`
<path stroke-linecap="round" stroke-linejoin="round"
...
...
@@ -46,20 +47,20 @@
// Keydown event
chatTextArea
.
addEventListener
(
'keydown'
,
function
(
e
)
{
if
(
e
.
key
===
'Enter'
&&
!
e
.
shiftKey
&&
!
isComposing
)
{
if
(
e
.
key
===
'Enter'
&&
!
e
.
shiftKey
&&
!
isComposing
&&
!
isLoading
)
{
e
.
preventDefault
()
// Prevent the default action of Enter (which is to create a new line)
const
{
value
}
=
e
.
target
if
(
value
.
trim
()
!==
''
)
{
addMessageToChatBody
(
value
)
chatTextArea
.
value
=
''
handleUserMessage
(
value
)
}
}
})
sendButton
.
addEventListener
(
'click'
,
()
=>
{
const
message
=
chatTextArea
.
value
addMessageToChatBody
(
message
)
chatTextArea
.
value
=
''
if
(
!
isLoading
)
{
const
message
=
chatTextArea
.
value
handleUserMessage
(
message
)
}
})
}
}
...
...
@@ -84,6 +85,13 @@
}
})
function
handleUserMessage
(
message
)
{
if
(
message
.
trim
()
!==
''
)
{
addMessageToChatBody
(
message
)
chatTextArea
.
value
=
''
}
}
function
addMessageToChatBody
(
message
)
{
if
(
message
.
trim
()
!==
''
)
{
const
user
=
document
.
createElement
(
'pre'
)
...
...
@@ -92,6 +100,7 @@
chatBody
.
appendChild
(
user
)
chatBody
.
scrollTop
=
chatBody
.
scrollHeight
isLoading
=
true
const
chatLoader
=
document
.
createElement
(
'div'
)
chatLoader
.
className
=
'chat-loader'
const
loader
=
document
.
createElement
(
'div'
)
...
...
@@ -108,6 +117,8 @@
ai
.
textContent
=
'지금은 답해드릴 수 없어요.'
chatBody
.
appendChild
(
ai
)
chatBody
.
scrollTop
=
chatBody
.
scrollHeight
isLoading
=
false
},
3000
)
}
}
...
...
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