Skip to content

Commit

Permalink
fix(frontend): sort resources alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
maybeanerd committed Jul 24, 2024
1 parent 117a38f commit b47a8ba
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion frontend/components/ProposeTrade.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const offeredResources = ref<{
amount?: number,
}>({});
async function submitTrade() {
async function submitTrade () {
const trade = {
requestedResources: [requestedResources.value],
offeredResources: [offeredResources.value],
Expand Down
24 changes: 19 additions & 5 deletions frontend/components/ShowAllResources.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<div>
<template v-if="resources">
<div v-if="resources.length === 0">
<template v-if="sortedResources">
<div v-if="sortedResources.length === 0">
No resources found.
</div>
<div v-for="resource in resources" v-else :key="resource.type">
<div v-for="resource in sortedResources" v-else :key="resource.type">
<p>Type: {{ resource.type }}</p>
<p>Amount: {{ resource.amount }}</p>
<p>Upgrade Level: {{ resource.upgradeLevel }}</p>
Expand All @@ -20,16 +20,30 @@
<script setup lang="ts">
import { basePath } from '~/utils/api';
const { data: resources, refresh } = await useFetch<Array<{
type Resource = {
ownerId: string, type: string, amount: number, 'upgradeLevel': number
}>>(
}
const { data: resources, refresh } = await useFetch<Array<Resource>>(
basePath + 'resources',
{
lazy: true,
server: false,
},
);
function sortResourceAlphabetically (resourceA: Resource, resourceB: Resource) {
if (resourceA.type < resourceB.type) {
return -1;
}
if (resourceA.type > resourceB.type) {
return 1;
}
return 0;
}
const sortedResources = computed(() => resources.value?.sort(sortResourceAlphabetically));
let stopInterval: NodeJS.Timeout;
onMounted(() => {
Expand Down
16 changes: 7 additions & 9 deletions frontend/components/ShowOccupation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
</template>
</UButton>
</div>

</div>
</template>

Expand All @@ -34,8 +33,7 @@ const occupationIcon = {
[Occupation.HUNTER]: '🏹',
};
function getOccupationIcon(occupation: Occupation) {
function getOccupationIcon (occupation: Occupation) {
return occupationIcon[occupation];
}
Expand All @@ -49,24 +47,24 @@ const { data: occupation, refresh } = await useFetch<Occupation>(
const availableOccupations =
computed(() => Object.values(Occupation)
.filter((availableOccupation) => availableOccupation !== occupation.value));
.filter(availableOccupation => availableOccupation !== occupation.value));
const cantChangeOccupation =
computed(() => chosenOccupation.value === null || chosenOccupation.value === occupation.value)
computed(() => chosenOccupation.value === null || chosenOccupation.value === occupation.value);
const chosenOccupation = ref<null | Occupation>(null)
const chosenOccupation = ref<null | Occupation>(null);
async function changeOccupation() {
async function changeOccupation () {
await useFetch(
basePath + 'occupations',
{
method: 'PUT',
body: {
occupation: chosenOccupation.value
occupation: chosenOccupation.value,
},
lazy: true,
server: false,
}
},
);
chosenOccupation.value = null;
Expand Down

0 comments on commit b47a8ba

Please sign in to comment.