feat(ui): add loading indicator and error handling

This commit is contained in:
2026-08-05 08:29:08 +02:00
parent a63682ced0
commit a0387126de
4 changed files with 22 additions and 15 deletions
@@ -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 };
}