85820e4a43
* fix(web): warn when pasted attachment is too large * test(web): provide toast context to chat input tests * fix(web): warn when browser image paste lacks file data * fix(web): warn about oversized new task attachments * fix(web): keep toasts above modal overlays * fix(web): handle file-list-only dialog pastes * fix(web): avoid parsing clipboard HTML * fix(web): handle attachment paste edge cases * fix(web): improve attachment limit feedback * fix(web): show aggregate attachment limit feedback
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import { useCallback } from "react";
|
||
import { useToast } from "@/components/toast-provider";
|
||
import { formatBytes, MAX_FILES, MAX_FILE_SIZE, MAX_TOTAL_SIZE } from "./file-attachment";
|
||
|
||
export function useAttachmentCountFeedback() {
|
||
const { toast } = useToast();
|
||
|
||
return useCallback(() => {
|
||
toast({
|
||
title: "Attachment limit reached",
|
||
description: `You can attach up to ${MAX_FILES} files.`,
|
||
variant: "error",
|
||
});
|
||
}, [toast]);
|
||
}
|
||
|
||
export function useAttachmentTotalSizeFeedback() {
|
||
const { toast } = useToast();
|
||
|
||
return useCallback(() => {
|
||
toast({
|
||
title: "Attachment limit reached",
|
||
description: `Attachments can total up to ${formatBytes(MAX_TOTAL_SIZE)}.`,
|
||
variant: "error",
|
||
});
|
||
}, [toast]);
|
||
}
|
||
|
||
export function useAttachmentFileFeedback() {
|
||
const { toast } = useToast();
|
||
|
||
return useCallback(
|
||
(file: File): boolean => {
|
||
if (file.size <= MAX_FILE_SIZE) return false;
|
||
|
||
toast({
|
||
title: "Attachment is too large",
|
||
description: `${file.name} is ${formatBytes(file.size)}. The maximum file size is ${formatBytes(MAX_FILE_SIZE)}.`,
|
||
variant: "error",
|
||
});
|
||
return true;
|
||
},
|
||
[toast],
|
||
);
|
||
}
|
||
|
||
export function useUnreadablePastedImageFeedback() {
|
||
const { toast } = useToast();
|
||
|
||
return useCallback(() => {
|
||
toast({
|
||
title: "Pasted image couldn’t be attached",
|
||
description:
|
||
"The browser didn’t provide image data. Save the image, then attach the file instead.",
|
||
variant: "error",
|
||
});
|
||
}, [toast]);
|
||
}
|