bugfix: fix typing for Round.Selections

This commit is contained in:
Settel 2022-09-13 11:06:48 +02:00
parent 1361d98570
commit cd475288f6
4 changed files with 11 additions and 11 deletions

View File

@ -2,9 +2,9 @@
<div class="playground__container">
<div class="playground__area">
<div class="playground__sources" :class="{ 'playground__sources__show': showSources }">
<SourceCard v-for="source in sources" :key="source.id" :source="source" :selectable="selectable"
<SourceCard v-for="(source, index) in sources" :key="source.id" :source="source" :selectable="selectable"
:selected="selection == source.id" @click="selectSource(source)" :badge="badgeMap[source.id]"
:disabled="disabledMap[source.id]" />
:disabled="disabledMap[source.id]" :index="index" />
</div>
<div class="playground__spacer" />
<div class="playground__quote" :class="{ 'playground__quote__show': showQuote}">
@ -36,7 +36,8 @@ const sources = round.sources as Sources
const { saveSelection } = useEngine()
const selection = ref('')
const selectable = computed(() => game.phase === 'select-quote' && !selection.value && !round.selections[useUserinfoStore().id])
const { id } = useUserinfoStore()
const selectable = computed(() => game.phase === 'select-quote' && !selection.value && !round.selections[id])
const selectSource = async (source: Source): Promise<void> => {
if (selectable.value) {
await saveSelection(source.id)
@ -50,7 +51,7 @@ const showSources = computed(() => ['select-quote', 'reveal-show-count', 'reveal
const showQuote = showSources
const showSkipButton = computed(() => game.phase === 'select-quote')
const badgeMap = computed(() => {
const badgeMap = {}
const badgeMap = {} as { [key: string]: number}
if (game.phase === 'reveal-show-count') {
for (const id in round.revelation.votes) {
badgeMap[id] = round.revelation.votes[id].length
@ -60,7 +61,7 @@ const badgeMap = computed(() => {
})
const disabledMap = computed(() => {
const disabledMap = {}
const disabledMap = {} as { [key: string]: boolean}
if (game.phase === 'reveal-source') {
for (const id in round.revelation.sources) {
disabledMap[id] = !round.revelation.sources[id]

View File

@ -15,6 +15,7 @@ import type { Source } from '@/composables/engine.d'
const props = defineProps<{
source: Source,
index: number,
selectable?: boolean,
selected?: boolean,
badge?: number,

View File

@ -35,12 +35,10 @@ export type Source = {
export type Sources = Array<Source>
export type Selection = {
id: string
export type Selections = {
[key: string]: boolean
}
export type Selections = Array<Selection>
export type RevelationVotes = {
[key: string]: Array<string>
}

View File

@ -7,7 +7,7 @@ export const useRoundStore = defineStore('RoundStore', {
round: {
quote: '',
sources: [] as Sources,
selections: [] as Selections,
selections: {} as Selections,
revelation: {
votes: {} as RevelationVotes,
sources: {} as RevelationSources,
@ -20,7 +20,7 @@ export const useRoundStore = defineStore('RoundStore', {
round = round || {} as Round
this.round.quote = round.quote || ''
this.round.sources = round.sources || [] as Sources
this.round.selections = round.selections || [] as Selections
this.round.selections = round.selections || {} as Selections
this.round.revelation.votes = round.revelation?.votes || {} as RevelationVotes
this.round.revelation.sources = round.revelation?.sources || {} as RevelationSources
},