Skip to content

Commit

Permalink
feat: message receiving hint improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaokang00010 committed Jun 1, 2024
1 parent ff4dc52 commit 59cf52b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ jobs:
- name: Build Electron
run: |
npm run electron-build
npm run build
npx electron-builder
- name: upload artifacts
uses: actions/upload-artifact@v2
Expand Down
50 changes: 27 additions & 23 deletions src/components/ChatroomView.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ function ChatroomView({ id, charName }) {
// setPendingSendTimer(setTimeout(f, 10000))
// }
// if menu is open, user probably wants to send emotion stickers, so postpone sending message
setPendingSendTimer(setTimeout(f, 1000))
console.log('random timeout', Math.floor((Math.random() * 1000) % 4000 + 1000))
setPendingSendTimer(setTimeout(f, Math.floor((Math.random() * 1000) % 4000 + 1000)))
}

function updateCursurPosition() {
Expand Down Expand Up @@ -435,13 +436,30 @@ function ChatroomView({ id, charName }) {
<mui.Box ref={dummyMsgRef} style={{ height: 0, width: 0, opacity: 0 }}></mui.Box>
</mui.Box>
<mui.Grid ref={toolbarRef} container sx={{ width: 'calc(70vw - 30px)', position: 'absolute', bottom: 0, backgroundColor: scheme == 'light' ? theme.light.palette.surface.main : theme.dark.palette.surface.main }} >
<mui.Grid item xs={12} sx={{paddingY: 10}}>
{isReceivingMessage && <mui.Typography variant='body2'><b>{charName}</b> is typing...</mui.Typography>}
</mui.Grid>
<mui.Grid item xs={9}>
<mui.TextField ref={chatMessageInputRef} onBlur={() => {
updateCursurPosition()
}} value={chatMessageInput} onChange={(e) => {
setChatMessageInput(e.target.value)
updateCursurPosition()
}} sx={{ width: '100%' }} variant='standard' multiline maxRows={4} label={''} placeholder='Type a message...' ></mui.TextField>
<mui.TextField ref={chatMessageInputRef}
onFocus={() => {
discardPendingMessageTimer()
if (chatSession.current) {
keepAliveTimer.current = setInterval(() => {
Remote.chatKeepAlive(chatSession.current)
}, 5000)
}
}} onBlur={() => {
updateCursurPosition()
resetPendingMsgTimer()
if (keepAliveTimer.current) {
console.log('clearing keepalive timer')
clearInterval(keepAliveTimer.current)
}
}}
value={chatMessageInput} onChange={(e) => {
setChatMessageInput(e.target.value)
updateCursurPosition()
}} sx={{ width: '100%' }} variant='standard' multiline maxRows={4} label={''} placeholder='Type a message...' ></mui.TextField>
</mui.Grid>
<mui.Grid item xs={3}>
<mui.Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center', flexDirection: 'row', alignSelf: 'center', width: '100%' }}>
Expand All @@ -467,7 +485,7 @@ function ChatroomView({ id, charName }) {
<mui.IconButton color='primary' variant='contained' >
<icons.Attachment />
</mui.IconButton>
{!isReceivingMessage && <mui.Button variant='contained' startIcon={<icons.Send />} onClick={() => {
<mui.Button variant='contained' startIcon={<icons.Send />} onClick={() => {
uploadAllAttachment().then(() => {
buildMessageChain(chatMessageInput, chatImages.current)
}).catch(r => {
Expand All @@ -477,23 +495,9 @@ function ChatroomView({ id, charName }) {
setMessageOpen(true)
})
chatImages.current = []
}} onFocus={() => {
discardPendingMessageTimer()
if (chatSession.current) {
keepAliveTimer.current = setInterval(() => {
Remote.chatKeepAlive(chatSession.current)
}, 5000)
}
}} onBlur={() => {
resetPendingMsgTimer()
if (keepAliveTimer.current) {
console.log('clearing keepalive timer')
clearInterval(keepAliveTimer.current)
}
}}>
Send
</mui.Button>}
{isReceivingMessage && <mui.Button variant='contained' startIcon={<icons.HourglassTop />} disabled color='secondary'>Waiting...</mui.Button>}
</mui.Button>
</mui.Box>
</mui.Grid>
</mui.Grid>
Expand Down

0 comments on commit 59cf52b

Please sign in to comment.