mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-04 17:07:22 +00:00
Extract themeEngine
This commit is contained in:
parent
eb8025791b
commit
c9f42e497a
5 changed files with 30 additions and 28 deletions
|
|
@ -1,15 +1,16 @@
|
||||||
import { h } from 'preact'
|
import { h } from 'preact'
|
||||||
|
|
||||||
export default function ({ themeList, currentTheme, setTheme }) {
|
export default function ({ themeEngine }) {
|
||||||
const options = themeList.map(theme => (
|
const options = themeEngine.themes.map(theme => (
|
||||||
<option value={theme}>
|
<option value={theme}>
|
||||||
{theme}
|
{theme}
|
||||||
</option>))
|
</option>))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<select
|
<select
|
||||||
value={currentTheme}
|
value={themeEngine.currentTheme}
|
||||||
onChange={({ target }) => setTheme(target.value)}>
|
onChange={({ target }) =>
|
||||||
|
themeEngine.setTheme(target.value)}>
|
||||||
{options}
|
{options}
|
||||||
</select>)
|
</select>)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ const INITIAL_STATUS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ({url}) {
|
export default function ({url}) {
|
||||||
console.log(123, url)
|
|
||||||
const [status, setStatus] = useState(INITIAL_STATUS)
|
const [status, setStatus] = useState(INITIAL_STATUS)
|
||||||
|
|
||||||
const [vm, setVM] = useState(null)
|
const [vm, setVM] = useState(null)
|
||||||
|
|
|
||||||
19
src/index.js
19
src/index.js
|
|
@ -1,12 +1,9 @@
|
||||||
import { h, render } from 'preact'
|
import { h, render } from 'preact'
|
||||||
import { useState } from 'preact/hooks'
|
|
||||||
import { Route, Router, Switch } from 'wouter-preact'
|
import { Route, Router, Switch } from 'wouter-preact'
|
||||||
|
|
||||||
import { useHashLocation } from '~/src/utils/utils.routing'
|
import { useHashLocation } from '~/src/utils/utils.routing'
|
||||||
import {
|
import {
|
||||||
DEFAULT_THEME,
|
useThemeEngine
|
||||||
themeList,
|
|
||||||
assertTheme
|
|
||||||
} from '~/src/themes/themes'
|
} from '~/src/themes/themes'
|
||||||
|
|
||||||
import HomeView from '~/src/views/HomeView'
|
import HomeView from '~/src/views/HomeView'
|
||||||
|
|
@ -15,26 +12,20 @@ import PlayerView from '~/src/views/PlayerView'
|
||||||
import '~/src/style/base.css'
|
import '~/src/style/base.css'
|
||||||
|
|
||||||
function App () {
|
function App () {
|
||||||
const [currentTheme, setCurrentTheme] =
|
const themeEngine = useThemeEngine()
|
||||||
useState(DEFAULT_THEME)
|
|
||||||
|
|
||||||
const setTheme = theme =>
|
|
||||||
setCurrentTheme(assertTheme(theme))
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Router hook={useHashLocation}>
|
<Router hook={useHashLocation}>
|
||||||
<div className={['app', currentTheme].join(' ')}>
|
<div className={['app', themeEngine.currentTheme].join(' ')}>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path='/'>
|
<Route path='/'>
|
||||||
<HomeView {...{
|
<HomeView {...{
|
||||||
setTheme,
|
themeEngine
|
||||||
themeList,
|
|
||||||
currentTheme
|
|
||||||
}} />
|
}} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path='/play/:theme/:encodedUrl'>
|
<Route path='/play/:theme/:encodedUrl'>
|
||||||
{params => <PlayerView {...{
|
{params => <PlayerView {...{
|
||||||
setTheme,
|
setTheme: themeEngine.setTheme,
|
||||||
...params
|
...params
|
||||||
}} />}
|
}} />}
|
||||||
</Route>
|
</Route>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
import { useState, useCallback } from 'preact/hooks'
|
||||||
|
|
||||||
import '~/src/style/themes.css'
|
import '~/src/style/themes.css'
|
||||||
|
|
||||||
export const themeList = [
|
const themes = [
|
||||||
'default',
|
'default',
|
||||||
'default-dark',
|
'default-dark',
|
||||||
'nord',
|
'nord',
|
||||||
|
|
@ -9,9 +11,20 @@ export const themeList = [
|
||||||
'_raw'
|
'_raw'
|
||||||
]
|
]
|
||||||
|
|
||||||
export const DEFAULT_THEME = themeList[0]
|
const DEFAULT_THEME = themes[0]
|
||||||
|
|
||||||
export const assertTheme = theme =>
|
const assertTheme = theme =>
|
||||||
themeList.includes(theme)
|
themes.includes(theme)
|
||||||
? theme
|
? theme
|
||||||
: DEFAULT_THEME
|
: DEFAULT_THEME
|
||||||
|
|
||||||
|
export const useThemeEngine = (defaultTheme = DEFAULT_THEME) => {
|
||||||
|
const [currentTheme, setCurrentTheme] =
|
||||||
|
useState(DEFAULT_THEME)
|
||||||
|
|
||||||
|
const setTheme = useCallback(theme => {
|
||||||
|
setCurrentTheme(assertTheme(theme))
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
return { currentTheme, setTheme, themes };
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ const playButton = (name, url, theme) => (
|
||||||
Play "{name}"
|
Play "{name}"
|
||||||
</Link>)
|
</Link>)
|
||||||
|
|
||||||
export default function ({ themeList, currentTheme, setTheme }) {
|
export default function ({ themeEngine }) {
|
||||||
const [targetName, setTargetName] = useState(null)
|
const [targetName, setTargetName] = useState(null)
|
||||||
const [targetUrl, setTargetUrl] = useState(null)
|
const [targetUrl, setTargetUrl] = useState(null)
|
||||||
|
|
||||||
|
|
@ -28,9 +28,7 @@ export default function ({ themeList, currentTheme, setTheme }) {
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<ThemeSelector {...{
|
<ThemeSelector {...{
|
||||||
currentTheme,
|
themeEngine
|
||||||
themeList,
|
|
||||||
setTheme
|
|
||||||
}} />
|
}} />
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
|
@ -47,7 +45,7 @@ export default function ({ themeList, currentTheme, setTheme }) {
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
{ targetUrl
|
{ targetUrl
|
||||||
? playButton(targetName, targetUrl, currentTheme)
|
? playButton(targetName, targetUrl, themeEngine.currentTheme)
|
||||||
: null }
|
: null }
|
||||||
</main>)
|
</main>)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue