feat: add showAddFileDescriptionAtFirstPost and allow cancel adding alt-text midway

This commit is contained in:
老周部落 2024-03-25 22:52:37 +08:00
parent 2267e90d3b
commit f346d2e2f6
No known key found for this signature in database
GPG Key ID: C72181CD85C6B738
6 changed files with 71 additions and 29 deletions

View File

@ -1226,6 +1226,8 @@ publishTimelinesDescription: "If enabled, the Local and Global timelines will be
on {url} even when signed out." on {url} even when signed out."
noAltTextWarning: "Some attached file(s) have no description. Did you forget to write?" noAltTextWarning: "Some attached file(s) have no description. Did you forget to write?"
showNoAltTextWarning: "Show a warning if you attempt to post files without a description" showNoAltTextWarning: "Show a warning if you attempt to post files without a description"
showAddFileDescriptionAtFirstPost: "Show add description page automatically when
first try to post a post attachment without a description"
_emojiModPerm: _emojiModPerm:
unauthorized: "None" unauthorized: "None"

View File

@ -2058,5 +2058,6 @@ searchRangeDescription: "如果您要过滤时间段,请按以下格式输入
messagingUnencryptedInfo: "Firefish 上的聊天没有经过端到端加密,请不要在聊天中分享您的敏感信息。" messagingUnencryptedInfo: "Firefish 上的聊天没有经过端到端加密,请不要在聊天中分享您的敏感信息。"
noAltTextWarning: 有些附件没有描述。您是否忘记写描述了? noAltTextWarning: 有些附件没有描述。您是否忘记写描述了?
showNoAltTextWarning: 当您尝试发布没有描述的帖子附件时显示警告 showNoAltTextWarning: 当您尝试发布没有描述的帖子附件时显示警告
showAddFileDescriptionAtFirstPost: 当您首次尝试发布没有描述的帖子附件时自动弹出添加描述页面
autocorrectNoteLanguage: 当帖子语言不符合自动检测的结果的时候显示警告 autocorrectNoteLanguage: 当帖子语言不符合自动检测的结果的时候显示警告
incorrectLanguageWarning: "看上去您帖子使用的语言是{detected},但您选择的语言是{current}。\n要改为以{detected}发帖吗?" incorrectLanguageWarning: "看上去您帖子使用的语言是{detected},但您选择的语言是{current}。\n要改为以{detected}发帖吗?"

View File

@ -1013,32 +1013,43 @@ function deleteDraft() {
localStorage.setItem("drafts", JSON.stringify(draftData)); localStorage.setItem("drafts", JSON.stringify(draftData));
} }
async function openFileDescriptionWindow(file: DriveFile) { /**
await os.popup( * @returns whether the file is described
XMediaCaption, */
{ function openFileDescriptionWindow(file: entities.DriveFile) {
title: i18n.ts.describeFile, return new Promise<boolean>((resolve, reject) => {
input: { os.popup(
placeholder: i18n.ts.inputNewDescription, XMediaCaption,
default: file.comment !== null ? file.comment : "", {
title: i18n.ts.describeFile,
input: {
placeholder: i18n.ts.inputNewDescription,
default: file.comment !== null ? file.comment : "",
},
image: file,
}, },
image: file, {
}, done: (result) => {
{ if (!result || result.canceled) {
done: (result) => { resolve(false);
if (!result || result.canceled) return; return;
const comment = }
result.result.length === 0 ? null : result.result; const comment =
os.api("drive/files/update", { result.result.length === 0 ? null : result.result;
fileId: file.id, os.api("drive/files/update", {
comment, fileId: file.id,
}).then(() => { comment,
file.comment = comment; }).then(() => {
}); resolve(true);
file.comment = comment;
}).catch((err: unknown) => {
reject(err);
});
},
}, },
}, "closed",
"closed", );
); })
} }
async function post() { async function post() {
@ -1076,19 +1087,30 @@ async function post() {
} }
if ( if (
defaultStore.state.showNoAltTextWarning && defaultStore.state.showAddFileDescriptionAtFirstPost &&
files.value.some((f) => f.comment == null || f.comment.length === 0) files.value.some((f) => f.comment == null || f.comment.length === 0)
) { ) {
if (isFirstPostAttempt) { 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) {
await openFileDescriptionWindow(file); const described = await openFileDescriptionWindow(file);
if (!described) {
return;
}
} }
} }
isFirstPostAttempt = false; isFirstPostAttempt = false;
return; // Continue if all files have alt-text added.
if (files.value.some((f) => f.comment == null || f.comment.length === 0)) {
return;
}
} }
}
if (
defaultStore.state.showNoAltTextWarning &&
files.value.some((f) => f.comment == null || f.comment.length === 0)
) {
// "canceled" means "post anyway" // "canceled" means "post anyway"
const { canceled } = await os.confirm({ const { canceled } = await os.confirm({
type: "warning", type: "warning",
@ -1101,10 +1123,16 @@ 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) {
await openFileDescriptionWindow(file); const described = await openFileDescriptionWindow(file);
if (!described) {
return;
}
} }
} }
return; // Continue if all files have alt-text added.
if (files.value.some((f) => f.comment == null || f.comment.length === 0)) {
return;
}
} }
} }

