diff --git a/src/components/FileSelector.js b/src/components/FileSelector.js index df4eb62..1cdd8e9 100644 --- a/src/components/FileSelector.js +++ b/src/components/FileSelector.js @@ -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 } diff --git a/src/components/ThemeSelector.js b/src/components/ThemeSelector.js new file mode 100644 index 0000000..8c05a90 --- /dev/null +++ b/src/components/ThemeSelector.js @@ -0,0 +1,15 @@ +import { h } from 'preact' + +export default function ({ themeList, currentTheme, setTheme }) { + const options = themeList.map(theme => ( + )) + + return ( + ) +} diff --git a/src/components/URLSelector.js b/src/components/URLSelector.js index 1c86948..c64a824 100644 --- a/src/components/URLSelector.js +++ b/src/components/URLSelector.js @@ -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) } diff --git a/src/index.js b/src/index.js index 25210d1..2996c7c 100644 --- a/src/index.js +++ b/src/index.js @@ -1,35 +1,50 @@ 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 ( -
- - -
- - - - - top100 - - - 404 - - -
+
+ + + + + + {params => } + + + top100 + + + 404 + +
) diff --git a/src/style/base.css b/src/style/base.css new file mode 100644 index 0000000..6e8a07a --- /dev/null +++ b/src/style/base.css @@ -0,0 +1,3 @@ +html, body { + margin: 0; +} diff --git a/src/themes/themes.js b/src/themes/themes.js new file mode 100644 index 0000000..5926d1b --- /dev/null +++ b/src/themes/themes.js @@ -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 diff --git a/src/utils/utils.routing.js b/src/utils/utils.routing.js index c586cea..2296ecf 100644 --- a/src/utils/utils.routing.js +++ b/src/utils/utils.routing.js @@ -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 => diff --git a/src/views/Home.js b/src/views/Home.js index 9d04922..1aae88a 100644 --- a/src/views/Home.js +++ b/src/views/Home.js @@ -5,17 +5,18 @@ 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 = (name, url, theme) => ( + + Play "{name}" + ) - const playButton = ( - - Play "{targetName}" - ) +export default function ({ themeList, currentTheme, setTheme }) { + const [targetName, setTargetName] = useState(null) + const [targetUrl, setTargetUrl] = useState(null) return (
@@ -26,16 +27,27 @@ export default function () {

  • - +
  • - + +
  • +
  • +
- { targetURL ? playButton : null } + { targetUrl + ? playButton(targetName, targetUrl, currentTheme) + : null }
) } diff --git a/src/views/Player.jsx b/src/views/Player.jsx index b5ec640..c678f8f 100644 --- a/src/views/Player.jsx +++ b/src/views/Player.jsx @@ -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)