-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
155 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
"use client"; | ||
|
||
import { useEffect, useState } from "react"; | ||
|
||
import { createClient } from "@/utils/supabase/client"; | ||
|
||
import { Button } from "@/components/ui/Button"; | ||
import ClipCard from "@/components/ClipCard"; | ||
|
||
import { FaFilter } from "react-icons/fa6"; | ||
|
||
import { Clip, UserProfile } from "@/interfaces"; | ||
|
||
interface Props { | ||
id: string; | ||
} | ||
|
||
interface SavedClip { | ||
clips: Clip; | ||
profiles: UserProfile; | ||
id: string; | ||
saved_at: string; | ||
saved_by: string; | ||
clipId: string; | ||
} | ||
|
||
const supabase = createClient(); | ||
|
||
export const SavedClips: React.FC<Props> = ({ id }) => { | ||
const [clips, setClips] = useState<SavedClip[]>([]); | ||
const [loading, setLoading] = useState(true); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
setLoading(true); | ||
|
||
let queryBuilder = supabase | ||
.from("savedClips") | ||
.select(` | ||
*, | ||
clips (*), | ||
profiles (full_name, username, avatar, verified) | ||
`) | ||
.eq("saved_by", id) | ||
.order("saved_at", { ascending: false }); | ||
|
||
const { data, error } = await queryBuilder; | ||
|
||
if (error) { | ||
console.error("Error fetching saved clips:", error); | ||
} else { | ||
setClips(data as SavedClip[]); | ||
} | ||
setLoading(false); | ||
}; | ||
|
||
fetchData(); | ||
}, [id]); | ||
|
||
return ( | ||
<> | ||
<div className="flex justify-between items-center mb-4"> | ||
<h3 className="text-white">Saved Clips</h3> | ||
<Button size="small" color="primary" icon={<FaFilter />}> | ||
Filter | ||
</Button> | ||
</div> | ||
|
||
{/* Loader */} | ||
{loading && ( | ||
<div className="flex justify-center items-center p-4"> | ||
<p>Loading...</p> | ||
</div> | ||
)} | ||
|
||
{/* Clips List */} | ||
{!loading && clips.length === 0 ? ( | ||
<div className="flex justify-center items-center flex-col h-full p-4"> | ||
<p className="text-xl">No results found</p> | ||
<p className="text-base font-normal">Try searching with different keywords</p> | ||
</div> | ||
) : ( | ||
<div className="h-full overflow-y-auto w-full space-y-4 scrollbar-hide"> | ||
{clips.map((clip, key) => ( | ||
<ClipCard | ||
key={key} | ||
isActive={true} | ||
clipData={{ | ||
...clip.clips, // Spread all properties from clip.clips | ||
profiles: clip.profiles, // Embed profiles directly | ||
}} | ||
/> | ||
))} | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; |
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,49 @@ | ||
import { Metadata, NextPage } from "next"; | ||
|
||
import { createClient } from "@/utils/supabase/server"; | ||
|
||
import WithAuth from "@/components/Auth/WithAuth"; | ||
|
||
import Navbar from "@/components/ui/Navbar"; | ||
|
||
import { GridProvider } from "@/components/ui/Grid/GridProvider"; | ||
import { LeftColumn } from "@/components/ui/Grid/LeftColumn"; | ||
import { MiddleColumn } from "@/components/ui/Grid/MiddleColumn"; | ||
import { RightColumn } from "@/components/ui/Grid/RightColumn"; | ||
|
||
import { UsersList } from "@/components/UsersList"; | ||
import { ProfileCard } from "@/components/ProfileCard"; | ||
import { SavedClips } from "./SavedClips"; | ||
|
||
import { Loader } from "@/components/ui/Loader"; | ||
|
||
export const metadata: Metadata = { | ||
title: "Saved Clips • VoidCast", | ||
} | ||
|
||
const supabase = createClient(); | ||
|
||
const Saved: NextPage = async () => { | ||
|
||
const { data: { user } } = await supabase.auth.getUser(); | ||
|
||
return ( | ||
<WithAuth> | ||
<Navbar user={user} /> | ||
<GridProvider> | ||
<LeftColumn> | ||
<h3 className="text-white mb-4">People</h3> | ||
<UsersList /> | ||
</LeftColumn> | ||
<MiddleColumn> | ||
{user ? <SavedClips id={user?.id} /> : <Loader />} | ||
</MiddleColumn> | ||
<RightColumn> | ||
<ProfileCard user={user} /> | ||
</RightColumn> | ||
</GridProvider> | ||
</WithAuth> | ||
) | ||
} | ||
|
||
export default Saved; |
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