View File

@ -124,6 +124,9 @@
<FormSwitch v-model="showNoAltTextWarning" class="_formBlock">{{ <FormSwitch v-model="showNoAltTextWarning" class="_formBlock">{{
i18n.ts.showNoAltTextWarning i18n.ts.showNoAltTextWarning
}}</FormSwitch> }}</FormSwitch>
<FormSwitch v-model="showAddFileDescriptionAtFirstPost" class="_formBlock">{{
i18n.ts.showAddFileDescriptionAtFirstPost
}}</FormSwitch>
<FormSwitch v-model="autocorrectNoteLanguage" class="_formBlock">{{ <FormSwitch v-model="autocorrectNoteLanguage" class="_formBlock">{{
i18n.ts.autocorrectNoteLanguage i18n.ts.autocorrectNoteLanguage
}}</FormSwitch> }}</FormSwitch>
@ -533,6 +536,9 @@ const pullToRefreshThreshold = computed(
const showNoAltTextWarning = computed( const showNoAltTextWarning = computed(
defaultStore.makeGetterSetter("showNoAltTextWarning"), defaultStore.makeGetterSetter("showNoAltTextWarning"),
); );
const showAddFileDescriptionAtFirstPost = computed(
defaultStore.makeGetterSetter("showAddFileDescriptionAtFirstPost"),
);
const autocorrectNoteLanguage = computed( const autocorrectNoteLanguage = computed(
defaultStore.makeGetterSetter("autocorrectNoteLanguage"), defaultStore.makeGetterSetter("autocorrectNoteLanguage"),
); );

View File

@ -125,6 +125,7 @@ const defaultStoreSaveKeys: (keyof (typeof defaultStore)["state"])[] = [
"enablePullToRefresh", "enablePullToRefresh",
"pullToRefreshThreshold", "pullToRefreshThreshold",
"showNoAltTextWarning", "showNoAltTextWarning",
"showAddFileDescriptionAtFirstPost",
"autocorrectNoteLanguage", "autocorrectNoteLanguage",
]; ];
const coldDeviceStorageSaveKeys: (keyof typeof ColdDeviceStorage.default)[] = [ const coldDeviceStorageSaveKeys: (keyof typeof ColdDeviceStorage.default)[] = [

View File

@ -432,6 +432,10 @@ export const defaultStore = markRaw(
where: "account", where: "account",
default: true, default: true,
}, },
showAddFileDescriptionAtFirstPost: {
where: "account",
default: false,
},
autocorrectNoteLanguage: { autocorrectNoteLanguage: {
where: "account", where: "account",
default: true, default: true,