import React, { useState } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
const LOFI_GIRL_URL = "https://www.youtube.com/embed/jfKfPfyJRdk?autoplay=1";
const LOFI_BOY_URL = "https://www.youtube.com/embed/4xDzrJKXOOY?autoplay=1";
function App() {
const [selectedPlaylist, setSelectedPlaylist] = useState(null);
const selectPlaylist = (url) => {
setSelectedPlaylist(url);
};
return (
<div className="container">
<h1>Lofi Playlist Selector</h1>
<div className="button-container">
<button onClick={() => selectPlaylist(LOFI_GIRL_URL)}>Lofi Girl</button>
<button onClick={() => selectPlaylist(LOFI_BOY_URL)}>Lofi Boy</button>
</div>
{selectedPlaylist && (
<div className="video-container">
<iframe
src={selectedPlaylist}
title="YouTube video player"
frameBorder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowFullScreen
width="560"
height="315"
></iframe>
</div>
)}
<p className="source-link">
<a href={import.meta.url.replace("esm.town", "val.town")} target="_blank" rel="noopener noreferrer">
View Source
</a>
</p>
</div>
);
}
function client() {
createRoot(document.getElementById("root")).render(<App />);
}
if (typeof document !== "undefined") {
client();
}
async function server(request: Request): Promise<Response> {
return new Response(
`
<html>
<head>
<title>Lofi Playlist Selector</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>${css}</style>
</head>
<body>
<div id="root"></div>
<script src="https://esm.town/v/std/catch"></script>
<script type="module" src="${import.meta.url}"></script>
</body>
</html>
`,
{
headers: {
"content-type": "text/html",
},
}
);
}
const css = `
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f0f0f0;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
text-align: center;
}
h1 {
color: #333;
}
.button-container {
margin-bottom: 20px;
}
button {
background-color: #4CAF50;