const Upload = { name: 'upload', props: { accept: String, label: String, }, template: ` `, methods: { async upload(evt) { const file = evt.target.files[0] if (!file) return; const formData = new FormData(); formData.append('file', file, file.name); const res = await fetch('/upload', { method: 'post', body: formData, }) const j = await res.json() this.$emit('uploaded', j) }, } } export const timestamp = () => { const d = new Date(); return Date.UTC( d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds(), ) } export default { components: { Upload, }, props: { games: Array, images: Array, }, template: `

Running games

New game

or (or select from below)
Start new game

Image lib

`, data() { return { tiles: 1000, image: '', } }, methods: { time(start, end) { const icon = end ? '🏁' : '⏳' const from = start; const to = end || timestamp() const MS = 1 const SEC = MS * 1000 const MIN = SEC * 60 const HOUR = MIN * 60 const DAY = HOUR * 24 let diff = to - from const d = Math.floor(diff / DAY) diff = diff % DAY const h = Math.floor(diff / HOUR) diff = diff % HOUR const m = Math.floor(diff / MIN) diff = diff % MIN const s = Math.floor(diff / SEC) return `${icon} ${d}d ${h}h ${m}m ${s}s` }, mediaImgUploaded(j) { this.image = j.image }, async onNewGameClick() { const res = await fetch('/newgame', { method: 'post', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({tiles: this.tiles, image: this.image}), }) if (res.status === 200) { const game = await res.json() location.assign(game.url) } } } }