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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
SWD
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
Pipeline
#20402
passed with stages
in 3 minutes and 46 seconds
Changes
1
Pipelines
1
Show 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 @@
...
@@ -10,6 +10,7 @@
let
INIT
=
false
let
INIT
=
false
let
isComposing
=
false
let
isComposing
=
false
let
isLoading
=
false
const
openIconPath
=
`
const
openIconPath
=
`
<path stroke-linecap="round" stroke-linejoin="round"
<path stroke-linecap="round" stroke-linejoin="round"
...
@@ -46,20 +47,20 @@
...
@@ -46,20 +47,20 @@
// Keydown event
// Keydown event
chatTextArea
.
addEventListener
(
'keydown'
,
function
(
e
)
{
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)
e
.
preventDefault
()
// Prevent the default action of Enter (which is to create a new line)
const
{
value
}
=
e
.
target
const
{
value
}
=
e
.
target
if
(
value
.
trim
()
!==
''
)
{
if
(
value
.
trim
()
!==
''
)
{
addMessageToChatBody
(
value
)
handleUserMessage
(
value
)
chatTextArea
.
value
=
''
}
}
}
}
})
})
sendButton
.
addEventListener
(
'click'
,
()
=>
{
sendButton
.
addEventListener
(
'click'
,
()
=>
{
if
(
!
isLoading
)
{
const
message
=
chatTextArea
.
value
const
message
=
chatTextArea
.
value
addMessageToChatBody
(
message
)
handleUserMessage
(
message
)
chatTextArea
.
value
=
''
}
})
})
}
}
}
}
...
@@ -84,6 +85,13 @@
...
@@ -84,6 +85,13 @@
}
}
})
})
function
handleUserMessage
(
message
)
{
if
(
message
.
trim
()
!==
''
)
{
addMessageToChatBody
(
message
)
chatTextArea
.
value
=
''
}
}
function
addMessageToChatBody
(
message
)
{
function
addMessageToChatBody
(
message
)
{
if
(
message
.
trim
()
!==
''
)
{
if
(
message
.
trim
()
!==
''
)
{
const
user
=
document
.
createElement
(
'pre'
)
const
user
=
document
.
createElement
(
'pre'
)
...
@@ -92,6 +100,7 @@
...
@@ -92,6 +100,7 @@
chatBody
.
appendChild
(
user
)
chatBody
.
appendChild
(
user
)
chatBody
.
scrollTop
=
chatBody
.
scrollHeight
chatBody
.
scrollTop
=
chatBody
.
scrollHeight
isLoading
=
true
const
chatLoader
=
document
.
createElement
(
'div'
)
const
chatLoader
=
document
.
createElement
(
'div'
)
chatLoader
.
className
=
'chat-loader'
chatLoader
.
className
=
'chat-loader'
const
loader
=
document
.
createElement
(
'div'
)
const
loader
=
document
.
createElement
(
'div'
)
...
@@ -108,6 +117,8 @@
...
@@ -108,6 +117,8 @@
ai
.
textContent
=
'지금은 답해드릴 수 없어요.'
ai
.
textContent
=
'지금은 답해드릴 수 없어요.'
chatBody
.
appendChild
(
ai
)
chatBody
.
appendChild
(
ai
)
chatBody
.
scrollTop
=
chatBody
.
scrollHeight
chatBody
.
scrollTop
=
chatBody
.
scrollHeight
isLoading
=
false
},
3000
)
},
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