tui: warn about attachment limits immediately instead of batch processing
parent
3c8b069bba
commit
32ba9287b6
|
|
@ -34,6 +34,8 @@ type PromptAttachmentsInput = {
|
||||||
readClipboardImage?: () => Promise<File | null>
|
readClipboardImage?: () => Promise<File | null>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AddState = "added" | "failed" | "unsupported" | "limit"
|
||||||
|
|
||||||
export function createPromptAttachments(input: PromptAttachmentsInput) {
|
export function createPromptAttachments(input: PromptAttachmentsInput) {
|
||||||
const prompt = usePrompt()
|
const prompt = usePrompt()
|
||||||
const language = useLanguage()
|
const language = useLanguage()
|
||||||
|
|
@ -52,7 +54,7 @@ export function createPromptAttachments(input: PromptAttachmentsInput) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const add = async (file: File) => {
|
const add = async (file: File): Promise<AddState> => {
|
||||||
const mime = await attachmentMime(file)
|
const mime = await attachmentMime(file)
|
||||||
if (!mime) {
|
if (!mime) {
|
||||||
return "unsupported" as const
|
return "unsupported" as const
|
||||||
|
|
@ -80,17 +82,16 @@ export function createPromptAttachments(input: PromptAttachmentsInput) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const addAttachments = async (list: File[]) => {
|
const addAttachments = async (list: File[]) => {
|
||||||
const result = { added: false, limit: false, unsupported: false }
|
const result = { added: false, unsupported: false }
|
||||||
for (const file of list) {
|
for (const file of list) {
|
||||||
const state = await add(file)
|
const state = await add(file)
|
||||||
|
if (state === "limit") {
|
||||||
|
warnLimit()
|
||||||
|
return result.added
|
||||||
|
}
|
||||||
result.added = result.added || state === "added"
|
result.added = result.added || state === "added"
|
||||||
result.limit = result.limit || state === "limit"
|
|
||||||
result.unsupported = result.unsupported || state === "unsupported"
|
result.unsupported = result.unsupported || state === "unsupported"
|
||||||
}
|
}
|
||||||
if (result.limit) {
|
|
||||||
warnLimit()
|
|
||||||
return result.added
|
|
||||||
}
|
|
||||||
if (!result.added && result.unsupported) warn()
|
if (!result.added && result.unsupported) warn()
|
||||||
return result.added
|
return result.added
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue