Skip to content

Commit

Permalink
WE DID IT!
Browse files Browse the repository at this point in the history
  • Loading branch information
t3dotgg committed Jan 30, 2025
1 parent c68504e commit 4202c60
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 61 deletions.
37 changes: 37 additions & 0 deletions src/app/(home)/drive/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { auth } from "@clerk/nextjs/server";
import { redirect } from "next/navigation";
import { Button } from "~/components/ui/button";
import { MUTATIONS, QUERIES } from "~/server/db/queries";

export default async function DrivePage() {
const session = await auth();

if (!session.userId) {
return redirect("/sign-in");
}

const rootFolder = await QUERIES.getRootFolderForUser(session.userId);

if (!rootFolder) {
return (
<form
action={async () => {
"use server";
const session = await auth();

if (!session.userId) {
return redirect("/sign-in");
}

const rootFolderId = await MUTATIONS.onboardUser(session.userId);

return redirect(`/f/${rootFolderId}`);
}}
>
<Button>Create new Drive</Button>
</form>
);
}

return redirect(`/f/${rootFolder.id}`);
}
7 changes: 7 additions & 0 deletions src/app/(home)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function HomePage(props: { children: React.ReactNode }) {
return (
<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">
<main className="text-center">{props.children}</main>
</div>
);
}
53 changes: 25 additions & 28 deletions src/app/(home)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
import { auth } from "@clerk/nextjs/server";
import { redirect } from "next/navigation";
import Link from "next/link";
import { Button } from "~/components/ui/button";

export default function HomePage() {
return (
<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">
<main className="text-center">
<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">
T3 Drive
</h1>
<p className="mx-auto mb-8 max-w-md text-xl text-neutral-400 md:text-2xl">
Secure, fast, and easy file storage for the modern web
</p>
<form
action={async () => {
"use server";
<>
<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">
T3 Drive
</h1>
<p className="mx-auto mb-8 max-w-md text-xl text-neutral-400 md:text-2xl">
Secure, fast, and easy file storage for the modern web
</p>
<form
action={async () => {
"use server";

const session = await auth();
const session = await auth();

if (!session.userId) {
return redirect("/sign-in");
}
if (!session.userId) {
return redirect("/sign-in");
}

return redirect("/drive");
}}
return redirect("/drive");
}}
>
<Button
size="lg"
type="submit"
className="border border-neutral-700 bg-neutral-800 text-white transition-colors hover:bg-neutral-700"
>
<Button
size="lg"
type="submit"
className="border border-neutral-700 bg-neutral-800 text-white transition-colors hover:bg-neutral-700"
>
Get Started
</Button>
</form>
</main>
Get Started
</Button>
</form>
<footer className="mt-16 text-sm text-neutral-500">
© {new Date().getFullYear()} T3 Drive. All rights reserved.
</footer>
</div>
</>
);
}
12 changes: 12 additions & 0 deletions src/app/(home)/sign-in/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { SignInButton } from "@clerk/nextjs";

export default function HomePage() {
return (
<>
<SignInButton forceRedirectUrl={"/drive"} />
<footer className="mt-16 text-sm text-neutral-500">
© {new Date().getFullYear()} T3 Drive. All rights reserved.
</footer>
</>
);
}
19 changes: 0 additions & 19 deletions src/app/drive/page.tsx

This file was deleted.

14 changes: 0 additions & 14 deletions src/app/sign-in/page.tsx

This file was deleted.

33 changes: 33 additions & 0 deletions src/server/db/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,37 @@ export const MUTATIONS = {
ownerId: input.userId,
});
},

onboardUser: async function (userId: string) {
const rootFolder = await db
.insert(foldersSchema)
.values({
name: "Root",
parent: null,
ownerId: userId,
})
.$returningId();

const rootFolderId = rootFolder[0]!.id;

await db.insert(foldersSchema).values([
{
name: "Trash",
parent: rootFolderId,
ownerId: userId,
},
{
name: "Shared",
parent: rootFolderId,
ownerId: userId,
},
{
name: "Documents",
parent: rootFolderId,
ownerId: userId,
},
]);

return rootFolderId;
},
};

0 comments on commit 4202c60

Please sign in to comment.