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

@ -459,18 +459,18 @@ export default defineComponent({
os.apiWithDialog('notes/create', {
renoteId: this.appearNote.id
}, undefined, (res: any) => {
os.dialog({
os.alert({
type: 'success',
text: this.$ts.renoted,
});
}, (e: Error) => {
if (e.id === 'b5c90186-4ab0-49c8-9bba-a1f76c282ba4') {
os.dialog({
os.alert({
type: 'error',
text: this.$ts.cantRenote,
});
} else if (e.id === 'fd4cc33e-2a37-48dd-99cc-9b806eb2031a') {
os.dialog({
os.alert({
type: 'error',
text: this.$ts.cantReRenote,
});
@ -513,18 +513,18 @@ export default defineComponent({
os.apiWithDialog('notes/favorites/create', {
noteId: this.appearNote.id
}, undefined, (res: any) => {
os.dialog({
os.alert({
type: 'success',
text: this.$ts.favorited,
});
}, (e: Error) => {
if (e.id === 'a402c12b-34dd-41d2-97d8-4d2ffd96a1a6') {
os.dialog({
os.alert({
type: 'error',
text: this.$ts.alreadyFavorited,
});
} else if (e.id === '6dd26674-e060-4816-909a-45ba3f4da458') {
os.dialog({
os.alert({
type: 'error',
text: this.$ts.cantFavorite,
});
@ -533,10 +533,9 @@ export default defineComponent({
},
del() {
os.dialog({
os.confirm({
type: 'warning',
text: this.$ts.noteDeleteConfirm,
showCancelButton: true
}).then(({ canceled }) => {
if (canceled) return;
@ -547,10 +546,9 @@ export default defineComponent({
},
delEdit() {
os.dialog({
os.confirm({
type: 'warning',
text: this.$ts.deleteAndEditConfirm,
showCancelButton: true
}).then(({ canceled }) => {
if (canceled) return;
@ -770,7 +768,7 @@ export default defineComponent({
noteId: this.appearNote.id
}, undefined, null, e => {
if (e.id === '72dab508-c64d-498f-8740-a8eec1ba385a') {
os.dialog({
os.alert({
type: 'error',
text: this.$ts.pinLimitExceeded
});
@ -817,9 +815,8 @@ export default defineComponent({
},
async promote() {
const { canceled, result: days } = await os.dialog({
const { canceled, result: days } = await os.inputNumber({
title: this.$ts.numberOfDays,
input: { type: 'number' }
});
if (canceled) return;

View File

@ -155,9 +155,8 @@ export default defineComponent({
},
async inChannelSearch() {
const { canceled, result: query } = await os.dialog({
const { canceled, result: query } = await os.inputText({
title: this.$ts.inChannelSearch,
input: true
});
if (canceled || query == null || query === '') return;
router.push(`/search?q=${encodeURIComponent(query)}&channel=${this.channelId}`);

View File

@ -450,10 +450,9 @@ export default defineComponent({
if (!this.renote && !this.quoteId && paste.startsWith(url + '/notes/')) {
e.preventDefault();
os.dialog({
os.confirm({
type: 'info',
text: this.$ts.quoteQuestion,
showCancelButton: true
}).then(({ canceled }) => {
if (canceled) {
insertTextAtCursor(this.$refs.text, paste);
@ -567,7 +566,7 @@ export default defineComponent({
});
}).catch(err => {
this.posting = false;
os.dialog({
os.alert({
type: 'error',
text: err.message + '\n' + (err as any).id,
});

View File

@ -118,15 +118,11 @@ export default defineComponent({
'direct',
];
const { canceled, result: column } = await os.dialog({
const { canceled, result: column } = await os.select({
title: this.$ts._deck.addColumn,
type: null,
select: {
items: columns.map(column => ({
value: column, text: this.$t('_deck._columns.' + column)
}))
},
showCancelButton: true
items: columns.map(column => ({
value: column, text: this.$t('_deck._columns.' + column)
}))
});
if (canceled) return;

View File

@ -52,16 +52,12 @@ export default defineComponent({
methods: {
async setAntenna() {
const antennas = await os.api('antennas/list');
const { canceled, result: antenna } = await os.dialog({
const { canceled, result: antenna } = await os.select({
title: this.$ts.selectAntenna,
type: null,
select: {
items: antennas.map(x => ({
value: x, text: x.name
})),
items: antennas.map(x => ({
value: x, text: x.name
})),
default: this.column.antennaId
},
showCancelButton: true
});
if (canceled) return;
updateColumn(this.column.id, {

View File

@ -52,16 +52,12 @@ export default defineComponent({
methods: {
async setList() {
const lists = await os.api('users/lists/list');
const { canceled, result: list } = await os.dialog({
const { canceled, result: list } = await os.select({
title: this.$ts.selectList,
type: null,
select: {
items: lists.map(x => ({
value: x, text: x.name
})),
default: this.column.listId
},
showCancelButton: true
items: lists.map(x => ({
value: x, text: x.name
})),
default: this.column.listId
});
if (canceled) return;
updateColumn(this.column.id, {

View File

@ -69,20 +69,17 @@ export default defineComponent({
methods: {
async setType() {
const { canceled, result: src } = await os.dialog({
const { canceled, result: src } = await os.select({
title: this.$ts.timeline,
type: null,
select: {
items: [{
value: 'home', text: this.$ts._timelines.home
}, {
value: 'local', text: this.$ts._timelines.local
}, {
value: 'social', text: this.$ts._timelines.social
}, {
value: 'global', text: this.$ts._timelines.global
}]
},
items: [{
value: 'home', text: this.$ts._timelines.home
}, {
value: 'local', text: this.$ts._timelines.local
}, {
value: 'social', text: this.$ts._timelines.social
}, {
value: 'global', text: this.$ts._timelines.global
}]
});
if (canceled) {
if (this.column.tl == null) {