Skip to content

Commit

Permalink
remove SSR from simple utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
chantastic committed Jul 23, 2024
1 parent 4965bf9 commit 71beb25
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 81 deletions.
14 changes: 7 additions & 7 deletions chan.dev/src/components/button.astro
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
const { class: className, ...restProps } = Astro.props;
const {class: className, ...restProps} = Astro.props
---

<button
class:list={[
className,
"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded w-full",
]}
{...Astro.props}
class:list={[
className,
'bg-blue-500 hover:bg-blue-700 active:bg-blue-900 text-white font-bold py-2 px-4 rounded w-full',
]}
{...Astro.props}
>
<slot />
<slot />
</button>
38 changes: 38 additions & 0 deletions chan.dev/src/pages/flip.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
import Layout from '#layouts/Layout.astro'
import Prose from '#components/prose.astro'
import Button from '#components/button.astro'
---

<Layout>
<Prose as="main">
<main class="min-w-[26rem] text-center">
<Button data-refresh-button>Flip</Button>
<div class="text-9xl font-black font-mono" data-result>
</div>
</main>
</Prose>
</Layout>
<script>
let refreshButton: HTMLButtonElement = document.querySelector(
'[data-refresh-button]'
)!,
result: HTMLElement =
document.querySelector('[data-result]')!

function renderResult(el: HTMLElement) {
return (el.innerText = Math.round(Math.random())
? 'heads'
: 'tails')
}

renderResult(result)

refreshButton.addEventListener('click', () => {
result.innerText = '🪙'

setTimeout(() => {
renderResult(result)
}, 300)
})
</script>
29 changes: 0 additions & 29 deletions chan.dev/src/pages/flip/index.astro

This file was deleted.

8 changes: 0 additions & 8 deletions chan.dev/src/pages/flip/result.astro

This file was deleted.

42 changes: 42 additions & 0 deletions chan.dev/src/pages/roll.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
import Layout from '#layouts/Layout.astro'
import Prose from '#components/prose.astro'
import Button from '#components/button.astro'
---

<Layout>
<Prose as="main">
<main class="min-w-[26rem] text-center">
<Button data-refresh-button>Flip</Button>
<div class="text-9xl font-black font-mono" data-result>
</div>
</main>
</Prose>
</Layout>
<script>
let refreshButton: HTMLButtonElement = document.querySelector(
'[data-refresh-button]'
)!,
result: HTMLElement =
document.querySelector('[data-result]')!

function renderResult(el: HTMLElement) {
const sides =
Number(
new URL(location.href).searchParams.get('sides')
) || 6
return (el.innerText = String(
Math.floor(Math.random() * sides) + 1
))
}

renderResult(result)

refreshButton.addEventListener('click', () => {
result.innerText = '🎲'

setTimeout(() => {
renderResult(result)
}, 300)
})
</script>
29 changes: 0 additions & 29 deletions chan.dev/src/pages/roll/index.astro

This file was deleted.

8 changes: 0 additions & 8 deletions chan.dev/src/pages/roll/result.astro

This file was deleted.

0 comments on commit 71beb25

Please sign in to comment.