refactor (client): await asynchronous processes, remove duplicate code
This commit is contained in:
parent
db0bd21edc
commit
2267e90d3b
1 changed files with 35 additions and 64 deletions
|
@ -309,6 +309,8 @@ import XNoteSimple from "@/components/MkNoteSimple.vue";
|
||||||
import XNotePreview from "@/components/MkNotePreview.vue";
|
import XNotePreview from "@/components/MkNotePreview.vue";
|
||||||
import XPostFormAttaches from "@/components/MkPostFormAttaches.vue";
|
import XPostFormAttaches from "@/components/MkPostFormAttaches.vue";
|
||||||
import XPollEditor from "@/components/MkPollEditor.vue";
|
import XPollEditor from "@/components/MkPollEditor.vue";
|
||||||
|
import XCheatSheet from "@/components/MkCheatSheetDialog.vue";
|
||||||
|
import XMediaCaption from "@/components/MkMediaCaption.vue";
|
||||||
import { host, url } from "@/config";
|
import { host, url } from "@/config";
|
||||||
import { erase, unique } from "@/scripts/array";
|
import { erase, unique } from "@/scripts/array";
|
||||||
import { extractMentions } from "@/scripts/extract-mentions";
|
import { extractMentions } from "@/scripts/extract-mentions";
|
||||||
|
@ -325,7 +327,6 @@ import { getAccounts, openAccountMenu as openAccountMenu_ } from "@/account";
|
||||||
import { me } from "@/me";
|
import { me } from "@/me";
|
||||||
import { uploadFile } from "@/scripts/upload";
|
import { uploadFile } from "@/scripts/upload";
|
||||||
import { deepClone } from "@/scripts/clone";
|
import { deepClone } from "@/scripts/clone";
|
||||||
import XCheatSheet from "@/components/MkCheatSheetDialog.vue";
|
|
||||||
import preprocess from "@/scripts/preprocess";
|
import preprocess from "@/scripts/preprocess";
|
||||||
import { vibrate } from "@/scripts/vibrate";
|
import { vibrate } from "@/scripts/vibrate";
|
||||||
import { langmap } from "@/scripts/langmap";
|
import { langmap } from "@/scripts/langmap";
|
||||||
|
@ -500,7 +501,7 @@ const withHashtags = computed(
|
||||||
);
|
);
|
||||||
const hashtags = computed(defaultStore.makeGetterSetter("postFormHashtags"));
|
const hashtags = computed(defaultStore.makeGetterSetter("postFormHashtags"));
|
||||||
|
|
||||||
let firstTryPost = true;
|
let isFirstPostAttempt = true;
|
||||||
|
|
||||||
watch(text, () => {
|
watch(text, () => {
|
||||||
checkMissingMention();
|
checkMissingMention();
|
||||||
|
@ -1012,6 +1013,34 @@ function deleteDraft() {
|
||||||
localStorage.setItem("drafts", JSON.stringify(draftData));
|
localStorage.setItem("drafts", JSON.stringify(draftData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function openFileDescriptionWindow(file: DriveFile) {
|
||||||
|
await os.popup(
|
||||||
|
XMediaCaption,
|
||||||
|
{
|
||||||
|
title: i18n.ts.describeFile,
|
||||||
|
input: {
|
||||||
|
placeholder: i18n.ts.inputNewDescription,
|
||||||
|
default: file.comment !== null ? file.comment : "",
|
||||||
|
},
|
||||||
|
image: file,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
done: (result) => {
|
||||||
|
if (!result || result.canceled) return;
|
||||||
|
const comment =
|
||||||
|
result.result.length === 0 ? null : result.result;
|
||||||
|
os.api("drive/files/update", {
|
||||||
|
fileId: file.id,
|
||||||
|
comment,
|
||||||
|
}).then(() => {
|
||||||
|
file.comment = comment;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"closed",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async function post() {
|
async function post() {
|
||||||
// For text that is too short, the false positive rate may be too high, so we don't show alarm.
|
// For text that is too short, the false positive rate may be too high, so we don't show alarm.
|
||||||
if (defaultStore.state.autocorrectNoteLanguage && text.value.length > 10) {
|
if (defaultStore.state.autocorrectNoteLanguage && text.value.length > 10) {
|
||||||
|
@ -1050,42 +1079,13 @@ async function post() {
|
||||||
defaultStore.state.showNoAltTextWarning &&
|
defaultStore.state.showNoAltTextWarning &&
|
||||||
files.value.some((f) => f.comment == null || f.comment.length === 0)
|
files.value.some((f) => f.comment == null || f.comment.length === 0)
|
||||||
) {
|
) {
|
||||||
if (firstTryPost) {
|
if (isFirstPostAttempt) {
|
||||||
for (const file of files.value) {
|
for (const file of files.value) {
|
||||||
if (file.comment == null || file.comment.length === 0) {
|
if (file.comment == null || file.comment.length === 0) {
|
||||||
os.popup(
|
await openFileDescriptionWindow(file);
|
||||||
defineAsyncComponent(
|
|
||||||
() => import("@/components/MkMediaCaption.vue"),
|
|
||||||
),
|
|
||||||
{
|
|
||||||
title: i18n.ts.describeFile,
|
|
||||||
input: {
|
|
||||||
placeholder: i18n.ts.inputNewDescription,
|
|
||||||
default:
|
|
||||||
file.comment !== null ? file.comment : "",
|
|
||||||
},
|
|
||||||
image: file,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
done: (result) => {
|
|
||||||
if (!result || result.canceled) return;
|
|
||||||
const comment =
|
|
||||||
result.result.length === 0
|
|
||||||
? null
|
|
||||||
: result.result;
|
|
||||||
os.api("drive/files/update", {
|
|
||||||
fileId: file.id,
|
|
||||||
comment,
|
|
||||||
}).then(() => {
|
|
||||||
file.comment = comment;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"closed",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
firstTryPost = false;
|
isFirstPostAttempt = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1101,36 +1101,7 @@ async function post() {
|
||||||
if (!canceled) {
|
if (!canceled) {
|
||||||
for (const file of files.value) {
|
for (const file of files.value) {
|
||||||
if (file.comment == null || file.comment.length === 0) {
|
if (file.comment == null || file.comment.length === 0) {
|
||||||
os.popup(
|
await openFileDescriptionWindow(file);
|
||||||
defineAsyncComponent(
|
|
||||||
() => import("@/components/MkMediaCaption.vue"),
|
|
||||||
),
|
|
||||||
{
|
|
||||||
title: i18n.ts.describeFile,
|
|
||||||
input: {
|
|
||||||
placeholder: i18n.ts.inputNewDescription,
|
|
||||||
default:
|
|
||||||
file.comment !== null ? file.comment : "",
|
|
||||||
},
|
|
||||||
image: file,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
done: (result) => {
|
|
||||||
if (!result || result.canceled) return;
|
|
||||||
const comment =
|
|
||||||
result.result.length === 0
|
|
||||||
? null
|
|
||||||
: result.result;
|
|
||||||
os.api("drive/files/update", {
|
|
||||||
fileId: file.id,
|
|
||||||
comment,
|
|
||||||
}).then(() => {
|
|
||||||
file.comment = comment;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"closed",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue