-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nextjs): create projects now works
- Loading branch information
Showing
14 changed files
with
167 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { findAllProjects } from "../_queries"; | ||
import ProjectGrid from "./project-grid"; | ||
|
||
export default async function AllProjects() { | ||
const allProjects = await findAllProjects(); | ||
return <ProjectGrid projects={allProjects} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { memo } from "react"; | ||
import Image from "next/image"; | ||
import Link from "next/link"; | ||
|
||
import { Card, CardContent, CardFooter } from "@amaxa/ui/card"; | ||
|
||
interface ProjectCardProps { | ||
project: { | ||
id: string; | ||
name: string; | ||
image: string | null; | ||
}; | ||
} | ||
|
||
const ProjectCard = memo(function ProjectCard({ project }: ProjectCardProps) { | ||
return ( | ||
<Link href={`/project/${project.id}`} className="block w-full"> | ||
<Card className="h-[300px] w-full overflow-hidden transition-transform duration-200 hover:bg-muted/40"> | ||
<CardContent className="relative h-[220px] p-0"> | ||
<Image | ||
src={project.image ?? "/placeholder.svg"} | ||
alt={project.name} | ||
fill | ||
className="object-cover" | ||
sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 33vw" | ||
/> | ||
</CardContent> | ||
<CardFooter className="h-[80px] items-center justify-center text-center"> | ||
<h3 className="line-clamp-2 text-lg font-semibold">{project.name}</h3> | ||
</CardFooter> | ||
</Card> | ||
</Link> | ||
); | ||
}); | ||
|
||
export default ProjectCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { memo } from "react"; | ||
|
||
import ProjectCard from "./project-card"; | ||
|
||
const ProjectGrid = memo(function ProjectGrid({ | ||
projects, | ||
}: { | ||
projects: { | ||
id: string; | ||
name: string; | ||
image: string | null; | ||
}[]; | ||
}) { | ||
return ( | ||
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3"> | ||
{projects.map((project) => ( | ||
<ProjectCard key={project.id} project={project} /> | ||
))} | ||
</div> | ||
); | ||
}); | ||
|
||
export default ProjectGrid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { getUserProjects } from "~/components/navbar/switcher"; | ||
import ProjectGrid from "./project-grid"; | ||
|
||
export default async function UserProjects({ | ||
userId, | ||
userStatus, | ||
}: { | ||
userId: string; | ||
userStatus: string; | ||
}) { | ||
const usersProjects = await getUserProjects(userId); | ||
|
||
if (userStatus === "Pending" || userStatus === "Unverified") { | ||
return ( | ||
<div className="col-span-1 row-span-1 flex h-[300px] w-[300px] flex-col items-center justify-center border-dashed bg-secondary/10"> | ||
<p> | ||
{userStatus === "Pending" | ||
? "Your account is pending approval, please wait for the admin to approve your account" | ||
: "Your account is unverified, please wait till we verify your account to access the platform"} | ||
</p> | ||
</div> | ||
); | ||
} | ||
|
||
return <ProjectGrid projects={usersProjects} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,3 @@ | ||
import { db } from "@amaxa/db/client"; | ||
|
||
import { next_cache } from "~/lib/cache"; | ||
|
||
export const findAllProjects = next_cache( | ||
async () => await db.query.Projects.findMany({}), | ||
["findAllProjects"], | ||
{ | ||
revalidate: 60 * 60 * 10, | ||
}, | ||
); | ||
export const findAllProjects = () => db.query.Projects.findMany({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,45 @@ | ||
import React from "react"; | ||
import Image from "next/image"; | ||
import Link from "next/link"; | ||
import { Suspense } from "react"; | ||
import dynamic from "next/dynamic"; | ||
|
||
import { Card, CardContent, CardFooter, CardHeader } from "@amaxa/ui/card"; | ||
|
||
import { getUserProjects } from "~/components/navbar/switcher"; | ||
import { checkAuth } from "~/lib/auth"; | ||
import { CreateProject } from "./_components/create-project-dialog"; | ||
import { findAllProjects } from "./_queries"; | ||
import AllProjects from "./_components/all-projects"; | ||
import UserProjects from "./_components/user-projects"; | ||
|
||
const CreateProject = dynamic( | ||
() => | ||
import("./_components/create-project-dialog").then( | ||
(mod) => mod.CreateProject, | ||
), | ||
{ | ||
loading: () => <p>Loading...</p>, | ||
}, | ||
); | ||
|
||
export default async function Page() { | ||
const session = await checkAuth(); | ||
const [usersProjects, allProjects] = await Promise.all([ | ||
getUserProjects(session.user.id), | ||
findAllProjects(), | ||
]); | ||
|
||
return ( | ||
<div className="min-h-screen p-4 sm:p-6 lg:p-8"> | ||
<div className=""> | ||
<div className="flex w-full flex-col gap-5"> | ||
<div className="flex flex-col gap-6"> | ||
<div className="flex flex-row justify-between gap-6"> | ||
<h3 className="text-4xl font-semibold">Your Project</h3> | ||
{session.user.role === "Admin" ? <CreateProject /> : null} | ||
</div> | ||
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 "> | ||
{session.user.status == "Pending" ? ( | ||
<Card className="col-span-1 row-span-1 flex h-[300px] w-[300px] flex-col items-center justify-center border-dashed bg-secondary/10 transition-transform duration-200"> | ||
<CardHeader> | ||
Your account is pending approval, please wait for the admin | ||
to approve your account | ||
</CardHeader> | ||
</Card> | ||
) : session.user.status == "Unverified" ? ( | ||
<Card className="col-span-1 row-span-1 flex h-[300px] w-[300px] flex-col items-center justify-center border-dashed bg-secondary/10 transition-transform duration-200"> | ||
<CardHeader> | ||
Your account is unverified, please wait till we verify your | ||
account to access the platform | ||
</CardHeader> | ||
</Card> | ||
) : ( | ||
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 "> | ||
{usersProjects.map((project) => { | ||
return ( | ||
<Link | ||
key={project.id} | ||
href={`/project/${project.id}`} | ||
className="col-span-1 row-span-1 bg-secondary/10 transition-transform duration-200" | ||
> | ||
<Card className="col-span-1 row-span-1 bg-secondary/10 transition-transform duration-200"> | ||
<CardContent className="py-5"> | ||
<Image | ||
src={project.image ?? ""} | ||
width={1000} | ||
height={500} | ||
alt={String(project.id)} | ||
/> | ||
</CardContent> | ||
<CardFooter className="justify-center text-center font-bold md:text-2xl"> | ||
{project.name} | ||
</CardFooter> | ||
</Card> | ||
</Link> | ||
); | ||
})} | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
<div className="flex flex-col gap-6"> | ||
<h3 className="text-4xl font-semibold">Explore Projects</h3> | ||
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 "> | ||
{allProjects.map((project) => { | ||
return ( | ||
<Link key={project.id} href={`/project/${project.id}`}> | ||
<Card className="col-span-1 row-span-1 bg-secondary/10 transition-transform duration-200"> | ||
<CardContent className="py-5"> | ||
<Image | ||
src={project.image ?? ""} | ||
width={1000} | ||
height={500} | ||
alt={String(project.id)} | ||
/> | ||
</CardContent> | ||
<CardFooter className="justify-center text-center font-bold md:text-2xl"> | ||
{project.name} | ||
</CardFooter> | ||
</Card> | ||
</Link> | ||
); | ||
})} | ||
</div> | ||
<div className="flex w-full flex-col gap-5"> | ||
<div className="flex flex-col gap-6"> | ||
<div className="flex flex-row justify-between gap-6"> | ||
<h3 className="text-4xl font-semibold">Your Projects</h3> | ||
{session.user.role === "Admin" && <CreateProject />} | ||
</div> | ||
<Suspense fallback={<div>Loading your projects...</div>}> | ||
<UserProjects | ||
userId={session.user.id} | ||
userStatus={session.user.status} | ||
/> | ||
</Suspense> | ||
</div> | ||
<div className="flex flex-col gap-6"> | ||
<h3 className="text-4xl font-semibold">Explore Projects</h3> | ||
<Suspense fallback={<div>Loading all projects...</div>}> | ||
<AllProjects /> | ||
</Suspense> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export const dynamic = "force-dynamic"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.