File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change 11import { auth } from "@clerk/nextjs/server" ;
22import { redirect } from "next/navigation" ;
33
4+ import { Button } from "~/components/ui/button" ;
45import * as queries from "~/server/db/queries" ;
6+ import * as mutations from "~/server/db/mutations" ;
57
68export default async function DrivePage ( ) {
79 const session = await auth ( ) ;
810 if ( ! session . userId ) return redirect ( "/sign-in" ) ;
911
1012 const rootFolder = await queries . getRootFolderForUser ( session . userId ) ;
11- if ( ! rootFolder ) return redirect ( "/drive/create-root-folder" ) ;
13+
14+ if ( ! rootFolder ) {
15+ return (
16+ < form
17+ action = { async ( ) => {
18+ "use server" ;
19+ const rootFolderId = await mutations . onboardUser ( session . userId ) ;
20+ return redirect ( `/f/${ rootFolderId } ` ) ;
21+ } }
22+ >
23+ < Button > Create Folder</ Button >
24+ </ form >
25+ ) ;
26+ }
1227
1328 return redirect ( `/f/${ rootFolder . id } ` ) ;
1429}
Original file line number Diff line number Diff line change 11import { db } from "~/server/db" ;
2- import { type File , files_table as filesSchema } from "~/server/db/schema" ;
2+ import {
3+ type File ,
4+ folders_table as folderSchema ,
5+ files_table as filesSchema ,
6+ } from "~/server/db/schema" ;
7+
8+ export async function onboardUser ( userId : string ) {
9+ const [ rootFolder ] = await db
10+ . insert ( folderSchema )
11+ . values ( { name : "root" , parent : null , ownerId : userId } )
12+ . $returningId ( ) ;
13+
14+ const rootFolderId = rootFolder ! . id ;
15+
16+ await db . insert ( folderSchema ) . values ( [
17+ { name : "Trash" , parent : rootFolderId , ownerId : userId } ,
18+ { name : "Shared" , parent : rootFolderId , ownerId : userId } ,
19+ { name : "Documents" , parent : rootFolderId , ownerId : userId } ,
20+ ] ) ;
21+
22+ return rootFolderId ;
23+ }
324
425export function createFile (
526 file : Pick < File , "name" | "size" | "url" | "parent" > ,
You can’t perform that action at this time.
0 commit comments