feat(ui): add loading indicator and error handling
This commit is contained in:
@@ -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