From 05f63c7c77fbabb8a466c020785c82d89154f13d Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Thu, 18 Jan 2024 14:18:51 -0600 Subject: [PATCH] Troig --- islands/Dashboard.tsx | 107 +++++++++++++++++++++++------------------- islands/Nav.tsx | 10 ++++ 2 files changed, 69 insertions(+), 48 deletions(-) diff --git a/islands/Dashboard.tsx b/islands/Dashboard.tsx index 0e736a0..d00dc12 100644 --- a/islands/Dashboard.tsx +++ b/islands/Dashboard.tsx @@ -9,6 +9,7 @@ import { Button } from '@homeman/components/Button.tsx' import { JSX } from 'preact' import { confetti } from 'https://esm.sh/@tsparticles/confetti@3.0.3' import { useEffect } from 'preact/hooks' +import { IS_BROWSER } from '$fresh/runtime.ts' interface Props { users: Record @@ -30,6 +31,63 @@ interface UserSelectButtonProps extends JSX.HTMLAttributes { user: User } +let fireworks: HTMLAudioElement | null +if (IS_BROWSER) { + fireworks = new Audio('/fireworks.mp3') +} + +function excitement() { + if (IS_BROWSER) { + const count = 200, + defaults = { + origin: { y: 0.7 }, + } + + if (fireworks) fireworks.play() + + // deno-lint-ignore no-inner-declarations + function fire(particleRatio: number, opts: { + spread?: number + startVelocity?: number + decay?: number + scalar?: number + }) { + confetti( + Object.assign({}, defaults, opts, { + particleCount: Math.floor(count * particleRatio), + }), + ) + } + + fire(0.25, { + spread: 26, + startVelocity: 55, + }) + + fire(0.2, { + spread: 60, + }) + + fire(0.35, { + spread: 100, + decay: 0.91, + scalar: 0.8, + }) + + fire(0.1, { + spread: 120, + startVelocity: 25, + decay: 0.92, + scalar: 1.2, + }) + + fire(0.1, { + spread: 120, + startVelocity: 45, + }) + } +} + function UserSelectButton( { user: { id, name, avatarUrl, color }, tabindex, ...props }: UserSelectButtonProps, @@ -92,54 +150,7 @@ export default function Dashboard( }) }, []) - useEffect(() => { - const fireworks = new Audio('/fireworks.mp3') - const count = 200, - defaults = { - origin: { y: 0.7 }, - } - - function fire(particleRatio: number, opts: { - spread?: number - startVelocity?: number - decay?: number - scalar?: number - }) { - fireworks.play() - confetti( - Object.assign({}, defaults, opts, { - particleCount: Math.floor(count * particleRatio), - }), - ) - } - - fire(0.25, { - spread: 26, - startVelocity: 55, - }) - - fire(0.2, { - spread: 60, - }) - - fire(0.35, { - spread: 100, - decay: 0.91, - scalar: 0.8, - }) - - fire(0.1, { - spread: 120, - startVelocity: 25, - decay: 0.92, - scalar: 1.2, - }) - - fire(0.1, { - spread: 120, - startVelocity: 45, - }) - }) + useEffect(excitement) useEffect(() => { let es = new EventSource('/api/todo') diff --git a/islands/Nav.tsx b/islands/Nav.tsx index da0311f..46b9a8d 100644 --- a/islands/Nav.tsx +++ b/islands/Nav.tsx @@ -5,6 +5,10 @@ import { Bars3Outline } from 'preact-heroicons' import { Clock } from '@homeman/islands/Clock.tsx' import { Dialog } from '@homeman/components/Dialog.tsx' import { useSignal } from '@preact/signals' +import { IS_BROWSER } from '$fresh/runtime.ts' + +let fireworks: HTMLAudioElement | undefined +if (IS_BROWSER) fireworks = new Audio('/fireworks.mp3') export function Nav(/* props: {} */) { const showMenu = useSignal(false) @@ -23,6 +27,12 @@ export function Nav(/* props: {} */) { Daily Routine Edit Users +