tangled
alpha
login
or
join now
modamo.xyz
/
bambu
1
fork
atom
this repo has no description
1
fork
atom
overview
issues
pulls
pipelines
Separate books based on clicked tab
modamo-gh
1 month ago
d7b363b8
2252e04d
+36
-6
2 changed files
expand all
collapse all
unified
split
app
library
LibraryClient.tsx
page.tsx
+11
-4
app/library/LibraryClient.tsx
···
4
4
import Link from "next/link";
5
5
import { useState } from "react";
6
6
7
7
-
const LibraryClient = ({ books, did }) => {
7
7
+
const LibraryClient = ({ did, incompleteBooks, rankedBooks }) => {
8
8
const [showRankedBooks, setShowRankedBooks] = useState(true);
9
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
19
-
onClick={() => setShowRankedBooks(true)}
20
20
+
onClick={() => {
21
21
+
setShowRankedBooks(true);
22
22
+
setDisplayedBooks(rankedBooks);
23
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
29
-
onClick={() => setShowRankedBooks(false)}
33
33
+
onClick={() => {
34
34
+
setShowRankedBooks(false);
35
35
+
setDisplayedBooks(incompleteBooks);
36
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
37
-
{books?.map((book) => {
44
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
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
16
-
let books;
17
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
26
+
let books;
27
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
40
+
41
41
+
const { data } = await supabase
42
42
+
.from("books")
43
43
+
.select("*")
44
44
+
.in(
45
45
+
"hive_id",
46
46
+
books.map((book) => book.hiveID)
47
47
+
);
48
48
+
49
49
+
rankedBooks = books.filter((book) => {
50
50
+
const meta = data?.find((m) => m.hive_id === book.hiveID);
51
51
+
52
52
+
return meta && meta.amazon_rating && meta.goodreads_rating;
53
53
+
});
54
54
+
incompleteBooks = books.filter((book) => {
55
55
+
const meta = data?.find((m) => m.hive_id === book.hiveID);
56
56
+
57
57
+
return !meta || !meta.amazon_rating || !meta.goodreads_rating;
58
58
+
});
37
59
} catch (error) {
38
60
console.error("Error fetching profile:", error);
39
61
···
45
67
<>
46
68
<Header />
47
69
<LibraryClient
48
48
-
books={books}
49
70
did={session.did}
71
71
+
incompleteBooks={incompleteBooks}
72
72
+
rankedBooks={rankedBooks}
50
73
/>
51
74
</>
52
75
);