Skip to content

Commit

Permalink
Merge pull request #78 from mbret/develop
Browse files Browse the repository at this point in the history
release
  • Loading branch information
mbret authored Feb 27, 2024
2 parents ec3338b + e3c7333 commit ae9fe13
Show file tree
Hide file tree
Showing 19 changed files with 584 additions and 284 deletions.
24 changes: 24 additions & 0 deletions packages/web/src/books/useUpdateBooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useMutation } from "reactjrx"
import { getLatestDatabase } from "../rxdb/useCreateDatabase"
import { from, mergeMap } from "rxjs"
import { MangoQuery } from "rxdb"
import { BookDocType } from "@oboku/shared"

export const useUpdateBooks = () => {
return useMutation({
mutationFn: ({
queryObj,
updateObj
}: {
queryObj: MangoQuery<BookDocType>
updateObj: any
}) =>
getLatestDatabase().pipe(
mergeMap((database) => {
const query = database.book.find(queryObj)

return from(query.update(updateObj))
})
)
})
}
234 changes: 0 additions & 234 deletions packages/web/src/collections/CollectionActionsDrawer.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/web/src/collections/CollectionDetailsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { useNavigate, useParams } from "react-router-dom"
import EmptyLibraryAsset from "../assets/empty-library.svg"
import CollectionBgSvg from "../assets/series-bg.svg"
import { useCollection } from "./states"
import { useCollectionActionsDrawer } from "./CollectionActionsDrawer"
import { BookListWithControls } from "../books/bookList/BookListWithControls"
import { useVisibleBookIds } from "../books/states"
import { useCollectionActionsDrawer } from "../library/collections/CollectionActionsDrawer/useCollectionActionsDrawer"

type ScreenParams = {
id: string
Expand Down
22 changes: 19 additions & 3 deletions packages/web/src/collections/list/CollectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ReactWindowList } from "../../common/lists/ReactWindowList"
import { CollectionListItemList } from "./CollectionListItemList"
import { CollectionDocType } from "@oboku/shared"
import { DeepReadonlyObject } from "rxdb"
import { useWindowSize } from "react-use"

export const CollectionList: FC<
{
Expand All @@ -28,9 +29,24 @@ export const CollectionList: FC<
`rowRenderer` | `itemsPerRow` | `data`
>
> = memo(({ itemMode, ...props }) => {
const { renderHeader, headerHeight, style, data, onItemClick, ...rest } =
props
const {
renderHeader,
viewMode,
headerHeight,
style,
data,
onItemClick,
...rest
} = props
const classes = useStyle()
const windowSize = useWindowSize()
const dynamicNumberOfItems = Math.floor(windowSize.width / 350)
const itemsPerRow =
viewMode === "grid"
? dynamicNumberOfItems > 0
? dynamicNumberOfItems
: dynamicNumberOfItems
: 1

const rowRenderer = useCallback(
(item: string) => (
Expand Down Expand Up @@ -63,7 +79,7 @@ export const CollectionList: FC<
<ReactWindowList
data={data}
rowRenderer={rowRenderer}
itemsPerRow={1}
itemsPerRow={itemsPerRow}
headerHeight={headerHeight}
renderHeader={renderHeader}
itemHeight={250}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { useCSS } from "../../common/utils"
import { MoreVert } from "@mui/icons-material"
import { CollectionDocType } from "@oboku/shared"
import { Cover } from "../../books/Cover"
import { useCollectionActionsDrawer } from "../CollectionActionsDrawer"
import { useCollection } from "../states"
import { DeepReadonlyObject } from "rxdb"
import { useCollectionActionsDrawer } from "../../library/collections/CollectionActionsDrawer/useCollectionActionsDrawer"

const ListItem = styled(MuiListItem)(() => ({
height: `100%`,
Expand Down
12 changes: 9 additions & 3 deletions packages/web/src/collections/useRemoveCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ export const useRemoveCollection = () => {
const { db } = useDatabase()

return useMutation({
mutationFn: async ({ _id }: { _id: string }) =>
db?.obokucollection.findOne({ selector: { _id } }).remove()
mutationFn: async ({ _id }: { _id: string }) => {
const document = await db?.obokucollection.findOne(_id).exec()

if (!document) throw new Error("no item")

return document.remove()
},
onError: console.error
})
}
}
49 changes: 49 additions & 0 deletions packages/web/src/collections/useUpdateCollectionBooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { useMutation } from "reactjrx"
import { getLatestDatabase } from "../rxdb/useCreateDatabase"
import { from, mergeMap } from "rxjs"
import { useUpdateBooks } from "../books/useUpdateBooks"

export const useUpdateCollectionBooks = () => {
const { mutateAsync: updateBooks } = useUpdateBooks()

return useMutation({
mutationFn: ({
id,
updateObj
}: {
id: string
updateObj: any
}) =>
getLatestDatabase().pipe(
mergeMap((database) =>
from(
database.obokucollection
.findOne({
selector: {
_id: {
$eq: id
}
}
})
.exec()
)
),
mergeMap((collection) => {
if (!collection) throw new Error("no item")

return from(
updateBooks({
queryObj: {
selector: {
_id: {
$in: collection.books
}
}
},
updateObj
})
)
})
)
})
}
Loading

0 comments on commit ae9fe13

Please sign in to comment.