mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-05 01:17:22 +00:00
Add instant game launch
This commit is contained in:
parent
90f630f277
commit
97cd8aca9e
4 changed files with 24 additions and 31 deletions
|
|
@ -1,11 +1,11 @@
|
||||||
import { h } from 'preact'
|
import { h } from 'preact'
|
||||||
|
|
||||||
export default function ({ setTargetName, setTargetUrl }) {
|
export default function ({ theme, setLocation, buildLink }) {
|
||||||
const fileInputHandler = ({ target }) => {
|
const fileInputHandler = ({ target }) => {
|
||||||
const file = target.files[0]
|
const file = target.files[0]
|
||||||
setTargetName(file.name)
|
const url = `${URL.createObjectURL(file)}#${file.name}`
|
||||||
setTargetUrl(`${URL.createObjectURL(file)}#${file.name}`)
|
|
||||||
target.value = null
|
setLocation(buildLink({ url, theme }))
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,21 @@
|
||||||
import { h } from 'preact'
|
import { h } from 'preact'
|
||||||
|
|
||||||
export default function ({ setTargetName, setTargetUrl }) {
|
export default function ({ theme, setLocation, buildLink }) {
|
||||||
const urlRE = /^(http|https):\/\/[^ "]+$/
|
const urlRE = /^(http|https):\/\/[^ "]+$/
|
||||||
|
|
||||||
const emit = url => {
|
const onKeyPress = ({ keyCode, target }) => {
|
||||||
setTargetName(url)
|
if (keyCode !== 13) return
|
||||||
setTargetUrl(url)
|
|
||||||
}
|
|
||||||
|
|
||||||
const urlInputHandler = ({ target }) => {
|
|
||||||
const url = target.value
|
const url = target.value
|
||||||
emit(urlRE.test(url)
|
|
||||||
? url
|
if (urlRE.test(url)) {
|
||||||
: null)
|
setLocation(buildLink({ url, theme }))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
type='text'
|
type='text'
|
||||||
placeholder='https://...'
|
placeholder='https://...'
|
||||||
onInput={urlInputHandler} />)
|
onKeyPress={onKeyPress} />)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ export const useHashLocation = () => {
|
||||||
return [loc, navigate]
|
return [loc, navigate]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const buildPlayLinkHref = (url, theme) =>
|
export const buildPlayLinkHref = ({ url, theme }) =>
|
||||||
`/#/play/${theme}/${encodeURIComponent(url)}`
|
`/#/play/${theme}/${encodeURIComponent(url)}`
|
||||||
|
|
||||||
export const extractView = location => {
|
export const extractView = location => {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
import { h } from 'preact'
|
import { h } from 'preact'
|
||||||
import { useState } from 'preact/hooks'
|
|
||||||
import { Link } from 'wouter-preact'
|
import { Link } from 'wouter-preact'
|
||||||
|
|
||||||
import { buildPlayLinkHref } from '~/src/utils/utils.routing'
|
import {
|
||||||
|
useHashLocation,
|
||||||
|
buildPlayLinkHref
|
||||||
|
} from '~/src/utils/utils.routing'
|
||||||
|
|
||||||
import LocalFileSelector from
|
import LocalFileSelector from
|
||||||
'~/src/components/FileSelector/LocalFileSelector'
|
'~/src/components/FileSelector/LocalFileSelector'
|
||||||
|
|
@ -13,14 +15,8 @@ import ThemeSelector from
|
||||||
|
|
||||||
import '~/src/style/views/HomeView.css'
|
import '~/src/style/views/HomeView.css'
|
||||||
|
|
||||||
const playButton = (name, url, theme) => (
|
|
||||||
<Link href={buildPlayLinkHref(url, theme)}>
|
|
||||||
Play "{name}"
|
|
||||||
</Link>)
|
|
||||||
|
|
||||||
export default function ({ themeEngine }) {
|
export default function ({ themeEngine }) {
|
||||||
const [targetName, setTargetName] = useState(null)
|
const setLocation = useHashLocation()[1]
|
||||||
const [targetUrl, setTargetUrl] = useState(null)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className='view home'>
|
<main className='view home'>
|
||||||
|
|
@ -103,8 +99,9 @@ export default function ({ themeEngine }) {
|
||||||
<label>
|
<label>
|
||||||
Local file: <br />
|
Local file: <br />
|
||||||
<LocalFileSelector {...{
|
<LocalFileSelector {...{
|
||||||
setTargetName,
|
setLocation,
|
||||||
setTargetUrl
|
buildLink: buildPlayLinkHref,
|
||||||
|
theme: themeEngine.currentTheme
|
||||||
}} />
|
}} />
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
|
|
@ -113,15 +110,13 @@ export default function ({ themeEngine }) {
|
||||||
<label>
|
<label>
|
||||||
Direct link: <br />
|
Direct link: <br />
|
||||||
<TargetURLSelector {...{
|
<TargetURLSelector {...{
|
||||||
setTargetName,
|
setLocation,
|
||||||
setTargetUrl
|
buildLink: buildPlayLinkHref,
|
||||||
|
theme: themeEngine.currentTheme
|
||||||
}} />
|
}} />
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
{ targetUrl
|
|
||||||
? playButton(targetName, targetUrl, themeEngine.currentTheme)
|
|
||||||
: null }
|
|
||||||
</main>)
|
</main>)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue