Skip to content

Commit

Permalink
feat: file upload UX
Browse files Browse the repository at this point in the history
  • Loading branch information
bboinay committed Aug 15, 2024
1 parent 4312352 commit 1484e78
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions ui/src/components/ModalFileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
import { Dispatch, SetStateAction } from "react";
import { Dispatch, SetStateAction, useState } from "react";
import { Overlay } from "./Overlay";
import { useForm } from "react-hook-form";
import { z } from "zod";
Expand Down Expand Up @@ -35,6 +35,7 @@ const formSchema = z.object({
});

export function ModalFileUpload({ setModalVisible, id }: ModalFileUploadProps) {
const [loadingStatus, setLoadingStatus] = useState<string | null>(null);
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
});
Expand All @@ -44,20 +45,21 @@ export function ModalFileUpload({ setModalVisible, id }: ModalFileUploadProps) {
}

function onSubmit(values: z.infer<typeof formSchema>) {
setLoadingStatus("File loading, please wait...");
uploadMutation.mutate(values.file);
}

const uploadMutation = useMutation({
mutationFn: async (file: File) => {
knowledgeBaseService.uploadFile(id, file);
return await knowledgeBaseService.uploadFile(id, file);
},
onSuccess: () => {
onSuccess: async () => {
await new Promise((resolve) => setTimeout(resolve, 0)); // Ensures synchronous execution
setModalVisible(false);
// You might want to add a success notification here
},
onError: (error) => {
setLoadingStatus("Error uploading file");
console.error("Error uploading file:", error);
// You might want to add an error notification here
},
});

Expand Down Expand Up @@ -100,6 +102,7 @@ export function ModalFileUpload({ setModalVisible, id }: ModalFileUploadProps) {
</Button>
<Button type="submit">Upload</Button>
</div>
{loadingStatus && <p>{loadingStatus}</p>}
</form>
</Form>
</CardContent>
Expand Down
6 changes: 3 additions & 3 deletions ui/src/components/form_fields/GenerativeModelField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export function GenerativeModelField({ control }: GenerativeModelFieldProps) {
<SelectValue placeholder="Generative Model" />
</SelectTrigger>
<SelectContent>
<SelectItem value="gpt-3.5-turbo">gpt-3.5-turbo</SelectItem>
<SelectItem value="option-2">Option 2</SelectItem>
<SelectItem value="option-3">Option 3</SelectItem>
<SelectItem value="gpt-4-turbo">gpt-4-turbo</SelectItem>
<SelectItem value="gpt-4o-mini">gpt-4o-mini</SelectItem>
<SelectItem value="gpt-4o">gpt-4o</SelectItem>
</SelectContent>
</Select>
</FormControl>
Expand Down

0 comments on commit 1484e78

Please sign in to comment.