1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-20 04:45:31 +02:00

refactor(frontend): use* 関数の格納場所のフォルダ名を composables に変更 (#16004)

* refactor(frontend): use* 関数の格納場所を正式名称(composables)に変更

* migrate

* move useLoading
This commit is contained in:
かっこかり
2025-05-10 07:58:26 +09:00
committed by GitHub
parent c803f842ba
commit e1cd7c94fb
57 changed files with 53 additions and 53 deletions

View File

@@ -0,0 +1,52 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { computed, h, ref } from 'vue';
import MkLoading from '@/components/global/MkLoading.vue';
export const useLoading = (props?: {
static?: boolean;
inline?: boolean;
colored?: boolean;
mini?: boolean;
em?: boolean;
}) => {
const showingCnt = ref(0);
const show = () => {
showingCnt.value++;
};
const close = (force?: boolean) => {
if (force) {
showingCnt.value = 0;
} else {
showingCnt.value = Math.max(0, showingCnt.value - 1);
}
};
const scope = <T>(fn: () => T) => {
show();
const result = fn();
if (result instanceof Promise) {
return result.finally(() => close());
} else {
close();
return result;
}
};
const showing = computed(() => showingCnt.value > 0);
const component = computed(() => showing.value ? h(MkLoading, props) : null);
return {
show,
close,
scope,
component,
showing,
};
};