split files

This commit is contained in:
Zutatensuppe 2021-05-01 08:42:39 +02:00
parent 62f8991e11
commit 9e3a6721c9
7 changed files with 99 additions and 123 deletions

View file

@ -0,0 +1,40 @@
import Time from './../../common/Time.js'
const GameTeaser = {
name: 'game-teaser',
props: {
game: Object,
},
template: `
<div class="game-teaser" :style="style">
<a class="game-info" :href="'/g/' + game.id">
<span class="game-info-text">
🧩 {{game.tilesFinished}}/{{game.tilesTotal}}<br />
👥 {{game.players}}<br />
{{time(game.started, game.finished)}}<br />
</span>
</a>
<a v-if="false && game.hasReplay" class="game-replay" :href="'/replay/' + game.id">
Watch replay
</a>
</div>`,
computed: {
style() {
const url = this.game.imageUrl.replace('uploads/', 'uploads/r/') + '-375x210.webp'
return {
'background-image': `url("${url}")`,
}
},
},
methods: {
time(start, end) {
const icon = end ? '🏁' : '⏳'
const from = start;
const to = end || Time.timestamp()
const timeDiffStr = Time.timeDiffStr(from, to)
return `${icon} ${timeDiffStr}`
},
},
}
export default GameTeaser

View file

@ -0,0 +1,22 @@
const ImageTeaser = {
name: 'image-teaser',
props: {
image: Object
},
template: `<div class="imageteaser" :style="style" @click="onClick"></div>`,
computed: {
style() {
const url = this.image.url.replace('uploads/', 'uploads/r/') + '-150x100.webp'
return {
'background-image': `url("${url}")`,
}
},
},
methods: {
onClick() {
this.$emit('click')
},
},
}
export default ImageTeaser

View file

@ -0,0 +1,29 @@
const Upload = {
name: 'upload',
props: {
accept: String,
label: String,
},
template: `
<label>
<input type="file" style="display: none" @change="upload" :accept="accept" />
<span class="btn">{{label || 'Upload File'}}</span>
</label>
`,
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 default Upload