use toast for error instead
This commit is contained in:
parent
08428bc12d
commit
c1a6713bd8
1 changed files with 2 additions and 17 deletions
|
|
@ -3,6 +3,7 @@ import { AnimatePresence, motion } from "motion/react";
|
||||||
import { forwardRef, useImperativeHandle, useRef, useState } from "react";
|
import { forwardRef, useImperativeHandle, useRef, useState } from "react";
|
||||||
import { useDropzone } from "react-dropzone";
|
import { useDropzone } from "react-dropzone";
|
||||||
import TextareaAutosize from "react-textarea-autosize";
|
import TextareaAutosize from "react-textarea-autosize";
|
||||||
|
import { toast } from "sonner";
|
||||||
import type { FilterColor } from "@/components/filter-icon-popover";
|
import type { FilterColor } from "@/components/filter-icon-popover";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
|
|
@ -75,7 +76,6 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
|
||||||
const inputRef = useRef<HTMLTextAreaElement>(null);
|
const inputRef = useRef<HTMLTextAreaElement>(null);
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
const [textareaHeight, setTextareaHeight] = useState(0);
|
const [textareaHeight, setTextareaHeight] = useState(0);
|
||||||
const [fileUploadError, setFileUploadError] = useState<Error | null>(null);
|
|
||||||
const isDragging = useFileDrag();
|
const isDragging = useFileDrag();
|
||||||
|
|
||||||
const { getRootProps, getInputProps } = useDropzone({
|
const { getRootProps, getInputProps } = useDropzone({
|
||||||
|
|
@ -89,11 +89,9 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
|
||||||
maxFiles: 1,
|
maxFiles: 1,
|
||||||
disabled: !isDragging,
|
disabled: !isDragging,
|
||||||
onDrop: (acceptedFiles, fileRejections) => {
|
onDrop: (acceptedFiles, fileRejections) => {
|
||||||
setFileUploadError(null);
|
|
||||||
if (fileRejections.length > 0) {
|
if (fileRejections.length > 0) {
|
||||||
console.log(fileRejections);
|
|
||||||
const message = fileRejections.at(0)?.errors.at(0)?.message;
|
const message = fileRejections.at(0)?.errors.at(0)?.message;
|
||||||
setFileUploadError(new Error(message));
|
toast.error(message || "Failed to upload file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
onFileSelected(acceptedFiles[0]);
|
onFileSelected(acceptedFiles[0]);
|
||||||
|
|
@ -110,7 +108,6 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const handleFilePickerChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleFilePickerChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setFileUploadError(null);
|
|
||||||
const files = e.target.files;
|
const files = e.target.files;
|
||||||
if (files && files.length > 0) {
|
if (files && files.length > 0) {
|
||||||
onFileSelected(files[0]);
|
onFileSelected(files[0]);
|
||||||
|
|
@ -151,18 +148,6 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
|
||||||
</motion.div>
|
</motion.div>
|
||||||
)}
|
)}
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
<AnimatePresence>
|
|
||||||
{fileUploadError && (
|
|
||||||
<motion.p
|
|
||||||
initial={{ opacity: 0, height: 0 }}
|
|
||||||
animate={{ opacity: 1, height: "auto" }}
|
|
||||||
exit={{ opacity: 0, height: 0 }}
|
|
||||||
className="text-sm text-destructive overflow-hidden"
|
|
||||||
>
|
|
||||||
{fileUploadError.message}
|
|
||||||
</motion.p>
|
|
||||||
)}
|
|
||||||
</AnimatePresence>
|
|
||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
{isDragging && (
|
{isDragging && (
|
||||||
<motion.div
|
<motion.div
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue