-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from bookracy/feature/bookmarks
add bookmarks, disable certain pages on prod
- Loading branch information
Showing
13 changed files
with
150 additions
and
16 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
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,27 @@ | ||
import { BookItemResponse } from "@/api/backend/types"; | ||
import { useBookmarksStore } from "@/stores/bookmarks"; | ||
import { Button } from "../ui/button"; | ||
import { useMemo } from "react"; | ||
import { BookmarkMinus, BookmarkPlus } from "lucide-react"; | ||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip"; | ||
|
||
export function BookmarkButton({ book }: { book: BookItemResponse }) { | ||
const bookmarks = useBookmarksStore((state) => state.bookmarks); | ||
const addBookmark = useBookmarksStore((state) => state.addBookmark); | ||
const removeBookmark = useBookmarksStore((state) => state.removeBookmark); | ||
|
||
const bookMarkedBook = useMemo(() => bookmarks.find((b) => b.md5 === book.md5), [bookmarks, book.md5]); | ||
|
||
return ( | ||
<TooltipProvider delayDuration={0}> | ||
<Tooltip> | ||
<TooltipTrigger asChild> | ||
<Button size="icon" onClick={() => (bookMarkedBook ? removeBookmark(bookMarkedBook.md5) : addBookmark(book))} className="flex items-center gap-2"> | ||
{bookMarkedBook ? <BookmarkMinus className="h-5 w-5" /> : <BookmarkPlus className="h-5 w-5" />} | ||
</Button> | ||
</TooltipTrigger> | ||
<TooltipContent>{bookMarkedBook ? "Remove bookmark" : "Add bookmark"}</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
); | ||
} |
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
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
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
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,25 @@ | ||
import { BookItem } from "@/components/books/book-item"; | ||
import { useBookmarksStore } from "@/stores/bookmarks"; | ||
import { createFileRoute } from "@tanstack/react-router"; | ||
|
||
export const Route = createFileRoute("/lists")({ | ||
component: Lists, | ||
}); | ||
|
||
export function Lists() { | ||
const bookmarks = useBookmarksStore((state) => state.bookmarks); | ||
|
||
return ( | ||
<div className="flex flex-1 justify-center"> | ||
<div className="flex w-full flex-col gap-4"> | ||
{bookmarks.length > 0 ? <h1 className="text-2xl font-bold">Your Bookmarks</h1> : null} | ||
|
||
<div className="grid grid-cols-2 gap-4"> | ||
{bookmarks.map((bookmark) => ( | ||
<BookItem key={bookmark.md5} {...bookmark} /> | ||
))} | ||
</div> | ||
</div> | ||
</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
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
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,23 @@ | ||
import { BookItemResponse } from "@/api/backend/types"; | ||
import { create } from "zustand"; | ||
import { persist } from "zustand/middleware"; | ||
|
||
interface BookmarksStoreState { | ||
bookmarks: BookItemResponse[]; | ||
addBookmark: (bookmark: BookItemResponse) => void; | ||
removeBookmark: (md5: string) => void; | ||
} | ||
|
||
export const useBookmarksStore = create<BookmarksStoreState>()( | ||
persist( | ||
(set) => ({ | ||
bookmarks: [], | ||
addBookmark: (bookmark) => set((state) => ({ bookmarks: [...state.bookmarks, bookmark] })), | ||
removeBookmark: (md5) => set((state) => ({ bookmarks: state.bookmarks.filter((b) => b.md5 !== md5) })), | ||
}), | ||
{ | ||
name: "BR::bookmarks", | ||
getStorage: () => localStorage, | ||
}, | ||
), | ||
); |