mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-18 21:44:06 +01:00
feat: add page to list followed project
This commit is contained in:
parent
142817986d
commit
4ae49558ac
46
src/app/follow/page.tsx
Normal file
46
src/app/follow/page.tsx
Normal file
@ -0,0 +1,46 @@
|
||||
import { ProjectSection } from "@/components/ProjectSection";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { getProjectCardData } from "@/lib/data/projectQuery";
|
||||
import { createSupabaseClient } from "@/lib/supabase/serverComponentClient";
|
||||
import { getFollowByUserId } from "@/lib/data/followQuery";
|
||||
|
||||
export default async function FollowPage() {
|
||||
const supabase = createSupabaseClient();
|
||||
const { data: user, error: userError } = await supabase.auth.getUser();
|
||||
|
||||
if (userError || !user) {
|
||||
throw new Error(userError?.message || "Unknown error");
|
||||
}
|
||||
|
||||
const { data: followsProjects, error: followsProjectsError } = await getFollowByUserId(supabase, user!.user.id);
|
||||
|
||||
if (followsProjectsError) {
|
||||
throw new Error(followsProjectsError.message || "Unknown error");
|
||||
}
|
||||
|
||||
const projectIdList: string[] = followsProjects.map((follow) => follow.project_id);
|
||||
|
||||
const { data: projectsData, error: projectsDataError } = await getProjectCardData(supabase, projectIdList);
|
||||
|
||||
if (projectsDataError) {
|
||||
throw new Error(projectsDataError || "Unknown error");
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="container max-w-screen-xl my-5">
|
||||
<div>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Your favorite projects</CardTitle>
|
||||
<CardDescription>Found {projectsData?.length ?? 0} projects!</CardDescription>
|
||||
</CardHeader>
|
||||
<Separator className="my-3" />
|
||||
<CardContent>
|
||||
<ProjectSection projectsData={projectsData} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -37,7 +37,9 @@ export const AuthenticatedComponents = ({ uid, avatarUrl }: AuthenticatedCompone
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
<Heart />
|
||||
<Link href="/follow">
|
||||
<Heart />
|
||||
</Link>
|
||||
<Link href={"/portfolio/" + uid}>
|
||||
<Wallet className="cursor-pointer" />
|
||||
</Link>
|
||||
|
||||
@ -9,6 +9,10 @@ export function getFollow(client: SupabaseClient, user_id: string, project_id: n
|
||||
.maybeSingle();
|
||||
}
|
||||
|
||||
export function getFollowByUserId(client: SupabaseClient, user_id: string) {
|
||||
return client.from("follow").select("id, project_id, user_id, created_at").eq("user_id", user_id);
|
||||
}
|
||||
|
||||
export async function insertFollow(client: SupabaseClient, user_id: string, project_id: number) {
|
||||
const { error } = await client.from("follow").insert({ user_id, project_id }).select();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user