diff --git a/backend/database/src/index.ts b/backend/database/src/index.ts index 81df8bf..9bfb009 100644 --- a/backend/database/src/index.ts +++ b/backend/database/src/index.ts @@ -93,7 +93,30 @@ export default { return methodNotAllowed; } } else if (path === "/api/sandbox/share") { - if (method === "POST") { + if (method === "GET") { + const params = url.searchParams; + if (params.has("id")) { + const id = params.get("id") as string; + const res = await db.query.usersToSandboxes.findMany({ + where: (uts, { eq }) => eq(uts.userId, id), + }); + + const owners = await Promise.all( + res.map(async (r) => { + const sb = await db.query.sandbox.findFirst({ + where: (sandbox, { eq }) => eq(sandbox.id, r.sandboxId), + with: { + author: true, + }, + }); + if (!sb) return; + return { id: sb.id, name: sb.name, type: sb.type, author: sb.author.name, sharedOn: Date.now() }; + }) + ); + + return json(owners ?? {}); + } else return invalidRequest; + } else if (method === "POST") { const shareSchema = z.object({ sandboxId: z.string(), email: z.string(), diff --git a/frontend/app/(app)/dashboard/page.tsx b/frontend/app/(app)/dashboard/page.tsx index e2db8a6..61d4e3f 100644 --- a/frontend/app/(app)/dashboard/page.tsx +++ b/frontend/app/(app)/dashboard/page.tsx @@ -14,10 +14,21 @@ export default async function DashboardPage() { const userRes = await fetch(`http://localhost:8787/api/user?id=${user.id}`) const userData = (await userRes.json()) as User + const sharedRes = await fetch( + `http://localhost:8787/api/sandbox/share?id=${user.id}` + ) + const shared = (await sharedRes.json()) as { + id: string + name: string + type: "react" | "node" + author: string + sharedOn: Date + }[] + return (
- +
) } diff --git a/frontend/components/dashboard/index.tsx b/frontend/components/dashboard/index.tsx index 1f233fa..25ff64e 100644 --- a/frontend/components/dashboard/index.tsx +++ b/frontend/components/dashboard/index.tsx @@ -3,28 +3,34 @@ import CustomButton from "@/components/ui/customButton" import { Button } from "@/components/ui/button" import { - Clock, Code2, - Ellipsis, FolderDot, - Globe, HelpCircle, Plus, Settings, Users, } from "lucide-react" import { useState } from "react" -import ProjectCard from "./projectCard" import { Sandbox } from "@/lib/types" -import Image from "next/image" -import ProjectCardDropdown from "./projectCard/dropdown" import DashboardProjects from "./projects" import DashboardSharedWithMe from "./shared" import NewProjectModal from "./newProject" type TScreen = "projects" | "shared" | "settings" | "search" -export default function Dashboard({ sandboxes }: { sandboxes: Sandbox[] }) { +export default function Dashboard({ + sandboxes, + shared, +}: { + sandboxes: Sandbox[] + shared: { + id: string + name: string + type: "react" | "node" + author: string + sharedOn: Date + }[] +}) { const [screen, setScreen] = useState("projects") const [newProjectModalOpen, setNewProjectModalOpen] = useState(false) @@ -95,7 +101,7 @@ export default function Dashboard({ sandboxes }: { sandboxes: Sandbox[] }) { {screen === "projects" ? ( ) : screen === "shared" ? ( - + ) : screen === "settings" ? null : null} diff --git a/frontend/components/dashboard/shared.tsx b/frontend/components/dashboard/shared.tsx index e74174e..84d76c6 100644 --- a/frontend/components/dashboard/shared.tsx +++ b/frontend/components/dashboard/shared.tsx @@ -14,9 +14,15 @@ import { ChevronRight } from "lucide-react" import Avatar from "../ui/avatar" export default function DashboardSharedWithMe({ - sandboxes, + shared, }: { - sandboxes: Sandbox[] + shared: { + id: string + name: string + type: "react" | "node" + author: string + sharedOn: Date + }[] }) { return (
@@ -32,7 +38,7 @@ export default function DashboardSharedWithMe({ - {sandboxes.map((sandbox) => ( + {shared.map((sandbox) => (
@@ -52,11 +58,11 @@ export default function DashboardSharedWithMe({
- - Ishaan Dey + + {sandbox.author}
- {new Date().toLocaleDateString()} + {sandbox.sharedOn.toLocaleDateString()}