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

@ -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,
});