From 583298720e54c41b21bf3cd79f024c6868c0bccd Mon Sep 17 00:00:00 2001 From: zurdi Date: Tue, 20 May 2025 17:15:40 +0000 Subject: [PATCH] refactor: enhance PlatformsStats component with sorting functionality and clean up SummaryStats template --- .../Settings/ServerStats/PlatformsStats.vue | 120 +++++++++++------- .../Settings/ServerStats/SummaryStats.vue | 5 - 2 files changed, 74 insertions(+), 51 deletions(-) diff --git a/frontend/src/components/Settings/ServerStats/PlatformsStats.vue b/frontend/src/components/Settings/ServerStats/PlatformsStats.vue index 58c845b66..a3134fbfa 100644 --- a/frontend/src/components/Settings/ServerStats/PlatformsStats.vue +++ b/frontend/src/components/Settings/ServerStats/PlatformsStats.vue @@ -3,6 +3,7 @@ import { formatBytes } from "@/utils"; import PlatformListItem from "@/components/common/Platform/ListItem.vue"; import storePlatforms from "@/stores/platforms"; import { storeToRefs } from "pinia"; +import { ref, computed } from "vue"; // Props const props = defineProps<{ @@ -11,62 +12,89 @@ const props = defineProps<{ const platformsStore = storePlatforms(); const { filteredPlatforms } = storeToRefs(platformsStore); +const orderBy = ref("name"); // Functions -function getPercentage(filesize: number | string, total: number): number { +const sortedPlatforms = computed(() => { + const platforms = [...filteredPlatforms.value]; + if (orderBy.value === "size") { + return platforms.sort( + (a, b) => Number(b.fs_size_bytes) - Number(a.fs_size_bytes), + ); + } + // Default to name + return platforms.sort((a, b) => + a.name.localeCompare(b.name, undefined, { sensitivity: "base" }), + ); +}); + +function getPlatformPercentage( + filesize: number | string, + total: number, +): number { const size = typeof filesize === "string" ? parseInt(filesize, 10) : filesize; if (!total || isNaN(size)) return 0; return (size / total) * 100; } - -function idToHexColor(id: number): string { - const knuthHash = 2654435761; - const hex = ((id * knuthHash) >>> 0).toString(16).padStart(6, "0"); - return `#${hex.slice(0, 6)}`; -} diff --git a/frontend/src/components/Settings/ServerStats/SummaryStats.vue b/frontend/src/components/Settings/ServerStats/SummaryStats.vue index ee787a121..d0fb62552 100644 --- a/frontend/src/components/Settings/ServerStats/SummaryStats.vue +++ b/frontend/src/components/Settings/ServerStats/SummaryStats.vue @@ -17,11 +17,6 @@ const { t } = useI18n();