mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-05 01:17:22 +00:00
Add GridBuffer component
This commit is contained in:
parent
4747a3396c
commit
752cb60b56
6 changed files with 75 additions and 10 deletions
48
src/components/Player/GridBuffer.jsx
Normal file
48
src/components/Player/GridBuffer.jsx
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import { h } from 'preact'
|
||||
import { useEffect, useRef, useState } from 'preact/hooks'
|
||||
|
||||
import TextMessage from './TextMessage'
|
||||
|
||||
export default function ({ inbox, currentWindow }) {
|
||||
const [prevMessages, setPrevMessages] = useState([])
|
||||
const [messages, setMessages] = useState([])
|
||||
|
||||
useEffect(() => {
|
||||
const currentInbox =
|
||||
inbox.find(({ id }) =>
|
||||
id === currentWindow.id).lines
|
||||
|
||||
const newOrPrev = (cur, prev) => i => {
|
||||
const byId = (list, i) =>
|
||||
list.find(({line}) => line === i)
|
||||
|
||||
return byId(cur, i) || byId(prev, i)
|
||||
}
|
||||
|
||||
const rawMessages =
|
||||
Array(currentWindow.gridheight)
|
||||
.fill(null)
|
||||
.map((_, i) => i)
|
||||
.map(newOrPrev(currentInbox, prevMessages))
|
||||
|
||||
setPrevMessages(rawMessages)
|
||||
setMessages(rawMessages
|
||||
.map(x => x.content)
|
||||
.map(([x]) => x)
|
||||
.map(({text}) => text)
|
||||
.map(text => text.trim())
|
||||
.map(text =>
|
||||
text.replace(' ', ' / '))
|
||||
.map(text => ({
|
||||
style: 'grid',
|
||||
text}))
|
||||
)
|
||||
}, [inbox, currentWindow])
|
||||
|
||||
return (
|
||||
<section
|
||||
className='buffer gridBuffer'>
|
||||
{messages.map(TextMessage)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue