Display state of other participants

closes #4
This commit is contained in:
Knut Ahlers 2024-08-21 20:55:36 +02:00
parent d1fb9d4ced
commit 4deb1e1502
Signed by: luzifer
SSH key fingerprint: SHA256:/xtE5lCgiRDQr8SLxHMS92ZBlACmATUmF1crK16Ks4E

View file

@ -19,7 +19,7 @@
@keypress.enter="broadcastName" @keypress.enter="broadcastName"
> >
<button <button
class="btn btn-success" class="btn btn-secondary"
@click="broadcastName" @click="broadcastName"
> >
<i class="fas fa-pencil fa-fw me-1" /> <i class="fas fa-pencil fa-fw me-1" />
@ -93,6 +93,20 @@
<i class="fas fa-play fa-fw" /> <i class="fas fa-play fa-fw" />
</button> </button>
</div> </div>
<div class="text-center text-muted small mt-1 text-nowrap">
<span class="badge bg-success me-2">
<i class="fas fa-check fa-fw me-1" />
{{ foreignInstanceAnswerStatus[generateKey(cat, letter)].answered }}
</span>
<span class="badge bg-warning text-dark me-2">
<i class="fas fa-forward fa-fw me-1" />
{{ foreignInstanceAnswerStatus[generateKey(cat, letter)].skipped }}
</span>
<span class="badge bg-secondary">
<i class="fas fa-question fa-fw me-1" />
{{ foreignInstanceAnswerStatus[generateKey(cat, letter)].thinking }}
</span>
</div>
</template> </template>
<template v-else> <template v-else>
<div <div
@ -146,7 +160,7 @@ export default defineComponent({
.filter((e: any[]) => this.now.getTime() - e[1].lastActive < instanceTimeout)) .filter((e: any[]) => this.now.getTime() - e[1].lastActive < instanceTimeout))
}, },
answersGiven(): Object { answerKeys(): string[] {
const keys: string[] = [] const keys: string[] = []
for (const cat of this.gameState.categories) { for (const cat of this.gameState.categories) {
for (const letter of this.gameState.letters) { for (const letter of this.gameState.letters) {
@ -154,13 +168,38 @@ export default defineComponent({
} }
} }
return Object.fromEntries(keys.map(key => [ return keys
},
answersGiven(): Object {
return Object.fromEntries(this.answerKeys.map(key => [
key, Object.keys(this.activeInstances).map(instId => ({ key, Object.keys(this.activeInstances).map(instId => ({
answer: this.activeInstances[instId].answers[key], answer: this.activeInstances[instId].answers[key],
name: this.activeInstances[instId].name, name: this.activeInstances[instId].name,
})), })),
])) ]))
}, },
foreignInstanceAnswerStatus(): any {
const foreignInstances = Object.entries(this.activeInstances)
.filter(e => e[0] !== this.instance)
.map(e => e[1])
return Object.fromEntries(this.answerKeys
.map((key: string) => [
key, {
answered: foreignInstances
.filter((instance: any) => instance.answers[key])
.length,
skipped: foreignInstances
.filter((instance: any) => instance.answers[key] === '')
.length,
thinking: foreignInstances
.filter((instance: any) => instance.answers[key] === undefined)
.length,
},
]))
},
}, },
created(): void { created(): void {