this repo has no description

Separate books based on clicked tab

+36 -6
+11 -4
app/library/LibraryClient.tsx
··· 4 4 import Link from "next/link"; 5 5 import { useState } from "react"; 6 6 7 - const LibraryClient = ({ books, did }) => { 7 + const LibraryClient = ({ did, incompleteBooks, rankedBooks }) => { 8 8 const [showRankedBooks, setShowRankedBooks] = useState(true); 9 + const [displayedBooks, setDisplayedBooks] = useState(); 9 10 10 11 return ( 11 12 <div className="grid grid-rows-10 p-4 row-span-9"> ··· 16 17 ? "bg-emerald-900 text-amber-100 transform translate-y-1" 17 18 : "bg-emerald-900/80 text-amber-100/80" 18 19 }`} 19 - onClick={() => setShowRankedBooks(true)} 20 + onClick={() => { 21 + setShowRankedBooks(true); 22 + setDisplayedBooks(rankedBooks); 23 + }} 20 24 > 21 25 Ranked Books 22 26 </button> ··· 26 30 ? "bg-emerald-900 text-amber-100 transform translate-y-1" 27 31 : "bg-emerald-900/80 text-amber-100/80" 28 32 }`} 29 - onClick={() => setShowRankedBooks(false)} 33 + onClick={() => { 34 + setShowRankedBooks(false); 35 + setDisplayedBooks(incompleteBooks); 36 + }} 30 37 > 31 38 Books with Missing Data 32 39 </button> ··· 34 41 <div 35 42 className={`auto-rows-min bg-emerald-900 gap-4 grid grid-cols-5 overflow-y-scroll p-4 rounded-b-xl row-span-9`} 36 43 > 37 - {books?.map((book) => { 44 + {displayedBooks?.map((book) => { 38 45 return ( 39 46 <Link 40 47 href={`/book/${book.hiveID.slice(3)}`}
+25 -2
app/library/page.tsx
··· 3 3 import { Agent } from "@atproto/api"; 4 4 import { redirect } from "next/navigation"; 5 5 import LibraryClient from "./LibraryClient"; 6 + import { supabase } from "@/lib/supabase/server"; 6 7 7 8 const Library = async () => { 8 9 const session = await getSession(); ··· 13 14 14 15 const agent = new Agent(session); 15 16 16 - let books; 17 + let incompleteBooks, rankedBooks; 17 18 18 19 try { 19 20 const response = await agent.com.atproto.repo.listRecords({ ··· 22 23 repo: session.did 23 24 }); 24 25 26 + let books; 27 + 25 28 books = response.data.records.filter( 26 29 (book) => 27 30 book.value.status === "buzz.bookhive.defs#reading" || ··· 34 37 hiveID: book.value.hiveId, 35 38 title: book.value.title 36 39 })); 40 + 41 + const { data } = await supabase 42 + .from("books") 43 + .select("*") 44 + .in( 45 + "hive_id", 46 + books.map((book) => book.hiveID) 47 + ); 48 + 49 + rankedBooks = books.filter((book) => { 50 + const meta = data?.find((m) => m.hive_id === book.hiveID); 51 + 52 + return meta && meta.amazon_rating && meta.goodreads_rating; 53 + }); 54 + incompleteBooks = books.filter((book) => { 55 + const meta = data?.find((m) => m.hive_id === book.hiveID); 56 + 57 + return !meta || !meta.amazon_rating || !meta.goodreads_rating; 58 + }); 37 59 } catch (error) { 38 60 console.error("Error fetching profile:", error); 39 61 ··· 45 67 <> 46 68 <Header /> 47 69 <LibraryClient 48 - books={books} 49 70 did={session.did} 71 + incompleteBooks={incompleteBooks} 72 + rankedBooks={rankedBooks} 50 73 /> 51 74 </> 52 75 );