mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-04 17:07:22 +00:00
Unified file link format
This commit is contained in:
parent
1e1e611104
commit
19e051045d
5 changed files with 96 additions and 13 deletions
15
src/components/FileSelector.js
Normal file
15
src/components/FileSelector.js
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { h } from 'preact'
|
||||||
|
|
||||||
|
export default function ({ emitName, emitURL }) {
|
||||||
|
const fileInputHandler = ({ target }) => {
|
||||||
|
const file = target.files[0]
|
||||||
|
emitName(file.name)
|
||||||
|
emitURL(URL.createObjectURL(file))
|
||||||
|
target.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<input
|
||||||
|
type='file'
|
||||||
|
onChange={fileInputHandler} />)
|
||||||
|
}
|
||||||
23
src/components/URLSelector.js
Normal file
23
src/components/URLSelector.js
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { h } from 'preact'
|
||||||
|
|
||||||
|
export default function ({ emitName, emitURL }) {
|
||||||
|
const reURL = /^(http|https):\/\/[^ "]+$/
|
||||||
|
|
||||||
|
const emit = url => {
|
||||||
|
emitName(url)
|
||||||
|
emitURL(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
const urlInputHandler = ({ target }) => {
|
||||||
|
const url = target.value
|
||||||
|
emit(reURL.test(url)
|
||||||
|
? url
|
||||||
|
: null)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<input
|
||||||
|
type='text'
|
||||||
|
placeholder='https://...'
|
||||||
|
onInput={urlInputHandler} />)
|
||||||
|
}
|
||||||
26
src/index.js
26
src/index.js
|
|
@ -1,10 +1,11 @@
|
||||||
import { h, render } from 'preact'
|
import { h, render } from 'preact'
|
||||||
import {
|
import { Link, Route, Router, Switch } from 'wouter-preact'
|
||||||
Redirect, Switch, Route, Link, Router
|
|
||||||
} from 'wouter-preact'
|
|
||||||
|
|
||||||
import { useHashLocation } from '~/src/utils/utils.routing'
|
import { useHashLocation } from '~/src/utils/utils.routing'
|
||||||
|
|
||||||
|
import Index from '~/src/views/Index'
|
||||||
|
import Player from '~/src/views/Player'
|
||||||
|
|
||||||
function App () {
|
function App () {
|
||||||
return (
|
return (
|
||||||
<Router hook={useHashLocation}>
|
<Router hook={useHashLocation}>
|
||||||
|
|
@ -12,22 +13,21 @@ function App () {
|
||||||
<nav>
|
<nav>
|
||||||
<Link href='/'>Root</Link>
|
<Link href='/'>Root</Link>
|
||||||
<Link href='/#/about'>About</Link>
|
<Link href='/#/about'>About</Link>
|
||||||
<Link href='/#/info'>Redirect</Link>
|
|
||||||
<Link href='/#/404'>404</Link>
|
<Link href='/#/404'>404</Link>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path='/'>
|
<Route
|
||||||
Root
|
path='/'
|
||||||
|
component={Index} />
|
||||||
|
<Route
|
||||||
|
path='/play/:theme/:encodedUrl'
|
||||||
|
component={Player} />
|
||||||
|
<Route path='/top100'>
|
||||||
|
top100
|
||||||
</Route>
|
</Route>
|
||||||
<Route path='/about'>
|
<Route>
|
||||||
About
|
|
||||||
</Route>
|
|
||||||
<Route path='/info'>
|
|
||||||
<Redirect to='/about' />
|
|
||||||
</Route>
|
|
||||||
<Route path='/:anything*'>
|
|
||||||
404
|
404
|
||||||
</Route>
|
</Route>
|
||||||
</Switch>
|
</Switch>
|
||||||
|
|
|
||||||
34
src/views/Index.js
Normal file
34
src/views/Index.js
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
import { h } from 'preact'
|
||||||
|
import { useState } from 'preact/hooks'
|
||||||
|
|
||||||
|
import { Link } from 'wouter-preact'
|
||||||
|
|
||||||
|
import FileSelector from '~/src/components/FileSelector'
|
||||||
|
import URLSelector from '~/src/components/URLSelector'
|
||||||
|
|
||||||
|
export default function () {
|
||||||
|
const [targetName, setTargetName] = useState(null)
|
||||||
|
const [targetURL, setTargetURL] = useState(null)
|
||||||
|
|
||||||
|
const playButton = (
|
||||||
|
<Link href={`/#/play/default/${encodeURIComponent(targetURL)}`}>
|
||||||
|
Play "{targetName}"
|
||||||
|
</Link>)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<URLSelector
|
||||||
|
emitName={setTargetName}
|
||||||
|
emitURL={setTargetURL} />
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<FileSelector
|
||||||
|
emitName={setTargetName}
|
||||||
|
emitURL={setTargetURL} />
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
{ targetURL ? playButton : null }
|
||||||
|
</main>)
|
||||||
|
}
|
||||||
11
src/views/Player.jsx
Normal file
11
src/views/Player.jsx
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { h } from 'preact'
|
||||||
|
|
||||||
|
export default function ({params: {theme, encodedUrl}}) {
|
||||||
|
const url = decodeURIComponent(encodedUrl)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{theme} <br/>
|
||||||
|
{url}
|
||||||
|
</div>)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue