Add progress bar

This commit is contained in:
Henry Hiles 2026-01-04 16:59:51 -05:00
commit e44850ff2d
No known key found for this signature in database
3 changed files with 114 additions and 85 deletions

View file

@ -4,6 +4,13 @@ import "../styles/index.css"
--- ---
<Layout> <Layout>
<section id="guesses">
<span></span>
<span></span>
<span></span>
<span class="correct">The Correct Answer - Queen</span>
</section>
<div>
<button id="play"> <button id="play">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960">
<path <path
@ -11,15 +18,14 @@ import "../styles/index.css"
></path> ></path>
</svg> </svg>
</button> </button>
<section id="bar">
<div id="bars"> <div id="bars">
<div></div> <div></div>
<div></div> <div></div>
<div></div> <div></div>
<div id="available"><div id="played"></div></div> <div id="available"></div>
<div id="played"></div>
</div> </div>
</section>
<button id="skip"> <button id="skip">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"
><path ><path
@ -27,6 +33,7 @@ import "../styles/index.css"
></path></svg ></path></svg
> >
</button> </button>
</div>
</Layout> </Layout>
<script> <script>
@ -37,13 +44,12 @@ import "../styles/index.css"
await auth.init({ await auth.init({
clientId: "NkcXqihOmrfZdBla", clientId: "NkcXqihOmrfZdBla",
clientSecret: "e6ldlWH48BEBOUZV1uIyIWJOf1KUGUEeH6qHkFvNjeU=", clientSecret: "e6ldlWH48BEBOUZV1uIyIWJOf1KUGUEeH6qHkFvNjeU=",
credentialsStorageKey: "key", credentialsStorageKey: "ZvZbtTWzx5@1zfiWUluxWD9@di17e1da",
}) })
player.setCredentialsProvider(auth.credentialsProvider) player.setCredentialsProvider(auth.credentialsProvider)
player.setEventSender(eventProducer) player.setEventSender(eventProducer)
// TODO: Use css anim for progress
class ExtendableTimeout { class ExtendableTimeout {
private timerId: ReturnType<typeof setTimeout> private timerId: ReturnType<typeof setTimeout>
private timeStart: number private timeStart: number
@ -70,28 +76,31 @@ import "../styles/index.css"
} }
const play = document.querySelector("#play") const play = document.querySelector("#play")
const played = document.querySelector("#played")
const skip = document.querySelector("#skip") const skip = document.querySelector("#skip")
const available = document.querySelector("#available") as HTMLDivElement const available = document.querySelector("#available")
let phase = 1 let phase = 1
let timer: ExtendableTimeout | null let timer: ExtendableTimeout | null
const getTimeout = () => 2 ** phase * 1000 const getTimeout = (phase: number) => (2 ** phase - 1) * 1000
const playVideo = async () => { const playVideo = async () => {
await player.load({ await player.load({
productId: "3188631", productId: "36737274",
productType: "track", productType: "track",
sourceId: "3188629", sourceId: "",
sourceType: "ALBUM", sourceType: "",
}) })
player.play() await player.play()
played?.classList.add("playing")
timer?.cancel() timer?.cancel()
timer = new ExtendableTimeout(() => { timer = new ExtendableTimeout(() => {
player.pause() player.pause()
timer = null timer = null
}, getTimeout()) played?.classList.remove("playing")
}, getTimeout(phase))
} }
play?.addEventListener("click", playVideo) play?.addEventListener("click", playVideo)
@ -100,13 +109,13 @@ import "../styles/index.css"
if (phase >= 4) return alert("FAIL!!!!") if (phase >= 4) return alert("FAIL!!!!")
phase += 1 phase += 1
//@ts-expect-error // @ts-expect-error
available.style["grid-column-end"] = phase + 1 available.style["grid-column-end"] = phase + 1
if (timer == null) { if (timer == null) {
playVideo() playVideo()
} else { } else {
timer.extend(getTimeout()) timer.extend(getTimeout(phase))
} }
}) })
</script> </script>

View file

@ -1,10 +1,44 @@
#bar { main > * {
width: min(40rem, 100%); display: flex;
width: 100%;
justify-content: center;
align-items: center;
width: min(45rem, 100%);
}
& #bars { #guesses {
flex-direction: column;
gap: 2rem;
& span {
display: flex;
justify-content: center;
align-items: center;
font-weight: bold;
background-color: #000;
height: 2.4rem;
width: 100%;
border-radius: 2rem;
&.correct {
background-image: linear-gradient(
to bottom right,
var(--brand-pink) 0%,
var(--brand-purple) 100%
);
}
}
}
#bars {
display: grid; display: grid;
grid-template-columns: 1fr 2fr 4fr 8fr; grid-template-columns: 1fr 2fr 4fr 8fr;
gap: 0.3rem; justify-content: center;
width: min(40rem, 100%);
position: relative;
& * { & * {
background-color: rgba(255, 255, 255, 20%); background-color: rgba(255, 255, 255, 20%);
@ -14,38 +48,27 @@
} }
& #available { & #available {
background-color: white;
grid-column-start: 1; grid-column-start: 1;
width: 100%; width: 100%;
} }
}
& #available { & #played {
background-color: white;
width: 0;
}
}
.frame-container {
position: relative;
@supports (-moz-appearance: none) {
display: none;
}
& span {
pointer-events: none;
}
& iframe {
position: absolute; position: absolute;
width: 100%; background: linear-gradient(
height: 100%; to bottom right,
border: none; #cc56d0 0%,
z-index: -2; var(--brand-purple) 100%
pointer-events: all; );
clip-path: inset(90% 0 0 90%); grid-column: 1 / -1;
transform-origin: bottom right;
transform: scale(10); width: 0%;
transition: none;
&.playing {
transition: width 15s linear;
width: 100%;
}
} }
} }

View file

@ -1,13 +1,17 @@
html, html,
body { body {
display: flex;
flex-direction: column;
margin: 0; margin: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
:root { :root {
background: linear-gradient(black, rgb(18, 2, 38));
--brand-purple: #6e06ff; --brand-purple: #6e06ff;
--brand-pink: #cc56d0;
background: linear-gradient(black, rgb(18, 2, 38));
font-family: sans-serif; font-family: sans-serif;
} }
@ -18,6 +22,7 @@ img {
} }
nav { nav {
position: absolute;
display: flex; display: flex;
align-items: center; align-items: center;
padding: 2rem 3rem; padding: 2rem 3rem;
@ -35,12 +40,15 @@ nav {
main { main {
color: white; color: white;
display: flex; display: flex;
flex-direction: column;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
gap: 1rem;
flex-grow: 1;
} }
button, button {
.fake-button {
--border-radius: 2rem; --border-radius: 2rem;
position: relative; position: relative;
background: white; background: white;
@ -60,16 +68,12 @@ button,
background: rgb(211, 211, 211); background: rgb(211, 211, 211);
} }
&.fake-button {
pointer-events: none;
}
& svg { & svg {
width: 2.2rem; width: 2.2rem;
} }
} }
:is(button, .fake-button)::before { button::before {
--border-size: 5px; --border-size: 5px;
content: ""; content: "";
z-index: -1; z-index: -1;
@ -78,7 +82,7 @@ button,
height: 100%; height: 100%;
background-image: linear-gradient( background-image: linear-gradient(
to bottom right, to bottom right,
#cc56d0 0%, var(--brand-pink) 0%,
var(--brand-purple) 100% var(--brand-purple) 100%
); );
padding: var(--border-size); padding: var(--border-size);
@ -86,10 +90,3 @@ button,
left: calc(var(--border-size) * -1); left: calc(var(--border-size) * -1);
position: absolute; position: absolute;
} }
.fake-button-container {
cursor: pointer;
&:hover {
filter: brightness(80%);
}
}