Skip to content

Commit

Permalink
web: Store Brawler IDs for survey
Browse files Browse the repository at this point in the history
  • Loading branch information
schneefux committed Jan 5, 2025
1 parent d7f4aa1 commit 64f0fc6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion web/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ declare module 'vue' {
SPowerplay: typeof import('./components/klicker/s-powerplay.vue')['default']
SSeason: typeof import('./components/klicker/s-season.vue')['default']
STrophies: typeof import('./components/klicker/s-trophies.vue')['default']
SurveyCard: typeof import('./components/survey/survey-card.vue')['default']
SurveyCard: typeof import('./components/survey-card.vue')['default']
SWithGadget: typeof import('./components/klicker/s-with-gadget.vue')['default']
SWithStarpower: typeof import('./components/klicker/s-with-starpower.vue')['default']
TopBrawlersCard: typeof import('./components/top-brawlers-card.vue')['default']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class="text-center flex-1"
dark
md
@click="vote(choice.slug)"
@click="vote(choice.brawlstarsId)"
>
<media-img
:path="`/brawlers/${choice.slug}/avatar`"
Expand Down Expand Up @@ -87,8 +87,8 @@ export default defineComponent({
const api = useApi()
const brawlersNotSeen = computed(() => {
const brawlersSeenSlugs = store.modeSurveyBrawlersSeen[props.mode] ?? []
return brawlers.value.filter(brawler => !brawlersSeenSlugs.includes(brawler.slug))
const brawlersSeenIds = store.modeSurveyBrawlersSeen[props.mode] ?? []
return brawlers.value.filter(brawler => !brawlersSeenIds.includes(brawler.brawlstarsId))
})
const progress = computed(() => 1 - brawlersNotSeen.value.length / brawlers.value.length)
Expand All @@ -108,20 +108,21 @@ export default defineComponent({
const choices = ref<BrawlerMetadata[]>([])
onMounted(() => generateChoices())
const vote = async (brawlerSlug: string) => {
store.addBrawlersSeenInModeSurvey(props.mode, choices.value.map(choice => choice.slug))
const vote = async (brawlerId: string) => {
store.addBrawlersSeenInModeSurvey(props.mode, choices.value.map(choice => choice.brawlstarsId))
emit('interact')
await api.survey.vote.mutate({
tag: props.player.tag.substring(1),
mode: props.mode,
best: brawlerSlug,
rest: choices.value.filter(choice => choice.slug != brawlerSlug).map(choice => choice.slug),
best: brawlerId,
rest: choices.value.filter(choice => choice.brawlstarsId != brawlerId).map(choice => choice.brawlstarsId),
player: {
trophies: props.player.trophies,
brawlersTrophies: Object.values(props.player.brawlers).map(brawler => ({
name: brawler.name,
power: brawler.power,
trophies: brawler.trophies,
})),
},
Expand Down
6 changes: 3 additions & 3 deletions web/stores/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ export const usePreferencesStore = defineStore('preferences', () => {
trackedPlayers.value = trackedPlayers.value.filter(p => p.tag !== tag)
}

function addBrawlersSeenInModeSurvey(mode: string, brawlerSlugs: string[]) {
function addBrawlersSeenInModeSurvey(mode: string, brawlerIds: string[]) {
const responses = modeSurveyBrawlersSeen.value[mode] || []
modeSurveyBrawlersSeen.value = {
...modeSurveyBrawlersSeen.value,
[mode]: [...responses, ...brawlerSlugs],
[mode]: [...responses, ...brawlerIds],
}
}

Expand All @@ -71,7 +71,7 @@ export const usePreferencesStore = defineStore('preferences', () => {
}
// v10: migration to pinia-plugin-persistedstate
// v11: added trackedPlayers
// v12: added modeSurveyResponses
// v12: added modeSurveyBrawlersSeen
version.value = 12
})

Expand Down

0 comments on commit 64f0fc6

Please sign in to comment.