Skip to content

Commit

Permalink
fix(frontend): modalが正しく閉じられていないのを修正 (misskey-dev#14307)
Browse files Browse the repository at this point in the history
* fix(frontend): modalが正しく閉じられていないのを修正

* Update packages/frontend/src/components/MkSystemWebhookEditor.vue

Co-authored-by: syuilo <[email protected]>

---------

Co-authored-by: syuilo <[email protected]>
  • Loading branch information
kakkokari-gtyih and syuilo authored Jul 27, 2024
1 parent 46d96c7 commit 22c4e9d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 34 deletions.
13 changes: 7 additions & 6 deletions packages/frontend/src/components/MkSystemWebhookEditor.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,23 @@ export type MkSystemWebhookResult = {
};

export async function showSystemWebhookEditorDialog(props: MkSystemWebhookEditorProps): Promise<MkSystemWebhookResult | null> {
const { dispose, result } = await new Promise<{ dispose: () => void, result: MkSystemWebhookResult | null }>(async resolve => {
const { dispose: _dispose } = os.popup(
const { result } = await new Promise<{ result: MkSystemWebhookResult | null }>(async resolve => {
const { dispose } = os.popup(
defineAsyncComponent(() => import('@/components/MkSystemWebhookEditor.vue')),
props,
{
submitted: (ev: MkSystemWebhookResult) => {
resolve({ dispose: _dispose, result: ev });
resolve({ result: ev });
},
canceled: () => {
resolve({ result: null });
},
closed: () => {
resolve({ dispose: _dispose, result: null });
dispose();
},
},
);
});

dispose();

return result;
}
22 changes: 15 additions & 7 deletions packages/frontend/src/components/MkSystemWebhookEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ SPDX-License-Identifier: AGPL-3.0-only

<template>
<MkModalWindow
ref="dialogEl"
:width="450"
:height="590"
:canClose="true"
:withOkButton="false"
:okButtonDisabled="false"
@click="onCancelClicked"
@close="onCancelClicked"
@closed="onCancelClicked"
@closed="emit('closed')"
>
<template #header>
{{ mode === 'create' ? i18n.ts._webhookSettings.createWebhook : i18n.ts._webhookSettings.modifyWebhook }}
Expand Down Expand Up @@ -59,8 +60,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>

<script setup lang="ts">
import { computed, onMounted, ref, toRefs } from 'vue';
import FormSection from '@/components/form/section.vue';
import { computed, onMounted, ref, shallowRef, toRefs } from 'vue';
import MkInput from '@/components/MkInput.vue';
import MkSwitch from '@/components/MkSwitch.vue';
import {
Expand All @@ -82,9 +82,12 @@ type EventType = {
const emit = defineEmits<{
(ev: 'submitted', result: MkSystemWebhookResult): void;
(ev: 'canceled'): void;
(ev: 'closed'): void;
}>();
const dialogEl = shallowRef<InstanceType<typeof MkModalWindow>>();
const props = defineProps<MkSystemWebhookEditorProps>();
const { mode, id, requiredEvents } = toRefs(props);
Expand Down Expand Up @@ -133,12 +136,14 @@ async function onSubmitClicked() {
switch (mode.value) {
case 'create': {
const result = await misskeyApi('admin/system-webhook/create', params);
dialogEl.value?.close();
emit('submitted', result);
break;
}
case 'edit': {
// eslint-disable-next-line
const result = await misskeyApi('admin/system-webhook/update', { id: id.value!, ...params });
dialogEl.value?.close();
emit('submitted', result);
break;
}
Expand All @@ -147,13 +152,15 @@ async function onSubmitClicked() {
} catch (ex: any) {
const msg = ex.message ?? i18n.ts.internalServerErrorDescription;
await os.alert({ type: 'error', title: i18n.ts.error, text: msg });
emit('closed');
dialogEl.value?.close();
emit('canceled');
}
});
}
function onCancelClicked() {
emit('closed');
dialogEl.value?.close();
emit('canceled');
}
async function loadingScope<T>(fn: () => Promise<T>): Promise<T> {
Expand Down Expand Up @@ -183,11 +190,12 @@ onMounted(async () => {
for (const ev of Object.keys(events.value)) {
events.value[ev] = res.on.includes(ev as SystemWebhookEventType);
}
// eslint-disable-next-line
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (ex: any) {
const msg = ex.message ?? i18n.ts.internalServerErrorDescription;
await os.alert({ type: 'error', title: i18n.ts.error, text: msg });
emit('closed');
dialogEl.value?.close();
emit('canceled');
}
break;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/frontend/src/components/MkUserSelectDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { onMounted, ref, shallowRef } from 'vue';
import * as Misskey from 'misskey-js';
import MkInput from '@/components/MkInput.vue';
import FormSplit from '@/components/form/split.vue';
Expand Down Expand Up @@ -91,7 +91,7 @@ const host = ref('');
const users = ref<Misskey.entities.UserLite[]>([]);
const recentUsers = ref<Misskey.entities.UserDetailed[]>([]);
const selected = ref<Misskey.entities.UserLite | null>(null);
const dialogEl = ref();
const dialogEl = shallowRef<InstanceType<typeof MkModalWindow>>();
function search() {
if (username.value === '' && host.value === '') {
Expand Down Expand Up @@ -122,7 +122,7 @@ async function ok() {
});
emit('ok', user);
dialogEl.value.close();
dialogEl.value?.close();
// 最近使ったユーザー更新
let recents = defaultStore.state.recentlyUsedUsers;
Expand All @@ -133,7 +133,7 @@ async function ok() {
function cancel() {
emit('cancel');
dialogEl.value.close();
dialogEl.value?.close();
}
onMounted(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<template>
<MkModalWindow
ref="dialog"
ref="dialogEl"
:width="400"
:height="490"
:withOkButton="false"
Expand Down Expand Up @@ -71,7 +71,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>

<script lang="ts" setup>
import { computed, onMounted, ref, toRefs } from 'vue';
import { computed, onMounted, ref, shallowRef, toRefs } from 'vue';
import { entities } from 'misskey-js';
import MkButton from '@/components/MkButton.vue';
import MkModalWindow from '@/components/MkModalWindow.vue';
Expand All @@ -88,6 +88,7 @@ type NotificationRecipientMethod = 'email' | 'webhook';
const emit = defineEmits<{
(ev: 'submitted'): void;
(ev: 'canceled'): void;
(ev: 'closed'): void;
}>();
Expand All @@ -98,6 +99,8 @@ const props = defineProps<{
const { mode, id } = toRefs(props);
const dialogEl = shallowRef<InstanceType<typeof MkModalWindow>>();
const loading = ref<number>(0);
const title = ref<string>('');
Expand Down Expand Up @@ -166,18 +169,21 @@ async function onSubmitClicked() {
}
}
dialogEl.value?.close();
emit('submitted');
// eslint-disable-next-line
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (ex: any) {
const msg = ex.message ?? i18n.ts.internalServerErrorDescription;
await os.alert({ type: 'error', title: i18n.ts.error, text: msg });
emit('closed');
dialogEl.value?.close();
emit('canceled');
}
});
}
function onCancelClicked() {
emit('closed');
dialogEl.value?.close();
emit('canceled');
}
async function onEditSystemWebhookClicked() {
Expand Down Expand Up @@ -262,7 +268,8 @@ onMounted(async () => {
} catch (ex: any) {
const msg = ex.message ?? i18n.ts.internalServerErrorDescription;
await os.alert({ type: 'error', title: i18n.ts.error, text: msg });
emit('closed');
dialogEl.value?.close();
emit('canceled');
}
} else {
userId.value = moderators.value[0]?.id ?? null;
Expand Down Expand Up @@ -296,11 +303,13 @@ onMounted(async () => {
gap: 8px;
button {
width: 2.5em;
height: 2.5em;
min-width: 2.5em;
min-height: 2.5em;
min-width: 0;
min-height: 0;
width: 34px;
height: 34px;
flex-shrink: 0;
box-sizing: border-box;
margin: 1px 0;
padding: 6px;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,27 @@ async function onDeleteButtonClicked(id: string) {
}
async function showEditor(mode: 'create' | 'edit', id?: string) {
const { dispose, needLoad } = await new Promise<{ dispose: () => void, needLoad: boolean }>(async resolve => {
const { dispose: _dispose } = os.popup(
const { needLoad } = await new Promise<{ needLoad: boolean }>(async resolve => {
const { dispose } = os.popup(
defineAsyncComponent(() => import('./notification-recipient.editor.vue')),
{
mode,
id,
},
{
submitted: async () => {
resolve({ dispose: _dispose, needLoad: true });
submitted: () => {
resolve({ needLoad: true });
},
canceled: () => {
resolve({ needLoad: false });
},
closed: () => {
resolve({ dispose: _dispose, needLoad: false });
dispose();
},
},
);
});
dispose();
if (needLoad) {
await fetchRecipients();
}
Expand Down

0 comments on commit 22c4e9d

Please sign in to comment.