mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-05 01:17:22 +00:00
Handling certain types of messages
This commit is contained in:
parent
3cc2818f40
commit
a36c36789d
2 changed files with 30 additions and 6 deletions
|
|
@ -1,6 +1,15 @@
|
||||||
import { h } from 'preact'
|
import { h } from 'preact'
|
||||||
import { useState, useEffect } from 'preact/hooks'
|
import { useState, useEffect } from 'preact/hooks'
|
||||||
|
|
||||||
|
import TextMessage from './TextMessage'
|
||||||
|
|
||||||
|
const trimImputPrompt = messages =>
|
||||||
|
messages.length < 1
|
||||||
|
? messages
|
||||||
|
: messages.slice(-1)[0].text === '>'
|
||||||
|
? messages.slice(0, messages.length - 1)
|
||||||
|
: messages
|
||||||
|
|
||||||
const parseInbox = (inbox, currentWindow) => {
|
const parseInbox = (inbox, currentWindow) => {
|
||||||
const currentInbox =
|
const currentInbox =
|
||||||
inbox.find(({ id }) =>
|
inbox.find(({ id }) =>
|
||||||
|
|
@ -16,7 +25,7 @@ const parseInbox = (inbox, currentWindow) => {
|
||||||
const { clear, text: inboxMessagesRaw } =
|
const { clear, text: inboxMessagesRaw } =
|
||||||
currentInbox
|
currentInbox
|
||||||
|
|
||||||
const incoming =
|
const incoming = trimImputPrompt(
|
||||||
inboxMessagesRaw
|
inboxMessagesRaw
|
||||||
/* Normalize. */
|
/* Normalize. */
|
||||||
.map(({ content }) =>
|
.map(({ content }) =>
|
||||||
|
|
@ -32,7 +41,7 @@ const parseInbox = (inbox, currentWindow) => {
|
||||||
return prev.style === 'emptyLine'
|
return prev.style === 'emptyLine'
|
||||||
? acc
|
? acc
|
||||||
: [...acc, x]
|
: [...acc, x]
|
||||||
}, [])
|
}, []))
|
||||||
|
|
||||||
return { clear, incoming }
|
return { clear, incoming }
|
||||||
}
|
}
|
||||||
|
|
@ -50,9 +59,8 @@ export default function ({ inbox, currentWindow }) {
|
||||||
}, [inbox])
|
}, [inbox])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<section className='textBuffer'>
|
||||||
{messages.map(({ text }) =>
|
{messages.map(TextMessage)}
|
||||||
(<div>{text}</div>))}
|
</section>
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
src/components/player/TextMessage.jsx
Normal file
16
src/components/player/TextMessage.jsx
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { h } from 'preact'
|
||||||
|
|
||||||
|
export default function ({ style, text }) {
|
||||||
|
const defaultContent = (<span>{text}</span>)
|
||||||
|
|
||||||
|
const content = ({
|
||||||
|
emptyLine: (<br />),
|
||||||
|
subheader: (<strong>{text}</strong>)
|
||||||
|
})[style] || defaultContent
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class={['message', style].join(' ')}>
|
||||||
|
{content}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue