feat: add page to list followed project

This commit is contained in:
Sosokker 2024-11-10 18:11:49 +07:00
parent 142817986d
commit 4ae49558ac
3 changed files with 53 additions and 1 deletions

46
src/app/follow/page.tsx Normal file
View 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>
);
}

View File

@ -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>

View File

@ -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();