Skip to content

Commit a8dc37d

Browse files
committed
Fix Upload Bug and Refresh Page
1 parent 130b08f commit a8dc37d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/app/drive-contents.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
import { SignedIn, SignedOut, SignInButton, UserButton } from "@clerk/nextjs";
44
import { ChevronRight } from "lucide-react";
55
import Link from "next/link";
6+
import { useRouter } from "next/navigation";
67

78
import { UploadButton } from "~/components/uploadthing";
89
import type { File, Folder } from "~/server/db/schema";
910
import { FileRow, FolderRow } from "./file-row";
10-
import { UploadButton } from "~/components/uploadthing";
1111

1212
export default function DriveContents(props: {
1313
files: File[];
1414
folders: Folder[];
1515
parents: Folder[];
1616
}) {
17+
const navigate = useRouter();
18+
1719
return (
1820
<div className="min-h-screen bg-gray-900 p-8 text-gray-100">
1921
<div className="mx-auto max-w-6xl">
@@ -61,7 +63,12 @@ export default function DriveContents(props: {
6163
))}
6264
</ul>
6365
</div>
64-
<UploadButton endpoint="imageUploader" />
66+
<UploadButton
67+
endpoint="imageUploader"
68+
onClientUploadComplete={() => {
69+
navigate.refresh();
70+
}}
71+
/>
6572
</div>
6673
</div>
6774
);

src/server/db/mutations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { db } from "~/server/db";
22
import { type File, files_table as filesSchema } from "~/server/db/schema";
33

4-
export function createFile(file: Omit<File, "id">, _userId: string) {
5-
return db.insert(filesSchema).values(file);
4+
export function createFile(file: Omit<File, "id" | "parent">, _userId: string) {
5+
return db.insert(filesSchema).values({ ...file, parent: 1 });
66
}

0 commit comments

Comments
 (0)