File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { auth } from "@clerk/nextjs/server"
2+ import { MUTATIONS , QUERIES } from "~/server/db/queries"
3+ import { redirect } from "next/navigation"
4+ import { Button } from "~/components/ui/button"
5+ import { root } from ".eslintrc.cjs"
6+
7+ export default async function DrivePage ( ) {
8+
9+ const session = await auth ( )
10+
11+ if ( ! session . userId ) {
12+ return redirect ( "/sign-in" )
13+ }
14+
15+ const rootFolder = await QUERIES . getRootFolderForUser ( session . userId )
16+
17+ if ( ! rootFolder ) {
18+ return (
19+ < form action = { async ( ) => {
20+ "use server" ;
21+ const session = await auth ( )
22+
23+ if ( ! session . userId ) {
24+ return redirect ( "/sign-in" )
25+ }
26+
27+ const rootFolderId = await MUTATIONS . onboardUser ( session . userId )
28+
29+ return redirect ( `/f/${ rootFolderId } ` )
30+ } } >
31+ < Button > Create New Drive</ Button >
32+ </ form >
33+ )
34+ }
35+
36+ return redirect ( `/f/${ rootFolder . id } ` )
37+ }
Original file line number Diff line number Diff line change 1+ export default function HomePage ( props : { children : React . ReactNode } ) {
2+ return (
3+ < div className = "flex min-h-screen flex-col items-center justify-center bg-gradient-to-br from-black via-neutral-900 to-neutral-800 p-4 text-white" >
4+ < main className = "text-center" > { props . children } </ main >
5+ </ div >
6+ ) ;
7+ }
Original file line number Diff line number Diff line change @@ -4,8 +4,7 @@ import { Button } from "~/components/ui/button";
44
55export default function HomePage ( ) {
66 return (
7- < div className = "flex min-h-screen flex-col items-center justify-center bg-gradient-to-br from-black via-neutral-900 to-neutral-800 p-4 text-white" >
8- < main className = "text-center" >
7+ < >
98 < h1 className = "mb-4 bg-gradient-to-r from-neutral-200 to-neutral-400 bg-clip-text text-5xl font-bold text-transparent md:text-6xl" >
109 DriveV2
1110 </ h1 >
@@ -30,10 +29,10 @@ export default function HomePage() {
3029 Get Started
3130 </ Button >
3231 </ form >
33- </ main >
32+
3433 < footer className = "mt-16 text-sm text-neutral-500" >
3534 © { new Date ( ) . getFullYear ( ) } DriveV2. All rights reserved.
3635 </ footer >
37- </ div >
36+ </ >
3837 ) ;
3938}
Original file line number Diff line number Diff line change 1+ import { SignInButton } from "@clerk/nextjs" ;
2+ export default function HomePage ( ) {
3+ return (
4+ < >
5+ < SignInButton forceRedirectUrl = { "/drive" } />
6+ < footer className = "mt-16 text-sm text-neutral-500" >
7+ © { new Date ( ) . getFullYear ( ) } T3 Drive. All rights reserved.
8+ </ footer >
9+ </ >
10+ ) ;
11+ }
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import "server-only"
33import { db } from "~/server/db"
44import { files_table as filesSchema , folders_table as foldersSchema } from "~/server/db/schema"
55import { eq , and , isNull } from "drizzle-orm"
6+ import { root } from ".eslintrc.cjs"
67
78export const QUERIES = {
89 getFiles : function ( folderId : number ) {
@@ -75,6 +76,35 @@ export const MUTATIONS = {
7576 ownerId : input . userId ,
7677 } )
7778
79+ } ,
80+
81+ onboardUser : async function ( userId : string ) {
82+ const rootFolder = await db . insert ( foldersSchema ) . values ( {
83+ name : "Root" ,
84+ parent : null ,
85+ ownerId : userId ,
86+ } ) . $returningId ( )
87+
88+ const rootFolderId = rootFolder [ 0 ] ! . id
89+
90+ await db . insert ( foldersSchema ) . values ( [ {
91+ name : "Trash" ,
92+ parent : rootFolderId ,
93+ ownerId : userId
94+ } ,
95+ {
96+ name : "Shared" ,
97+ parent : rootFolderId ,
98+ ownerId : userId ,
99+ } ,
100+ {
101+ name : "Documents" ,
102+ parent : rootFolderId ,
103+ ownerId : userId ,
104+ }
105+ ] )
106+
107+ return rootFolderId
78108 }
79109}
80110
You can’t perform that action at this time.
0 commit comments