diff --git a/components/BookDetails.js b/components/BookDetails.js index 92f5a2e..3d87a15 100644 --- a/components/BookDetails.js +++ b/components/BookDetails.js @@ -12,6 +12,7 @@ import { import { supabaseClient } from "../lib/client"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; +import { useToast } from "@chakra-ui/react"; export function BookDetails({ id, @@ -21,6 +22,7 @@ export function BookDetails({ }) { const router = useRouter(); const user = supabaseClient.auth.user(); + const toast = useToast(); // Hacky way to remove data from list.\ // TODO: Use a reducer instead @@ -34,11 +36,12 @@ export function BookDetails({ return imageLinks.thumbnail.replace("http://", "https://"); }; - const extractISBN13 = ({ industryIdentifiers }) => { - industryIdentifiers.filter((isbn) => { - if (isbn.type === "ISBN_13") { - return isbn.identifier; - } + const toastMsg = (title, status) => { + return toast({ + title: title, + status: status ? status : "success", + duration: 1000, + isClosable: true, }); }; @@ -91,16 +94,17 @@ export function BookDetails({ if (!error) { setRemoved(true); console.log(data); + toastMsg("Moved to Library"); } else { console.log(error); + toastMsg("Failed", "error"); } }); } else { console.log(error); + toastMsg("Failed", "error"); } }); - // router.reload(window.location.pathname); - console.log("Moved to Library", id, volumeInfo); } }; @@ -113,12 +117,12 @@ export function BookDetails({ if (!error) { setRemoved(true); console.log(data); + toastMsg("Added to Wishlist"); } else { console.log(error); + toastMsg("Failed", "error"); } }); - // router.reload(window.location.pathname); - console.log("Added to Wishlist", id, volumeInfo); } }; @@ -131,12 +135,12 @@ export function BookDetails({ if (!error) { setRemoved(true); console.log(data); + toastMsg("Added to Library"); } else { console.log(error); + toastMsg("Failed", "error"); } }); - // router.reload(window.location.pathname); - console.log("Added to Library", id, volumeInfo); } }; @@ -145,17 +149,17 @@ export function BookDetails({ supabaseClient .from("book_wishlist") .delete() - .eq("g_id", id) + .eq("id", volumeInfo.id) .then(({ data, error }) => { if (!error) { setRemoved(true); console.log(data); + toastMsg("Deleted from Wishlist"); } else { console.log(error); + toastMsg("Failed", "error"); } }); - // router.reload(window.location.pathname); - console.log("Deleted from Wishlist", id, volumeInfo); } }; @@ -164,17 +168,17 @@ export function BookDetails({ supabaseClient .from("book_library") .delete() - .eq("g_id", id) + .eq("id", volumeInfo.id) .then(({ data, error }) => { if (!error) { setRemoved(true); console.log(data); + toastMsg("Deleted from Library"); } else { console.log(error); + toastMsg("Failed", "error"); } }); - // router.reload(window.location.pathname); - console.log("Deleted from Library", id, volumeInfo); } }; diff --git a/pages/library.js b/pages/library.js index 2def558..b2b6627 100644 --- a/pages/library.js +++ b/pages/library.js @@ -1,24 +1,15 @@ import * as React from "react"; -import Head from "next/head"; import { Text } from "@chakra-ui/react"; import { Avatar } from "@chakra-ui/react"; import { BookDetails } from "../components/BookDetails"; import { useRouter } from "next/router"; import { NextSeo } from "next-seo"; -import useSWR from "swr"; import { supabaseClient } from "../lib/client"; import { useEffect, useState } from "react"; -import { libStatus } from "../utils/listener"; - -const fetcher = (...args) => fetch(...args).then((res) => res.json()); function Library() { const router = useRouter(); const [data, setData] = React.useState([]); - const { data: bookData, error } = useSWR( - `https://www.googleapis.com/books/v1/volumes?q=George R R Martin&maxResults=15`, - fetcher - ); const [name, setName] = useState(""); const user = supabaseClient.auth.user(); @@ -48,10 +39,6 @@ function Library() { } }, [user]); - // React.useEffect(() => { - // if (bookData) setData(bookData.items); - // }, [bookData]); - return (