2021-11-28 12:07:37 +01:00
|
|
|
<template>
|
2022-01-25 15:18:21 +01:00
|
|
|
<transition :name="$store.state.animation ? 'fade' : ''" mode="out-in">
|
2021-11-28 12:07:37 +01:00
|
|
|
<div v-if="pending">
|
|
|
|
<MkLoading/>
|
|
|
|
</div>
|
|
|
|
<div v-else-if="resolved">
|
|
|
|
<slot :result="result"></slot>
|
|
|
|
</div>
|
|
|
|
<div v-else>
|
|
|
|
<div class="wszdbhzo">
|
2022-11-10 23:12:44 +01:00
|
|
|
<div><i class="ph-warning-bold ph-lg"></i> {{ i18n.ts.somethingHappened }}</div>
|
|
|
|
<MkButton inline class="retry" @click="retry"><i class="ph-arrow-clockwise-bold ph-lg"></i> {{ i18n.ts.retry }}</MkButton>
|
2021-11-28 12:07:37 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent, PropType, ref, watch } from 'vue';
|
2022-09-06 11:21:49 +02:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2022-11-10 23:12:44 +01:00
|
|
|
import { i18n } from '@/i18n';
|
2021-11-28 12:07:37 +01:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
2022-11-15 20:47:30 +01:00
|
|
|
MkButton,
|
2021-11-28 12:07:37 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
p: {
|
|
|
|
type: Function as PropType<() => Promise<any>>,
|
|
|
|
required: true,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setup(props, context) {
|
|
|
|
const pending = ref(true);
|
|
|
|
const resolved = ref(false);
|
|
|
|
const rejected = ref(false);
|
|
|
|
const result = ref(null);
|
|
|
|
|
|
|
|
const process = () => {
|
|
|
|
if (props.p == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const promise = props.p();
|
|
|
|
pending.value = true;
|
|
|
|
resolved.value = false;
|
|
|
|
rejected.value = false;
|
|
|
|
promise.then((_result) => {
|
|
|
|
pending.value = false;
|
|
|
|
resolved.value = true;
|
|
|
|
result.value = _result;
|
|
|
|
});
|
|
|
|
promise.catch(() => {
|
|
|
|
pending.value = false;
|
|
|
|
rejected.value = true;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
watch(() => props.p, () => {
|
|
|
|
process();
|
|
|
|
}, {
|
2022-11-15 20:47:30 +01:00
|
|
|
immediate: true,
|
2021-11-28 12:07:37 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
const retry = () => {
|
|
|
|
process();
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
pending,
|
|
|
|
resolved,
|
|
|
|
rejected,
|
|
|
|
result,
|
|
|
|
retry,
|
2022-11-15 20:47:30 +01:00
|
|
|
i18n,
|
2021-11-28 12:07:37 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.fade-enter-active,
|
|
|
|
.fade-leave-active {
|
|
|
|
transition: opacity 0.125s ease;
|
|
|
|
}
|
|
|
|
.fade-enter-from,
|
|
|
|
.fade-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.wszdbhzo {
|
|
|
|
padding: 16px;
|
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
> .retry {
|
|
|
|
margin-top: 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|