mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-04 17:07:22 +00:00
Extract URL loader component
This commit is contained in:
parent
d7ba6d8c60
commit
eb8025791b
3 changed files with 37 additions and 21 deletions
|
|
@ -4,8 +4,8 @@
|
||||||
import { engineByFilename } from '~/src/common/engines'
|
import { engineByFilename } from '~/src/common/engines'
|
||||||
|
|
||||||
export const prepareVM = ({ url, setStatus, setVM }) => _ => {
|
export const prepareVM = ({ url, setStatus, setVM }) => _ => {
|
||||||
const st = (step, details) => args => {
|
const st = (stage, details) => args => {
|
||||||
setStatus({ step, details })
|
setStatus({ stage, details })
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -23,7 +23,7 @@ export const prepareVM = ({ url, setStatus, setVM }) => _ => {
|
||||||
.then(st('loading', 'Running...'))
|
.then(st('loading', 'Running...'))
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
setStatus({ level: 'fail', details: e.message })
|
setStatus({ stage: 'fail', details: e.message })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
32
src/components/player/UrlPlayer.js
Normal file
32
src/components/player/UrlPlayer.js
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
import { h } from 'preact'
|
||||||
|
import { useState, useEffect } from 'preact/hooks'
|
||||||
|
|
||||||
|
import { prepareVM } from '~/src/common/if'
|
||||||
|
|
||||||
|
const INITIAL_STATUS = {
|
||||||
|
stage: 'loading',
|
||||||
|
details: 'Loading...'
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ({url}) {
|
||||||
|
console.log(123, url)
|
||||||
|
const [status, setStatus] = useState(INITIAL_STATUS)
|
||||||
|
|
||||||
|
const [vm, setVM] = useState(null)
|
||||||
|
|
||||||
|
useEffect(prepareVM({
|
||||||
|
url,
|
||||||
|
setStatus,
|
||||||
|
setVM
|
||||||
|
}), [url])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (vm) console.log('success', vm)
|
||||||
|
}, [vm])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main>
|
||||||
|
{url}
|
||||||
|
{status.details}
|
||||||
|
</main>)
|
||||||
|
}
|
||||||
|
|
@ -1,31 +1,15 @@
|
||||||
import { h } from 'preact'
|
import { h } from 'preact'
|
||||||
|
|
||||||
import { useState, useEffect } from 'preact/hooks'
|
import { useState, useEffect } from 'preact/hooks'
|
||||||
import { prepareVM } from '~/src/common/if'
|
|
||||||
|
|
||||||
const INITIAL_STATUS = {
|
import UrlPlayer from '~/src/components/player/UrlPlayer'
|
||||||
level: 'loading',
|
|
||||||
details: 'Loading...'
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function ({setTheme, theme, encodedUrl}) {
|
export default function ({setTheme, theme, encodedUrl}) {
|
||||||
const [url] = useState(decodeURIComponent(encodedUrl))
|
const [url] = useState(decodeURIComponent(encodedUrl))
|
||||||
const [status, setStatus] = useState(INITIAL_STATUS)
|
|
||||||
|
|
||||||
const [vm, setVM] = useState(null)
|
|
||||||
|
|
||||||
useEffect(() => setTheme(theme), [theme])
|
useEffect(() => setTheme(theme), [theme])
|
||||||
useEffect(prepareVM({
|
|
||||||
url,
|
|
||||||
setStatus,
|
|
||||||
setVM
|
|
||||||
}), [url])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (vm) console.log('success', vm)
|
|
||||||
}, [vm])
|
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
{status.details}
|
<UrlPlayer url={url} />
|
||||||
</main>)
|
</main>)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue