Skip to content

Commit

Permalink
fix: book cover
Browse files Browse the repository at this point in the history
  • Loading branch information
mbret committed Feb 24, 2024
1 parent 432d396 commit 18ef9af
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
12 changes: 8 additions & 4 deletions packages/web/src/books/bookList/BookListCoverContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { Cover } from "../Cover"
import { useBook, useIsBookProtected } from "../states"
import { ReadingStateState } from "@oboku/shared"
import { ReadingProgress } from "./ReadingProgress"
import { DownloadState, booksDownloadStateSignal } from "../../download/states"
import {
DownloadState,
booksDownloadStateSignal,
useBookDownloadState
} from "../../download/states"
import { useCSS } from "../../common/utils"
import { useSignalValue } from "reactjrx"

Expand All @@ -38,7 +42,7 @@ export const BookListCoverContainer: FC<{
withProtectedStatus = true
}) => {
const { data: item } = useBook({ id: bookId })
const bookDownloadState = useSignalValue(booksDownloadStateSignal)[bookId]
const bookDownloadState = useBookDownloadState(bookId)
const { data: isBookProtected = true } = useIsBookProtected(item)
const classes = useStyles({ item })

Expand Down Expand Up @@ -101,13 +105,13 @@ export const BookListCoverContainer: FC<{
/>
</div>
)}
{bookDownloadState?.downloadState === "none" && (
{bookDownloadState?.downloadState === DownloadState.None && (
<div style={classes.pauseButton}>
<CloudDownloadRounded color="action" fontSize={size} />
</div>
)}
{withDownloadStatus &&
bookDownloadState?.downloadState === "downloading" && (
bookDownloadState?.downloadState === DownloadState.Downloading && (
<div style={classes.pauseButton}>
<Chip color="primary" size="small" label="downloading..." />
</div>
Expand Down
17 changes: 14 additions & 3 deletions packages/web/src/download/states.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { signal } from "reactjrx"
import { signal, useSignalValue } from "reactjrx"

export enum DownloadState {
None = "none",
Expand All @@ -21,8 +21,7 @@ export const booksDownloadStateSignal = signal<
default: {}
})

export const normalizedBookDownloadsStatePersist =
booksDownloadStateSignal
export const normalizedBookDownloadsStatePersist = booksDownloadStateSignal

/**
* @deprecated
Expand All @@ -40,3 +39,15 @@ export const getBookDownloadsState = ({
downloadState: DownloadState.None,
downloadProgress: 0
}

export const useBookDownloadState = (bookId?: string | null) => {
const bookDownloadState = useSignalValue(booksDownloadStateSignal)

if (!bookId) return undefined

return {
downloadState: DownloadState.None,
downloadProgress: 0,
...bookDownloadState[bookId]
}
}
2 changes: 1 addition & 1 deletion packages/web/src/tags/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const useBlurredTagIds = () =>
queryKey: ["blurredTagIds"]
})

export const useProtectedTagIds = (options: { enabled?: boolean }) =>
export const useProtectedTagIds = (options: { enabled?: boolean } = {}) =>
useForeverQuery({
queryFn: () =>
protectedTags$.pipe(map((tags) => tags.map(({ _id }) => _id))),
Expand Down

0 comments on commit 18ef9af

Please sign in to comment.