|
| 1 | +"use client"; |
| 2 | +import { useState, useRef } from "react"; |
| 3 | + |
| 4 | +import { Button } from "@shared/components/ui/button"; |
| 5 | +import { Input } from "@shared/components/ui/input"; |
| 6 | + |
| 7 | +import { FileText, Upload } from "lucide-react"; |
| 8 | +import { toast } from "sonner"; |
| 9 | + |
| 10 | +export default function AugmentComponent({ |
| 11 | + // TODO: remove for classroomId and setIsProcessing once we actually implement augments |
| 12 | + // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 13 | + classroomId, |
| 14 | +}: { |
| 15 | + classroomId: string; |
| 16 | +}) { |
| 17 | + // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 18 | + const [isProcessing, setIsProcessing] = useState(false); |
| 19 | + const [file, setFile] = useState<File | null>(null); |
| 20 | + const inputFile = useRef<HTMLInputElement>(null); |
| 21 | + |
| 22 | + const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => { |
| 23 | + const selectedFile = event.target.files?.[0]; |
| 24 | + if (!selectedFile) return; |
| 25 | + |
| 26 | + // Double-check that file passed by user is markdown or pdf |
| 27 | + const fileExtension = selectedFile.name.split(".").at(-1)?.toLowerCase(); |
| 28 | + if (fileExtension !== "pdf" && fileExtension !== "md") { |
| 29 | + toast.error("Invalid file format", { |
| 30 | + description: "Please upload a Markdown (.md) or PDF (.pdf) file", |
| 31 | + }); |
| 32 | + return; |
| 33 | + } |
| 34 | + |
| 35 | + setFile(selectedFile); |
| 36 | + }; |
| 37 | + |
| 38 | + const handleUpload = async () => { |
| 39 | + // TODO |
| 40 | + }; |
| 41 | + |
| 42 | + return ( |
| 43 | + <div className="flex flex-col items-center justify-center gap-4 p-8"> |
| 44 | + <h1 className="text-3xl font-bold">Augment Notes</h1> |
| 45 | + <p className="text-muted-foreground"> |
| 46 | + Upload your notes to get AI-powered enhancements and improvements |
| 47 | + </p> |
| 48 | + <div className="flex items-center gap-2"> |
| 49 | + <Input |
| 50 | + type="file" |
| 51 | + onChange={handleFileChange} |
| 52 | + ref={inputFile} |
| 53 | + className="hidden" |
| 54 | + accept=".md,.pdf" |
| 55 | + /> |
| 56 | + <Button |
| 57 | + variant="outline" |
| 58 | + size="lg" |
| 59 | + className="cursor-pointer" |
| 60 | + disabled={isProcessing} |
| 61 | + onClick={() => inputFile.current?.click()} |
| 62 | + > |
| 63 | + {isProcessing ? ( |
| 64 | + <Upload className="mr-2 h-4 w-4 animate-spin" /> |
| 65 | + ) : ( |
| 66 | + <FileText className="mr-2 h-4 w-4" /> |
| 67 | + )} |
| 68 | + Upload Notes |
| 69 | + </Button> |
| 70 | + {file && ( |
| 71 | + <Button |
| 72 | + variant="default" |
| 73 | + size="lg" |
| 74 | + onClick={handleUpload} |
| 75 | + disabled={isProcessing} |
| 76 | + > |
| 77 | + Process Notes |
| 78 | + </Button> |
| 79 | + )} |
| 80 | + </div> |
| 81 | + </div> |
| 82 | + ); |
| 83 | +} |
0 commit comments