mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-05 01:17:22 +00:00
Rearrange components
This commit is contained in:
parent
e44831db08
commit
90f630f277
13 changed files with 10 additions and 8 deletions
|
|
@ -1,51 +0,0 @@
|
|||
import { h } from 'preact'
|
||||
import { useState, useEffect } from 'preact/hooks'
|
||||
|
||||
import { engineByFilename } from './common/engines'
|
||||
|
||||
import Player from './Player'
|
||||
|
||||
const INITIAL_STATUS = {
|
||||
stage: 'loading',
|
||||
details: 'Loading...'
|
||||
}
|
||||
|
||||
const prepareVM = ({ url, setStatus, setParts }) => {
|
||||
const st = (stage, details) => args => {
|
||||
setStatus({ stage, details })
|
||||
return args
|
||||
}
|
||||
|
||||
return Promise.resolve()
|
||||
.then(st('loading', 'Downloading file...'))
|
||||
.then(_ => fetch(url))
|
||||
.then(st('loading', 'Processing file...'))
|
||||
.then(response => response.arrayBuffer())
|
||||
.then(arrayBuffer => new Uint8Array(arrayBuffer))
|
||||
.then(st('loading', 'Downloading engine...'))
|
||||
.then(file => setParts({
|
||||
file,
|
||||
engine: engineByFilename(url)
|
||||
}))
|
||||
.then(st('loading', 'Running...'))
|
||||
.catch(e => {
|
||||
console.error(e)
|
||||
setStatus({ stage: 'fail', details: e.message })
|
||||
})
|
||||
}
|
||||
|
||||
export default function ({ url }) {
|
||||
const [status, setStatus] = useState(INITIAL_STATUS)
|
||||
const [vmParts, setParts] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
setStatus(INITIAL_STATUS)
|
||||
setParts(null)
|
||||
|
||||
prepareVM({ url, setStatus, setParts })
|
||||
}, [url])
|
||||
|
||||
return vmParts
|
||||
? (<Player vmParts={vmParts} />)
|
||||
: (<div>{status.details}</div>)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue