tangled
alpha
login
or
join now
modamo.xyz
/
bambu
1
fork
atom
this repo has no description
1
fork
atom
overview
issues
pulls
pipelines
Fetch number of pages from Google Books
modamo-gh
1 month ago
d23695ac
873c08ac
+29
-3
3 changed files
expand all
collapse all
unified
split
app
book
[bookID]
page.tsx
components
Header.tsx
lib
books
google.ts
+10
-2
app/book/[bookID]/page.tsx
···
1
import Header from "@/components/Header";
2
import { getSession } from "@/lib/auth/session";
0
3
import { Agent } from "@atproto/api";
4
import Image from "next/image";
5
import { redirect } from "next/navigation";
···
15
16
const agent = new Agent(session);
17
18
-
let book;
19
20
try {
21
const response = await agent.com.atproto.repo.listRecords({
···
27
book = response.data.records.find(
28
(record) => record.value.hiveId === `bk_${bookID}`
29
);
0
0
0
0
0
30
} catch (error) {
31
console.error("Error fetching book:", error);
32
}
···
52
<p className="text-emerald-900">{`Title: ${book?.value.title}`}</p>
53
<p className="text-emerald-900">Amazon Rating:</p>
54
<p className="text-emerald-900">Goodreads Rating:</p>
55
-
<p className="text-emerald-900">Number of Pages:</p>
0
0
56
</div>
57
</div>
58
<div className="bg-emerald-900 col-span-1 p-4 rounded-2xl"></div>
···
1
import Header from "@/components/Header";
2
import { getSession } from "@/lib/auth/session";
3
+
import { fetchNumberOfPages } from "@/lib/books/google";
4
import { Agent } from "@atproto/api";
5
import Image from "next/image";
6
import { redirect } from "next/navigation";
···
16
17
const agent = new Agent(session);
18
19
+
let book, numberOfPages;
20
21
try {
22
const response = await agent.com.atproto.repo.listRecords({
···
28
book = response.data.records.find(
29
(record) => record.value.hiveId === `bk_${bookID}`
30
);
31
+
32
+
numberOfPages = await fetchNumberOfPages(
33
+
book.value.authors,
34
+
book.value.title
35
+
);
36
} catch (error) {
37
console.error("Error fetching book:", error);
38
}
···
58
<p className="text-emerald-900">{`Title: ${book?.value.title}`}</p>
59
<p className="text-emerald-900">Amazon Rating:</p>
60
<p className="text-emerald-900">Goodreads Rating:</p>
61
+
<p className="text-emerald-900">
62
+
Number of Pages: {numberOfPages}
63
+
</p>
64
</div>
65
</div>
66
<div className="bg-emerald-900 col-span-1 p-4 rounded-2xl"></div>
+4
-1
components/Header.tsx
···
1
import { getSession } from "@/lib/auth/session";
2
import { Agent } from "@atproto/api";
3
import Image from "next/image";
0
4
import { redirect } from "next/navigation";
5
6
const Header = async () => {
···
24
25
return (
26
<header className="bg-emerald-900 flex items-center justify-between p-4 rounded-2xl row-span-1">
27
-
<h1 className="text-amber-100 text-4xl">bambü</h1>
0
0
28
<div className="h-16 relative w-16">
29
<Image
30
alt={`Profile picture for ${profile?.handle}`}
···
1
import { getSession } from "@/lib/auth/session";
2
import { Agent } from "@atproto/api";
3
import Image from "next/image";
4
+
import Link from "next/link";
5
import { redirect } from "next/navigation";
6
7
const Header = async () => {
···
25
26
return (
27
<header className="bg-emerald-900 flex items-center justify-between p-4 rounded-2xl row-span-1">
28
+
<Link href="/">
29
+
<h1 className="text-amber-100 text-4xl">bambü</h1>
30
+
</Link>
31
<div className="h-16 relative w-16">
32
<Image
33
alt={`Profile picture for ${profile?.handle}`}
+15
lib/books/google.ts
···
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
···
1
+
export const fetchNumberOfPages = async (authors: string, title: string) => {
2
+
try {
3
+
const response = await fetch(
4
+
`https://www.googleapis.com/books/v1/volumes?q=intitle:${encodeURIComponent(
5
+
title
6
+
)}+inauthor:${encodeURIComponent(authors)}&maxResults=1`
7
+
);
8
+
const json = await response.json();
9
+
const volumeInfo = json.items[0].volumeInfo;
10
+
11
+
return Number(volumeInfo.pageCount);
12
+
} catch (error) {
13
+
console.error("Error fetching number of pages:", error);
14
+
}
15
+
};