mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-22 14:56:31 +00:00
33 lines
699 B
TypeScript
33 lines
699 B
TypeScript
|
import { WritableComputedRef } from "vue";
|
||
|
|
||
|
export function useMinLoader(ms = 500): WritableComputedRef<boolean> {
|
||
|
const loading = ref(false);
|
||
|
|
||
|
const locked = ref(false);
|
||
|
|
||
|
const minLoading = computed({
|
||
|
get: () => loading.value,
|
||
|
set: value => {
|
||
|
if (value) {
|
||
|
loading.value = true;
|
||
|
|
||
|
if (!locked.value) {
|
||
|
locked.value = true;
|
||
|
setTimeout(() => {
|
||
|
locked.value = false;
|
||
|
}, ms);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!value && !locked.value) {
|
||
|
loading.value = false;
|
||
|
} else if (!value && locked.value) {
|
||
|
setTimeout(() => {
|
||
|
loading.value = false;
|
||
|
}, ms);
|
||
|
}
|
||
|
},
|
||
|
});
|
||
|
return minLoading;
|
||
|
}
|