mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-05 01:17:22 +00:00
Add GridBuffer placeholder
This commit is contained in:
parent
393b1f1dd6
commit
4747a3396c
2 changed files with 45 additions and 22 deletions
|
|
@ -33,7 +33,12 @@ const keyNames = {
|
||||||
}
|
}
|
||||||
/* eslint-enable */
|
/* eslint-enable */
|
||||||
|
|
||||||
export default function ({ currentWindow, inputType, sendMessage }) {
|
export default function ({
|
||||||
|
inputType,
|
||||||
|
windows,
|
||||||
|
currentWindowId,
|
||||||
|
sendMessage
|
||||||
|
}) {
|
||||||
const [inputText, setInputText] = useState('')
|
const [inputText, setInputText] = useState('')
|
||||||
const [lastInput, setLastInput] = useState('')
|
const [lastInput, setLastInput] = useState('')
|
||||||
const inputEl = useRef(null)
|
const inputEl = useRef(null)
|
||||||
|
|
@ -43,9 +48,14 @@ export default function ({ currentWindow, inputType, sendMessage }) {
|
||||||
inputEl.current && inputEl.current.focus()
|
inputEl.current && inputEl.current.focus()
|
||||||
}, [inputType])
|
}, [inputType])
|
||||||
|
|
||||||
const send = x => {
|
const send = message => {
|
||||||
sendMessage(x, currentWindow)
|
sendMessage(
|
||||||
setLastInput(x)
|
message,
|
||||||
|
inputType,
|
||||||
|
windows
|
||||||
|
.find(({id}) =>
|
||||||
|
id === currentWindowId))
|
||||||
|
setLastInput(message)
|
||||||
setInputText('')
|
setInputText('')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,18 +30,20 @@ const runMachine = ({ engine: Engine, file, handlers }) => {
|
||||||
|
|
||||||
const Handlers = ({
|
const Handlers = ({
|
||||||
setStatus,
|
setStatus,
|
||||||
setCurrentWindow,
|
setWindows,
|
||||||
|
setCurrentWindowId,
|
||||||
setInputType,
|
setInputType,
|
||||||
setInbox
|
setInbox
|
||||||
}) => ({
|
}) => ({
|
||||||
onInit: _ => setStatus({ stage: 'ready' }),
|
onInit: _ => setStatus({ stage: 'ready' }),
|
||||||
/* */
|
/* */
|
||||||
onUpdateWindows: windows => {
|
onUpdateWindows: windows => {
|
||||||
setCurrentWindow(windows
|
setWindows(windows)
|
||||||
.filter(x => x.type === 'buffer')
|
},
|
||||||
.slice(-1)[0])
|
onUpdateInputs: ([{type, id}]) => {
|
||||||
|
setCurrentWindowId(id)
|
||||||
|
setInputType(type)
|
||||||
},
|
},
|
||||||
onUpdateInputs: setInputType,
|
|
||||||
onUpdateContent: setInbox,
|
onUpdateContent: setInbox,
|
||||||
onDisable: _ => setInputType(null),
|
onDisable: _ => setInputType(null),
|
||||||
/* */
|
/* */
|
||||||
|
|
@ -65,7 +67,8 @@ const Handlers = ({
|
||||||
export default function ({ vmParts: { file, engine } }) {
|
export default function ({ vmParts: { file, engine } }) {
|
||||||
const [status, setStatus] = useState(INITIAL_STATUS)
|
const [status, setStatus] = useState(INITIAL_STATUS)
|
||||||
|
|
||||||
const [currentWindow, setCurrentWindow] = useState(null)
|
const [windows, setWindows] = useState([])
|
||||||
|
const [currentWindowId, setCurrentWindowId] = useState(null)
|
||||||
const [inputType, setInputType] = useState(null)
|
const [inputType, setInputType] = useState(null)
|
||||||
const [inbox, setInbox] = useState([])
|
const [inbox, setInbox] = useState([])
|
||||||
|
|
||||||
|
|
@ -78,7 +81,8 @@ export default function ({ vmParts: { file, engine } }) {
|
||||||
file,
|
file,
|
||||||
handlers: Handlers({
|
handlers: Handlers({
|
||||||
setStatus,
|
setStatus,
|
||||||
setCurrentWindow,
|
setWindows,
|
||||||
|
setCurrentWindowId,
|
||||||
setInputType,
|
setInputType,
|
||||||
setInbox
|
setInbox
|
||||||
})
|
})
|
||||||
|
|
@ -93,19 +97,28 @@ export default function ({ vmParts: { file, engine } }) {
|
||||||
: null)
|
: null)
|
||||||
}, [vm])
|
}, [vm])
|
||||||
|
|
||||||
return status.stage !== 'ready'
|
const textWindow = inbox => currentWindow => {
|
||||||
? (<Status {...status} />)
|
const props = {
|
||||||
: (
|
|
||||||
<section className='ifplayer'>
|
|
||||||
<TextBuffer {...{
|
|
||||||
inbox,
|
inbox,
|
||||||
currentWindow
|
currentWindow
|
||||||
}} />
|
}
|
||||||
<InputBox {...{
|
|
||||||
currentWindow,
|
return ({
|
||||||
inputType,
|
'buffer': <TextBuffer {...props} />,
|
||||||
sendMessage
|
'grid': <div>GridView</div>
|
||||||
}} />
|
})[currentWindow.type]
|
||||||
</section>
|
}
|
||||||
)
|
|
||||||
|
return status.stage !== 'ready'
|
||||||
|
? (<Status {...status} />)
|
||||||
|
: (<section className='ifplayer'>
|
||||||
|
{ windows
|
||||||
|
.filter(({id}) => id === currentWindowId)
|
||||||
|
.map(textWindow(inbox)) }
|
||||||
|
<InputBox {...{
|
||||||
|
inputType,
|
||||||
|
windows,
|
||||||
|
currentWindowId,
|
||||||
|
sendMessage }} />
|
||||||
|
</section>)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue