ninelands-reddit/src/client/game.ts
Lukas Müllner 83b3ab69a8
Some checks failed
CI / test (push) Failing after 0s
chore: Devvit-Vorlage Bare und CLAUDE.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 14:38:53 +01:00

23 lines
749 B
TypeScript

import {fetchGetCounter, fetchIncCounter} from './fetch.ts'
async function init(): Promise<void> {
const counter = document.getElementById('counter') as HTMLOutputElement
const incBtn = document.getElementById('inc-btn') as HTMLButtonElement
const decBtn = document.getElementById('dec-btn') as HTMLButtonElement
incBtn.addEventListener('click', () => void incCount(counter, 1))
decBtn.addEventListener('click', () => void incCount(counter, -1))
const rsp = await fetchGetCounter()
counter.value = rsp ? `${rsp.count}` : 'Error'
}
async function incCount(
counter: HTMLOutputElement,
amount: number,
): Promise<void> {
const inc = await fetchIncCounter(amount)
counter.value = inc ? `${inc.count}` : 'Error'
}
void init()