From 3e263211ebe5efd1788a3c0f36b95cc981a7fa14 Mon Sep 17 00:00:00 2001 From: legonzaur Date: Thu, 4 May 2023 11:48:40 +0200 Subject: [PATCH] optimize data structure and refs --- src/components/PlayerChart.vue | 6 +- src/components/PlayerList.vue | 62 +++++++++++--------- src/components/WeaponChart.vue | 12 ++-- src/main.ts | 103 ++++++++++++++++++++++++++++++++- src/stores/kill.ts | 34 ++++++----- src/views/PlayerView.vue | 21 +++---- 6 files changed, 178 insertions(+), 60 deletions(-) diff --git a/src/components/PlayerChart.vue b/src/components/PlayerChart.vue index 1845dda..95568e8 100644 --- a/src/components/PlayerChart.vue +++ b/src/components/PlayerChart.vue @@ -22,7 +22,7 @@ import dataLabel from 'chartjs-plugin-datalabels' import { useKillStore, Player, Filters } from '@/stores/kill' import { Scatter } from 'vue-chartjs' -import { defineComponent, PropType } from 'vue' +import { defineComponent, PropType, toRaw, unref } from 'vue' import { ChartEvent } from 'chart.js/dist/core/core.plugins' import { _DeepPartialObject } from 'chart.js/dist/types/utils' @@ -51,8 +51,8 @@ export default defineComponent({ computed: { playerList (): (Player & {id:string})[] { const data = this.store.getPlayerList(this.filters || {})?.value.data - if (!data) return Object.entries(this.store.fetchPlayers(this.filters || {}).value.data).map(e => ({ id: e[0], ...e[1] })) - const cut = Object.entries(data).map(e => ({ id: e[0], ...e[1] })) + if (!data) return Object.entries(this.store.fetchPlayers(this.filters || {}).value.data).map(e => ({ id: e[0], ...toRaw(e[1].value) })) + const cut = Object.entries(data).map(e => ({ id: e[0], ...toRaw(e[1].value) })) cut.sort((a, b) => { return b.kills - a.kills }) diff --git a/src/components/PlayerList.vue b/src/components/PlayerList.vue index 358914a..d1fa48d 100644 --- a/src/components/PlayerList.vue +++ b/src/components/PlayerList.vue @@ -16,18 +16,18 @@ v-for="(player, index) in playerList" v-bind:key="player.id" v-on:click="$emit('highlightPlayer', player.id)" :ref="`player:` + player.id">
{{ index+1 }}
-
{{ player.username }}
-
{{ player.kills }}
-
{{ player.deaths }}
-
{{ Math.round(player.kills / Math.max(1, player.deaths) * 100) / 100 }}
-
{{ player.max_distance }}
-
{{ Math.round(((player.total_distance / player.kills) || 0) * 100) / 100 }}
+
{{ player.value.username }}
+
{{ player.value.kills }}
+
{{ player.value.deaths }}
+
{{ Math.round(player.value.kills / Math.max(1, player.value.deaths) * 100) / 100 }}
+
{{ player.value.max_distance }}
+
{{ Math.round(((player.value.total_distance / player.value.kills) || 0) * 100) / 100 }}