refactor(client): refactor dialog functions to improve type inference

This commit is contained in:
syuilo
2021-11-18 18:45:58 +09:00
parent 63415f1074
commit ea9aeef9d8
84 changed files with 415 additions and 460 deletions

View File

@ -9,16 +9,15 @@ export function createAiScriptEnv(opts) {
USER_NAME: $i ? values.STR($i.name) : values.NULL,
USER_USERNAME: $i ? values.STR($i.username) : values.NULL,
'Mk:dialog': values.FN_NATIVE(async ([title, text, type]) => {
await os.dialog({
await os.alert({
type: type ? type.value : 'info',
title: title.value,
text: text.value,
});
}),
'Mk:confirm': values.FN_NATIVE(async ([title, text, type]) => {
const confirm = await os.dialog({
const confirm = await os.confirm({
type: type ? type.value : 'question',
showCancelButton: true,
title: title.value,
text: text.value,
});

View File

@ -14,21 +14,17 @@ export function getUserMenu(user) {
const t = i18n.locale.selectList; // なぜか後で参照すると null になるので最初にメモリに確保しておく
const lists = await os.api('users/lists/list');
if (lists.length === 0) {
os.dialog({
os.alert({
type: 'error',
text: i18n.locale.youHaveNoLists
});
return;
}
const { canceled, result: listId } = await os.dialog({
type: null,
const { canceled, result: listId } = await os.select({
title: t,
select: {
items: lists.map(list => ({
value: list.id, text: list.name
}))
},
showCancelButton: true
items: lists.map(list => ({
value: list.id, text: list.name
}))
});
if (canceled) return;
os.apiWithDialog('users/lists/push', {
@ -40,21 +36,17 @@ export function getUserMenu(user) {
async function inviteGroup() {
const groups = await os.api('users/groups/owned');
if (groups.length === 0) {
os.dialog({
os.alert({
type: 'error',
text: i18n.locale.youHaveNoGroups
});
return;
}
const { canceled, result: groupId } = await os.dialog({
type: null,
const { canceled, result: groupId } = await os.select({
title: i18n.locale.group,
select: {
items: groups.map(group => ({
value: group.id, text: group.name
}))
},
showCancelButton: true
items: groups.map(group => ({
value: group.id, text: group.name
}))
});
if (canceled) return;
os.apiWithDialog('users/groups/invite', {
@ -108,9 +100,8 @@ export function getUserMenu(user) {
}
async function getConfirmed(text: string): Promise<boolean> {
const confirm = await os.dialog({
const confirm = await os.confirm({
type: 'warning',
showCancelButton: true,
title: 'confirm',
text,
});

View File

@ -39,9 +39,8 @@ export class Hpml {
}), ...initAiLib(this)}, {
in: (q) => {
return new Promise(ok => {
os.dialog({
os.inputText({
title: q,
input: {}
}).then(({ canceled, result: a }) => {
ok(a);
});

View File

@ -3,9 +3,8 @@ import { i18n } from '@/i18n';
import * as os from '@/os';
export async function lookupUser() {
const { canceled, result } = await os.dialog({
const { canceled, result } = await os.inputText({
title: i18n.locale.usernameOrUserId,
input: true
});
if (canceled) return;
@ -18,7 +17,7 @@ export async function lookupUser() {
let _notFound = false;
const notFound = () => {
if (_notFound) {
os.dialog({
os.alert({
type: 'error',
text: i18n.locale.noSuchUser
});

View File

@ -3,9 +3,8 @@ import { i18n } from '@/i18n';
import { router } from '@/router';
export async function search() {
const { canceled, result: query } = await os.dialog({
const { canceled, result: query } = await os.inputText({
title: i18n.locale.search,
input: true
});
if (canceled || query == null || query === '') return;
@ -35,7 +34,7 @@ export async function search() {
// TODO
//v.$root.$emit('warp', date);
os.dialog({
os.alert({
icon: 'fas fa-history',
iconOnly: true, autoClose: true
});

View File

@ -14,7 +14,7 @@ export function selectFile(src: any, label: string | null, multiple = false) {
Promise.all(promises).then(driveFiles => {
res(multiple ? driveFiles : driveFiles[0]);
}).catch(e => {
os.dialog({
os.alert({
type: 'error',
text: e
});
@ -38,11 +38,10 @@ export function selectFile(src: any, label: string | null, multiple = false) {
};
const chooseFileFromUrl = () => {
os.dialog({
os.inputText({
title: i18n.locale.uploadFromUrl,
input: {
placeholder: i18n.locale.uploadFromUrlDescription
}
type: 'url',
placeholder: i18n.locale.uploadFromUrlDescription
}).then(({ canceled, result: url }) => {
if (canceled) return;
@ -62,7 +61,7 @@ export function selectFile(src: any, label: string | null, multiple = false) {
marker
});
os.dialog({
os.alert({
title: i18n.locale.uploadFromUrlRequested,
text: i18n.locale.uploadFromUrlMayTakeTime
});

View File

@ -2,7 +2,7 @@ import * as os from '@/os';
import { i18n } from '@/i18n';
export function showSuspendedDialog() {
return os.dialog({
return os.alert({
type: 'error',
title: i18n.locale.yourAccountSuspendedTitle,
text: i18n.locale.yourAccountSuspendedDescription