mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-04 09:35:51 +02:00
enhance(frontend): 非同期的なコンポーネントの読み込み時のハンドリングを強化
This commit is contained in:
@@ -206,6 +206,52 @@ export function popup<T extends Component>(
|
||||
};
|
||||
}
|
||||
|
||||
export async function popupAsyncWithDialog<T extends Component>(
|
||||
componentFetching: Promise<T>,
|
||||
props: ComponentProps<T>,
|
||||
events: Partial<ComponentEmit<T>> = {},
|
||||
): Promise<{ dispose: () => void }> {
|
||||
const closeWaiting = waiting();
|
||||
|
||||
let component: T;
|
||||
|
||||
try {
|
||||
component = await componentFetching;
|
||||
} catch (err) {
|
||||
closeWaiting();
|
||||
alert({
|
||||
type: 'error',
|
||||
title: i18n.ts.somethingHappened,
|
||||
text: 'CODE: ASYNC_COMP_LOAD_FAIL',
|
||||
});
|
||||
throw err;
|
||||
}
|
||||
|
||||
closeWaiting();
|
||||
|
||||
markRaw(component);
|
||||
|
||||
const id = ++popupIdCount;
|
||||
const dispose = () => {
|
||||
// このsetTimeoutが無いと挙動がおかしくなる(autocompleteが閉じなくなる)。Vueのバグ?
|
||||
window.setTimeout(() => {
|
||||
popups.value = popups.value.filter(p => p.id !== id);
|
||||
}, 0);
|
||||
};
|
||||
const state = {
|
||||
component,
|
||||
props,
|
||||
events,
|
||||
id,
|
||||
};
|
||||
|
||||
popups.value.push(state);
|
||||
|
||||
return {
|
||||
dispose,
|
||||
};
|
||||
}
|
||||
|
||||
export function pageWindow(path: string) {
|
||||
const { dispose } = popup(MkPageWindow, {
|
||||
initialPath: path,
|
||||
@@ -787,9 +833,9 @@ export function launchUploader(
|
||||
multiple?: boolean;
|
||||
},
|
||||
): Promise<Misskey.entities.DriveFile[]> {
|
||||
return new Promise((res, rej) => {
|
||||
return new Promise(async (res, rej) => {
|
||||
if (files.length === 0) return rej();
|
||||
const { dispose } = popup(defineAsyncComponent(() => import('@/components/MkUploaderDialog.vue')), {
|
||||
const { dispose } = await popupAsyncWithDialog(import('@/components/MkUploaderDialog.vue').then(x => x.default), {
|
||||
files: markRaw(files),
|
||||
folderId: options?.folderId,
|
||||
multiple: options?.multiple,
|
||||
|
||||
Reference in New Issue
Block a user