mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-04 17:07: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'
|
||||
|
||||
export default function ({ emitName, emitURL }) {
|
||||
export default function ({ setTargetName, setTargetUrl }) {
|
||||
const fileInputHandler = ({ target }) => {
|
||||
const file = target.files[0]
|
||||
emitName(file.name)
|
||||
emitURL(`${URL.createObjectURL(file)}#${file.name}`)
|
||||
setTargetName(file.name)
|
||||
setTargetUrl(`${URL.createObjectURL(file)}#${file.name}`)
|
||||
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'
|
||||
|
||||
export default function ({ emitName, emitURL }) {
|
||||
const reURL = /^(http|https):\/\/[^ "]+$/
|
||||
export default function ({ setTargetName, setTargetUrl }) {
|
||||
const urlRE = /^(http|https):\/\/[^ "]+$/
|
||||
|
||||
const emit = url => {
|
||||
emitName(url)
|
||||
emitURL(url)
|
||||
setTargetName(url)
|
||||
setTargetUrl(url)
|
||||
}
|
||||
|
||||
const urlInputHandler = ({ target }) => {
|
||||
const url = target.value
|
||||
emit(reURL.test(url)
|
||||
emit(urlRE.test(url)
|
||||
? url
|
||||
: null)
|
||||
}
|
||||
|
|
|
|||
43
src/index.js
43
src/index.js
|
|
@ -1,27 +1,43 @@
|
|||
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 {
|
||||
DEFAULT_THEME,
|
||||
themeList,
|
||||
assertTheme
|
||||
} from '~/src/themes/themes'
|
||||
|
||||
import Home from '~/src/views/Home'
|
||||
import Player from '~/src/views/Player'
|
||||
|
||||
import '~/src/style/base.css'
|
||||
|
||||
function App () {
|
||||
const [currentTheme, setCurrentTheme] =
|
||||
useState(DEFAULT_THEME)
|
||||
|
||||
const setTheme = theme =>
|
||||
setCurrentTheme(assertTheme(theme))
|
||||
|
||||
return (
|
||||
<Router hook={useHashLocation}>
|
||||
<div className='App'>
|
||||
<nav>
|
||||
<Link href='/'>Root</Link>
|
||||
</nav>
|
||||
|
||||
<main>
|
||||
<div className={['app', currentTheme].join(' ')}>
|
||||
<Switch>
|
||||
<Route
|
||||
path='/'
|
||||
component={Home} />
|
||||
<Route
|
||||
path='/play/:theme/:encodedUrl'
|
||||
component={Player} />
|
||||
<Route path='/'>
|
||||
<Home {...{
|
||||
setTheme,
|
||||
themeList,
|
||||
currentTheme
|
||||
}} />
|
||||
</Route>
|
||||
<Route path='/play/:theme/:encodedUrl'>
|
||||
{params => <Player {...{
|
||||
setTheme,
|
||||
...params
|
||||
}} />}
|
||||
</Route>
|
||||
<Route path='/top100'>
|
||||
top100
|
||||
</Route>
|
||||
|
|
@ -29,7 +45,6 @@ function App () {
|
|||
404
|
||||
</Route>
|
||||
</Switch>
|
||||
</main>
|
||||
</div>
|
||||
</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]
|
||||
}
|
||||
|
||||
export const buildPlayLinkHref = (url, theme = 'default') =>
|
||||
export const buildPlayLinkHref = (url, theme) =>
|
||||
`/#/play/${theme}/${encodeURIComponent(url)}`
|
||||
|
||||
export const getFileExtension = fileName =>
|
||||
|
|
|
|||
|
|
@ -5,18 +5,19 @@ import { Link } from 'wouter-preact'
|
|||
|
||||
import FileSelector from '~/src/components/FileSelector'
|
||||
import URLSelector from '~/src/components/URLSelector'
|
||||
import ThemeSelector from '~/src/components/ThemeSelector'
|
||||
|
||||
import { buildPlayLinkHref } from '~/src/utils/utils.routing'
|
||||
|
||||
export default function () {
|
||||
const [targetName, setTargetName] = useState(null)
|
||||
const [targetURL, setTargetURL] = useState(null)
|
||||
|
||||
const playButton = (
|
||||
<Link href={buildPlayLinkHref(targetURL)}>
|
||||
Play "{targetName}"
|
||||
const playButton = (name, url, theme) => (
|
||||
<Link href={buildPlayLinkHref(url, theme)}>
|
||||
Play "{name}"
|
||||
</Link>)
|
||||
|
||||
export default function ({ themeList, currentTheme, setTheme }) {
|
||||
const [targetName, setTargetName] = useState(null)
|
||||
const [targetUrl, setTargetUrl] = useState(null)
|
||||
|
||||
return (
|
||||
<main>
|
||||
<p>
|
||||
|
|
@ -26,16 +27,27 @@ export default function () {
|
|||
</p>
|
||||
<ul>
|
||||
<li>
|
||||
<FileSelector
|
||||
emitName={setTargetName}
|
||||
emitURL={setTargetURL} />
|
||||
<ThemeSelector {...{
|
||||
currentTheme,
|
||||
themeList,
|
||||
setTheme
|
||||
}} />
|
||||
</li>
|
||||
<li>
|
||||
<URLSelector
|
||||
emitName={setTargetName}
|
||||
emitURL={setTargetURL} />
|
||||
<FileSelector {...{
|
||||
setTargetName,
|
||||
setTargetUrl
|
||||
}} />
|
||||
</li>
|
||||
<li>
|
||||
<URLSelector {...{
|
||||
setTargetName,
|
||||
setTargetUrl
|
||||
}} />
|
||||
</li>
|
||||
</ul>
|
||||
{ targetURL ? playButton : null }
|
||||
{ targetUrl
|
||||
? playButton(targetName, targetUrl, currentTheme)
|
||||
: null }
|
||||
</main>)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ import { h } from 'preact'
|
|||
|
||||
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 type = getFileExtension(url)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue