feat(ui): add loading indicator and error handling
This commit is contained in:
@@ -3,6 +3,8 @@ import { computed, onMounted, ref, watch } from 'vue';
|
||||
import useHistoryViewModel from '../viewmodels/HistoryViewModel';
|
||||
import moment from 'moment';
|
||||
import Chart from '../components/Chart.vue';
|
||||
import Loading from '@/components/Loading.vue';
|
||||
import Error from '@/components/Error.vue';
|
||||
|
||||
const model = useHistoryViewModel();
|
||||
|
||||
@@ -29,5 +31,7 @@ const chartData = computed(
|
||||
|
||||
<template>
|
||||
<input type="date" v-model="date" />
|
||||
<Chart :data="chartData" />
|
||||
<Loading v-if="model.isLoading.value" />
|
||||
<Chart :data="chartData" v-if="chartData" />
|
||||
<Error v-if="model.error.value" :message="model.error.value" />
|
||||
</template>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { create } from 'axios';
|
||||
import { ref } from 'vue';
|
||||
import HistoryData = App.Features.History.Data.HistoryData;
|
||||
import moment from 'moment';
|
||||
|
||||
export default function useHistoryViewModel() {
|
||||
const isLoading = ref<boolean>(false);
|
||||
const error = ref<string>();
|
||||
const historyData = ref<HistoryData>();
|
||||
|
||||
function getHistoryData(date: string) {
|
||||
@@ -18,22 +18,13 @@ export default function useHistoryViewModel() {
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
console.log(
|
||||
res.data?.electricity.flatMap((e) => {
|
||||
if (!e.totalPriceTaxIncluded) {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
label: moment(e.startDate).format('DD-MM-YYYY'),
|
||||
value: e.totalPriceTaxIncluded?.toPrecision(2),
|
||||
};
|
||||
}),
|
||||
);
|
||||
historyData.value = res.data;
|
||||
})
|
||||
.catch((err) => {
|
||||
error.value = err.response.data.message;
|
||||
})
|
||||
.finally(() => (isLoading.value = false));
|
||||
}
|
||||
|
||||
return { isLoading, historyData, getHistoryData };
|
||||
return { isLoading, historyData, error, getHistoryData };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user