Skip to content

Commit b47a8ba

Browse files
committed
fix(frontend): sort resources alphabetically
1 parent 117a38f commit b47a8ba

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

frontend/components/ProposeTrade.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const offeredResources = ref<{
3232
amount?: number,
3333
}>({});
3434
35-
async function submitTrade() {
35+
async function submitTrade () {
3636
const trade = {
3737
requestedResources: [requestedResources.value],
3838
offeredResources: [offeredResources.value],

frontend/components/ShowAllResources.vue

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<template>
22
<div>
3-
<template v-if="resources">
4-
<div v-if="resources.length === 0">
3+
<template v-if="sortedResources">
4+
<div v-if="sortedResources.length === 0">
55
No resources found.
66
</div>
7-
<div v-for="resource in resources" v-else :key="resource.type">
7+
<div v-for="resource in sortedResources" v-else :key="resource.type">
88
<p>Type: {{ resource.type }}</p>
99
<p>Amount: {{ resource.amount }}</p>
1010
<p>Upgrade Level: {{ resource.upgradeLevel }}</p>
@@ -20,16 +20,30 @@
2020
<script setup lang="ts">
2121
import { basePath } from '~/utils/api';
2222
23-
const { data: resources, refresh } = await useFetch<Array<{
23+
type Resource = {
2424
ownerId: string, type: string, amount: number, 'upgradeLevel': number
25-
}>>(
25+
}
26+
27+
const { data: resources, refresh } = await useFetch<Array<Resource>>(
2628
basePath + 'resources',
2729
{
2830
lazy: true,
2931
server: false,
3032
},
3133
);
3234
35+
function sortResourceAlphabetically (resourceA: Resource, resourceB: Resource) {
36+
if (resourceA.type < resourceB.type) {
37+
return -1;
38+
}
39+
if (resourceA.type > resourceB.type) {
40+
return 1;
41+
}
42+
return 0;
43+
}
44+
45+
const sortedResources = computed(() => resources.value?.sort(sortResourceAlphabetically));
46+
3347
let stopInterval: NodeJS.Timeout;
3448
3549
onMounted(() => {

frontend/components/ShowOccupation.vue

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
</template>
1616
</UButton>
1717
</div>
18-
1918
</div>
2019
</template>
2120

@@ -34,8 +33,7 @@ const occupationIcon = {
3433
[Occupation.HUNTER]: '🏹',
3534
};
3635
37-
38-
function getOccupationIcon(occupation: Occupation) {
36+
function getOccupationIcon (occupation: Occupation) {
3937
return occupationIcon[occupation];
4038
}
4139
@@ -49,24 +47,24 @@ const { data: occupation, refresh } = await useFetch<Occupation>(
4947
5048
const availableOccupations =
5149
computed(() => Object.values(Occupation)
52-
.filter((availableOccupation) => availableOccupation !== occupation.value));
50+
.filter(availableOccupation => availableOccupation !== occupation.value));
5351
5452
const cantChangeOccupation =
55-
computed(() => chosenOccupation.value === null || chosenOccupation.value === occupation.value)
53+
computed(() => chosenOccupation.value === null || chosenOccupation.value === occupation.value);
5654
57-
const chosenOccupation = ref<null | Occupation>(null)
55+
const chosenOccupation = ref<null | Occupation>(null);
5856
59-
async function changeOccupation() {
57+
async function changeOccupation () {
6058
await useFetch(
6159
basePath + 'occupations',
6260
{
6361
method: 'PUT',
6462
body: {
65-
occupation: chosenOccupation.value
63+
occupation: chosenOccupation.value,
6664
},
6765
lazy: true,
6866
server: false,
69-
}
67+
},
7068
);
7169
7270
chosenOccupation.value = null;

0 commit comments

Comments
 (0)