Skip to content

Commit 7bbd30b

Browse files
committed
Category Names
1 parent f763d14 commit 7bbd30b

7 files changed

Lines changed: 81 additions & 76 deletions

File tree

app/components/DynamicTable.vue

Lines changed: 0 additions & 43 deletions
This file was deleted.

app/components/FilterPanel.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script setup lang="ts">
22
import type { FilterConfig } from "~/composables/useDataTable";
33
4+
const { t } = useI18n();
5+
46
defineProps<{
57
filters: FilterConfig[];
68
maxPage?: number;
@@ -23,7 +25,7 @@ function emitPageUpdate(value: number) {
2325
<label
2426
class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-2 block"
2527
>
26-
Page
28+
{{ t("filters.page") }}
2729
</label>
2830
<UInputNumber
2931
v-model="pageValue"
@@ -50,7 +52,7 @@ function emitPageUpdate(value: number) {
5052
<UInput
5153
v-else-if="filter.type === 'input'"
5254
v-model="filter.modelValue.value as string"
53-
placeholder="Enter value..."
55+
:placeholder="t('filters.enterValue')"
5456
/>
5557
</div>
5658
</div>

app/pages/index.vue

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,33 @@ const [categoriesRes, itemsRes, playersRes] = await Promise.all([
1111
api.players(),
1212
]);
1313
14-
const categories = withNoneOption(categoriesRes.data);
15-
const items = withNoneOption(itemsRes.data);
16-
const players = withNoneOption(playersRes.data);
14+
const categories = withNoneOption(categoriesRes.data, t("common.none"));
15+
const items = withNoneOption(itemsRes.data, t("common.none"));
16+
const players = withNoneOption(playersRes.data, t("common.none"));
1717
18-
const selectedCategory = ref(getDefaultNone(categories));
19-
const selectedItem = ref(getDefaultNone(items));
20-
const selectedPlayer = ref(getDefaultNone(players));
18+
const selectedCategory = ref(getDefaultNone(categories, t("common.none")));
19+
const selectedItem = ref(getDefaultNone(items, t("common.none")));
20+
const selectedPlayer = ref(getDefaultNone(players, t("common.none")));
2121
22-
const { data, page, maxPage, isLoading, error, filters } = useDataTable({
22+
const { data, page, maxPage, filters } = useDataTable({
2323
filters: [
2424
{
2525
key: "player",
26-
label: "Player",
26+
label: t("filters.player"),
2727
type: "select",
2828
items: players,
2929
modelValue: selectedPlayer,
3030
},
3131
{
3232
key: "category",
33-
label: "Category",
33+
label: t("filters.category"),
3434
type: "select",
3535
items: categories,
3636
modelValue: selectedCategory,
3737
},
3838
{
3939
key: "item",
40-
label: "Item",
40+
label: t("filters.item"),
4141
type: "select",
4242
items: items,
4343
modelValue: selectedItem,
@@ -67,8 +67,13 @@ const columns = computed(() => [
6767
header: t("stats.player"),
6868
},
6969
{
70-
accessorFn: (row) =>
71-
transformer.getCategoryNameById(row.statCategoriesId as number),
70+
accessorFn: (row) => {
71+
const categoryName = transformer.getCategoryNameById(
72+
row.statCategoriesId as number,
73+
);
74+
const translated = t(`categories.${categoryName}`) || categoryName;
75+
return translated;
76+
},
7277
header: t("stats.category"),
7378
},
7479
{
@@ -91,12 +96,7 @@ function handlePageUpdate(newPage: number) {
9196
<UContainer>
9297
<TableHeader :title="t('stats.title')" />
9398

94-
<DynamicTable
95-
:data="data as any"
96-
:columns="columns"
97-
:is-loading="isLoading"
98-
:error="error"
99-
>
99+
<UTable :data="data" :columns="columns">
100100
<template #playerName-cell="{ cell }">
101101
<div class="flex items-center gap-3">
102102
<img
@@ -106,13 +106,7 @@ function handlePageUpdate(newPage: number) {
106106
<span>{{ cell.getValue() }}</span>
107107
</div>
108108
</template>
109-
110-
<template #value-cell="{ cell }">
111-
<span class="font-mono font-semibold">
112-
{{ cell.getValue() }}
113-
</span>
114-
</template>
115-
</DynamicTable>
109+
</UTable>
116110
</UContainer>
117111

118112
<ClientOnly>

app/utils/selectWithNone.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
export function withNoneOption<T extends { name: string }>(items: T[]) {
2-
return [{ id: -1, name: "None" } as unknown as T, ...items];
1+
export function withNoneOption<T extends { name: string }>(
2+
items: T[],
3+
noneLabel: string,
4+
) {
5+
return [{ id: -1, name: noneLabel } as unknown as T, ...items];
36
}
47

5-
export function getDefaultNone<T extends { name: string }>(items: T[]) {
6-
return items.find((i) => i.name === "None") ?? null;
8+
export function getDefaultNone<T extends { name: string }>(
9+
items: T[],
10+
noneLabel: string,
11+
) {
12+
return items.find((i) => i.name === noneLabel) ?? null;
713
}

docker-compose.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ services:
88
environment:
99
- HOST=0.0.0.0
1010
- PORT=3000
11-
- NITRO_HOST=0.0.0.0
12-
- NITRO_PORT=3000
1311
- NUXT_PUBLIC_API_URL=http://0.0.0.0:2456
1412
restart: unless-stopped
1513
depends_on:

i18n/locales/en.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,29 @@
55
"category": "Category",
66
"type": "Type",
77
"value": "Value"
8+
},
9+
"filters": {
10+
"player": "Player",
11+
"category": "Category",
12+
"item": "Item",
13+
"page": "Page",
14+
"enterValue": "Enter value..."
15+
},
16+
"common": {
17+
"none": "None"
18+
},
19+
"errors": {
20+
"fetchFailed": "Failed to fetch data"
21+
},
22+
"categories": {
23+
"minecraft:picked_up": "Picked up",
24+
"minecraft:custom": "Other",
25+
"minecraft:broken": "Broken",
26+
"minecraft:mined": "Mined",
27+
"minecraft:dropped": "Dropped",
28+
"minecraft:crafted": "Crafted",
29+
"minecraft:killed_by": "Killed By",
30+
"minecraft:killed": "Killed",
31+
"minecraft:used": "Used"
832
}
933
}

i18n/locales/sv.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,29 @@
55
"category": "Kategori",
66
"type": "Typ",
77
"value": "Värde"
8+
},
9+
"filters": {
10+
"player": "Spelare",
11+
"category": "Kategori",
12+
"item": "Föremål",
13+
"page": "Sida",
14+
"enterValue": "Ange värde..."
15+
},
16+
"common": {
17+
"none": "Ingen"
18+
},
19+
"errors": {
20+
"fetchFailed": "Misslyckades hämta data"
21+
},
22+
"categories": {
23+
"minecraft:picked_up": "Plockat upp",
24+
"minecraft:custom": "Annat",
25+
"minecraft:broken": "Använt sönder",
26+
"minecraft:mined": "Brutit",
27+
"minecraft:dropped": "Kastat",
28+
"minecraft:crafted": "Tillverkat",
29+
"minecraft:killed_by": "Dödats av",
30+
"minecraft:killed": "Dödat",
31+
"minecraft:used": "Använt"
832
}
933
}

0 commit comments

Comments
 (0)