import Time from '../common/Time.js' 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) }, } } const GameTeaser = { name: 'game-teaser', props: { game: Object, }, template: `
🧩 {{game.tilesFinished}}/{{game.tilesTotal}}
👥 {{game.players}}
{{time(game.started, game.finished)}}
↪️ Watch replay
`, methods: { time(start, end) { const icon = end ? '🏁' : '⏳' const from = start; const to = end || Time.timestamp() const timeDiffStr = Time.timeDiffStr(from, to) return `${icon} ${timeDiffStr}` }, }, } const ImageTeaser = { name: 'image-teaser', props: { image: Object }, template: `
`, computed: { style() { return { 'background-image': `url("${this.image.url}")`, } }, }, } export default { components: { Upload, GameTeaser, ImageTeaser, }, props: { gamesRunning: Array, gamesFinished: Array, images: Array, }, template: `

Running games

New game

or (or select from below)
Start new game

Image lib

Finished games

`, data() { return { tiles: 1000, image: '', } }, methods: { time(start, end) { const icon = end ? '🏁' : '⏳' const from = start; const to = end || Time.timestamp() const timeDiffStr = Time.timeDiffStr(from, to) return `${icon} ${timeDiffStr}` }, 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) } } } }