mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-05 01:17:22 +00:00
Themes: init
This commit is contained in:
parent
251fa153f0
commit
cbc6207ad9
9 changed files with 108 additions and 46 deletions
|
|
@ -1,10 +1,10 @@
|
||||||
import { h } from 'preact'
|
import { h } from 'preact'
|
||||||
|
|
||||||
export default function ({ emitName, emitURL }) {
|
export default function ({ setTargetName, setTargetUrl }) {
|
||||||
const fileInputHandler = ({ target }) => {
|
const fileInputHandler = ({ target }) => {
|
||||||
const file = target.files[0]
|
const file = target.files[0]
|
||||||
emitName(file.name)
|
setTargetName(file.name)
|
||||||
emitURL(`${URL.createObjectURL(file)}#${file.name}`)
|
setTargetUrl(`${URL.createObjectURL(file)}#${file.name}`)
|
||||||
target.value = null
|
target.value = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
15
src/components/ThemeSelector.js
Normal file
15
src/components/ThemeSelector.js
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { h } from 'preact'
|
||||||
|
|
||||||
|
export default function ({ themeList, currentTheme, setTheme }) {
|
||||||
|
const options = themeList.map(theme => (
|
||||||
|
<option value={theme}>
|
||||||
|
{theme}
|
||||||
|
</option>))
|
||||||
|
|
||||||
|
return (
|
||||||
|
<select
|
||||||
|
value={currentTheme}
|
||||||
|
onChange={({ target }) => setTheme(target.value)}>
|
||||||
|
{options}
|
||||||
|
</select>)
|
||||||
|
}
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
import { h } from 'preact'
|
import { h } from 'preact'
|
||||||
|
|
||||||
export default function ({ emitName, emitURL }) {
|
export default function ({ setTargetName, setTargetUrl }) {
|
||||||
const reURL = /^(http|https):\/\/[^ "]+$/
|
const urlRE = /^(http|https):\/\/[^ "]+$/
|
||||||
|
|
||||||
const emit = url => {
|
const emit = url => {
|
||||||
emitName(url)
|
setTargetName(url)
|
||||||
emitURL(url)
|
setTargetUrl(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
const urlInputHandler = ({ target }) => {
|
const urlInputHandler = ({ target }) => {
|
||||||
const url = target.value
|
const url = target.value
|
||||||
emit(reURL.test(url)
|
emit(urlRE.test(url)
|
||||||
? url
|
? url
|
||||||
: null)
|
: null)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
59
src/index.js
59
src/index.js
|
|
@ -1,35 +1,50 @@
|
||||||
import { h, render } from 'preact'
|
import { h, render } from 'preact'
|
||||||
import { Link, Route, Router, Switch } from 'wouter-preact'
|
import { useState } from 'preact/hooks'
|
||||||
|
import { Route, Router, Switch } from 'wouter-preact'
|
||||||
|
|
||||||
import { useHashLocation } from '~/src/utils/utils.routing'
|
import { useHashLocation } from '~/src/utils/utils.routing'
|
||||||
|
import {
|
||||||
|
DEFAULT_THEME,
|
||||||
|
themeList,
|
||||||
|
assertTheme
|
||||||
|
} from '~/src/themes/themes'
|
||||||
|
|
||||||
import Home from '~/src/views/Home'
|
import Home from '~/src/views/Home'
|
||||||
import Player from '~/src/views/Player'
|
import Player from '~/src/views/Player'
|
||||||
|
|
||||||
|
import '~/src/style/base.css'
|
||||||
|
|
||||||
function App () {
|
function App () {
|
||||||
|
const [currentTheme, setCurrentTheme] =
|
||||||
|
useState(DEFAULT_THEME)
|
||||||
|
|
||||||
|
const setTheme = theme =>
|
||||||
|
setCurrentTheme(assertTheme(theme))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Router hook={useHashLocation}>
|
<Router hook={useHashLocation}>
|
||||||
<div className='App'>
|
<div className={['app', currentTheme].join(' ')}>
|
||||||
<nav>
|
<Switch>
|
||||||
<Link href='/'>Root</Link>
|
<Route path='/'>
|
||||||
</nav>
|
<Home {...{
|
||||||
|
setTheme,
|
||||||
<main>
|
themeList,
|
||||||
<Switch>
|
currentTheme
|
||||||
<Route
|
}} />
|
||||||
path='/'
|
</Route>
|
||||||
component={Home} />
|
<Route path='/play/:theme/:encodedUrl'>
|
||||||
<Route
|
{params => <Player {...{
|
||||||
path='/play/:theme/:encodedUrl'
|
setTheme,
|
||||||
component={Player} />
|
...params
|
||||||
<Route path='/top100'>
|
}} />}
|
||||||
top100
|
</Route>
|
||||||
</Route>
|
<Route path='/top100'>
|
||||||
<Route>
|
top100
|
||||||
404
|
</Route>
|
||||||
</Route>
|
<Route>
|
||||||
</Switch>
|
404
|
||||||
</main>
|
</Route>
|
||||||
|
</Switch>
|
||||||
</div>
|
</div>
|
||||||
</Router>
|
</Router>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
3
src/style/base.css
Normal file
3
src/style/base.css
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
html, body {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
15
src/themes/themes.js
Normal file
15
src/themes/themes.js
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
export const themeList = [
|
||||||
|
'default',
|
||||||
|
'default-dark',
|
||||||
|
'nord',
|
||||||
|
'solarized-dark',
|
||||||
|
'solarized-light',
|
||||||
|
'_raw'
|
||||||
|
]
|
||||||
|
|
||||||
|
export const DEFAULT_THEME = themeList[0]
|
||||||
|
|
||||||
|
export const assertTheme = theme =>
|
||||||
|
themeList.includes(theme)
|
||||||
|
? theme
|
||||||
|
: DEFAULT_THEME
|
||||||
|
|
@ -20,7 +20,7 @@ export const useHashLocation = () => {
|
||||||
return [loc, navigate]
|
return [loc, navigate]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const buildPlayLinkHref = (url, theme = 'default') =>
|
export const buildPlayLinkHref = (url, theme) =>
|
||||||
`/#/play/${theme}/${encodeURIComponent(url)}`
|
`/#/play/${theme}/${encodeURIComponent(url)}`
|
||||||
|
|
||||||
export const getFileExtension = fileName =>
|
export const getFileExtension = fileName =>
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,18 @@ import { Link } from 'wouter-preact'
|
||||||
|
|
||||||
import FileSelector from '~/src/components/FileSelector'
|
import FileSelector from '~/src/components/FileSelector'
|
||||||
import URLSelector from '~/src/components/URLSelector'
|
import URLSelector from '~/src/components/URLSelector'
|
||||||
|
import ThemeSelector from '~/src/components/ThemeSelector'
|
||||||
|
|
||||||
import { buildPlayLinkHref } from '~/src/utils/utils.routing'
|
import { buildPlayLinkHref } from '~/src/utils/utils.routing'
|
||||||
|
|
||||||
export default function () {
|
const playButton = (name, url, theme) => (
|
||||||
const [targetName, setTargetName] = useState(null)
|
<Link href={buildPlayLinkHref(url, theme)}>
|
||||||
const [targetURL, setTargetURL] = useState(null)
|
Play "{name}"
|
||||||
|
</Link>)
|
||||||
|
|
||||||
const playButton = (
|
export default function ({ themeList, currentTheme, setTheme }) {
|
||||||
<Link href={buildPlayLinkHref(targetURL)}>
|
const [targetName, setTargetName] = useState(null)
|
||||||
Play "{targetName}"
|
const [targetUrl, setTargetUrl] = useState(null)
|
||||||
</Link>)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
|
|
@ -26,16 +27,27 @@ export default function () {
|
||||||
</p>
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<FileSelector
|
<ThemeSelector {...{
|
||||||
emitName={setTargetName}
|
currentTheme,
|
||||||
emitURL={setTargetURL} />
|
themeList,
|
||||||
|
setTheme
|
||||||
|
}} />
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<URLSelector
|
<FileSelector {...{
|
||||||
emitName={setTargetName}
|
setTargetName,
|
||||||
emitURL={setTargetURL} />
|
setTargetUrl
|
||||||
|
}} />
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<URLSelector {...{
|
||||||
|
setTargetName,
|
||||||
|
setTargetUrl
|
||||||
|
}} />
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
{ targetURL ? playButton : null }
|
{ targetUrl
|
||||||
|
? playButton(targetName, targetUrl, currentTheme)
|
||||||
|
: null }
|
||||||
</main>)
|
</main>)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ import { h } from 'preact'
|
||||||
|
|
||||||
import { getFileExtension } from '~/src/utils/utils.routing'
|
import { getFileExtension } from '~/src/utils/utils.routing'
|
||||||
|
|
||||||
export default function ({params: {theme, encodedUrl}}) {
|
export default function ({setTheme, theme, encodedUrl}) {
|
||||||
|
setTheme(theme)
|
||||||
|
|
||||||
const url = decodeURIComponent(encodedUrl)
|
const url = decodeURIComponent(encodedUrl)
|
||||||
const type = getFileExtension(url)
|
const type = getFileExtension(url)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue