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>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -39,6 +39,7 @@ export default function ({
|
||||||
currentWindowId,
|
currentWindowId,
|
||||||
sendMessage
|
sendMessage
|
||||||
}) {
|
}) {
|
||||||
|
const [targetWindow, setTargetWindow] = useState(null)
|
||||||
const [inputText, setInputText] = useState('')
|
const [inputText, setInputText] = useState('')
|
||||||
const [lastInput, setLastInput] = useState('')
|
const [lastInput, setLastInput] = useState('')
|
||||||
const inputEl = useRef(null)
|
const inputEl = useRef(null)
|
||||||
|
|
@ -48,13 +49,18 @@ export default function ({
|
||||||
inputEl.current && inputEl.current.focus()
|
inputEl.current && inputEl.current.focus()
|
||||||
}, [inputType])
|
}, [inputType])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setTargetWindow(
|
||||||
|
windows
|
||||||
|
.find(({id}) =>
|
||||||
|
id === currentWindowId))
|
||||||
|
}, [currentWindowId, windows])
|
||||||
|
|
||||||
const send = message => {
|
const send = message => {
|
||||||
sendMessage(
|
sendMessage(
|
||||||
message,
|
message,
|
||||||
inputType,
|
inputType,
|
||||||
windows
|
targetWindow)
|
||||||
.find(({id}) =>
|
|
||||||
id === currentWindowId))
|
|
||||||
setLastInput(message)
|
setLastInput(message)
|
||||||
setInputText('')
|
setInputText('')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ import {
|
||||||
import CheapGlkOte from 'cheap-glkote'
|
import CheapGlkOte from 'cheap-glkote'
|
||||||
|
|
||||||
import TextBuffer from './TextBuffer'
|
import TextBuffer from './TextBuffer'
|
||||||
|
import GridBuffer from './GridBuffer'
|
||||||
|
|
||||||
import InputBox from './InputBox'
|
import InputBox from './InputBox'
|
||||||
import Status from './Status'
|
import Status from './Status'
|
||||||
|
|
||||||
|
|
@ -105,7 +107,7 @@ export default function ({ vmParts: { file, engine } }) {
|
||||||
|
|
||||||
return ({
|
return ({
|
||||||
'buffer': <TextBuffer {...props} />,
|
'buffer': <TextBuffer {...props} />,
|
||||||
'grid': <div>GridView</div>
|
'grid': <GridBuffer {...props} />
|
||||||
})[currentWindow.type]
|
})[currentWindow.type]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,7 +115,7 @@ export default function ({ vmParts: { file, engine } }) {
|
||||||
? (<Status {...status} />)
|
? (<Status {...status} />)
|
||||||
: (<section className='ifplayer'>
|
: (<section className='ifplayer'>
|
||||||
{ windows
|
{ windows
|
||||||
.filter(({id}) => id === currentWindowId)
|
// .filter(({id}) => id === currentWindowId)
|
||||||
.map(textWindow(inbox)) }
|
.map(textWindow(inbox)) }
|
||||||
<InputBox {...{
|
<InputBox {...{
|
||||||
inputType,
|
inputType,
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ export default function ({ inbox, currentWindow }) {
|
||||||
return (
|
return (
|
||||||
<section
|
<section
|
||||||
ref={textBufferEl}
|
ref={textBufferEl}
|
||||||
className='textBuffer'>
|
className='buffer textBuffer'>
|
||||||
{messages.map(TextMessage)}
|
{messages.map(TextMessage)}
|
||||||
</section>
|
</section>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ export default function ({ style, text }) {
|
||||||
</span>)
|
</span>)
|
||||||
|
|
||||||
return ({
|
return ({
|
||||||
|
grid: (<div>{text} </div>),
|
||||||
input: (<span class='message input'>> {text}</span>),
|
input: (<span class='message input'>> {text}</span>),
|
||||||
subheader: (<strong>{text}</strong>),
|
subheader: (<strong>{text}</strong>),
|
||||||
emphasized: (<em>{text}</em>),
|
emphasized: (<em>{text}</em>),
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,7 @@
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ifplayer .textBuffer {
|
.ifplayer .buffer {
|
||||||
flex: 2 1 auto;
|
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
|
@ -47,16 +46,25 @@
|
||||||
scrollbar-width: thin;
|
scrollbar-width: thin;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ifplayer .textBuffer::-webkit-scrollbar {
|
.ifplayer .buffer::-webkit-scrollbar {
|
||||||
width: 8px;
|
width: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ifplayer .textBuffer::-webkit-scrollbar-thumb {
|
.ifplayer .buffer::-webkit-scrollbar-thumb {
|
||||||
background-color: var(--main-color);
|
background-color: var(--main-color);
|
||||||
border: 4px solid var(--bg-color);
|
border: 4px solid var(--bg-color);
|
||||||
border-left-width: 0px;
|
border-left-width: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ifplayer .gridBuffer {
|
||||||
|
flex-shrink: 0;
|
||||||
|
border-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ifplayer .textBuffer {
|
||||||
|
flex: 2 1 auto;
|
||||||
|
}
|
||||||
|
|
||||||
.ifplayer .textBuffer > br:first-child,
|
.ifplayer .textBuffer > br:first-child,
|
||||||
.ifplayer .textBuffer > br:last-child,
|
.ifplayer .textBuffer > br:last-child,
|
||||||
.ifplayer .textBuffer > br + br + br {
|
.ifplayer .textBuffer > br + br + br {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue