Skip to content

Commit

Permalink
Merge pull request #167 from mbret/develop
Browse files Browse the repository at this point in the history
fix: tsc
  • Loading branch information
mbret authored Jul 28, 2024
2 parents f8604cf + 48115de commit dd187fa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/web/src/books/states.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { intersection } from "lodash"
import { useProtectedTagIds, useTagsByIds } from "../tags/helpers"
import { getLinkState, useLink, useLinks } from "../links/states"
import { getLinkState, useLink, useLinksDic } from "../links/states"
import {
getBookDownloadsState,
booksDownloadStateSignal
Expand Down Expand Up @@ -175,7 +175,7 @@ export const getEnrichedBookState = ({
>
protectedTagIds: ReturnType<typeof useProtectedTagIds>["data"]
tags: ReturnType<typeof useTagsByIds>["data"]
normalizedLinks: ReturnType<typeof useLinks>["data"]
normalizedLinks: ReturnType<typeof useLinksDic>["data"]
normalizedCollections: CollectionDocType[] | undefined
normalizedBooks: ReturnType<typeof useBooksDic>["data"]
}) => {
Expand Down Expand Up @@ -248,7 +248,7 @@ export const useEnrichedBookState = ({
protectedTagIds: ReturnType<typeof useProtectedTagIds>["data"]
tags: ReturnType<typeof useTagsByIds>["data"]
}) => {
const { data: normalizedLinks } = useLinks()
const { data: normalizedLinks } = useLinksDic()
const { data: normalizedCollections } = useCollections()
const { data: normalizedBooks } = useBooksDic()

Expand Down Expand Up @@ -330,7 +330,7 @@ export const useBookLinksState = ({
tags: ReturnType<typeof useTagsByIds>["data"]
}) => {
const book = useBookState({ bookId, tags })
const { data: links } = useLinks()
const { data: links } = useLinksDic()

return book?.links?.map((id) => getLinkState(links, id)) || []
}
Expand Down
18 changes: 15 additions & 3 deletions packages/web/src/links/states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ export const getLinksByIds = async (database: Database) => {

export const useLinks = () => {
return useForeverQuery({
queryKey: ["rxdb", "get", "many", "link"],
queryKey: ["rxdb", "get", "many", "links/list"],
queryFn: () => {
return latestDatabase$.pipe(
switchMap((db) => db.collections.link.find({}).$),
map((entries) => entries.map((item) => item.toJSON()))
)
}
})
}

export const useLinksDic = () => {
return useForeverQuery({
queryKey: ["rxdb", "get", "many", "links/dic"],
queryFn: () => {
return latestDatabase$.pipe(
switchMap((db) => db.collections.link.find({}).$),
Expand Down Expand Up @@ -57,7 +69,7 @@ const mapLinkTtoState = ({ link }: { link?: LinkDocType | null }) => {
}

export const getLinkState = (
linksState: ReturnType<typeof useLinks>["data"] = {},
linksState: ReturnType<typeof useLinksDic>["data"] = {},
linkId: string
) => {
const link = Object.values(linksState).find((link) => link?._id === linkId)
Expand Down Expand Up @@ -87,7 +99,7 @@ export const getLinkStateAsync = async ({
* @todo optimize to refresh only when link id change
*/
export const useLinkState = (linkId: string) => {
const { data: links = {} } = useLinks()
const { data: links = {} } = useLinksDic()

const link = Object.values(links).find((link) => link?._id === linkId)

Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/problems/useRepair.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BookDocType, CollectionDocType } from "@oboku/shared"
import { useMutation } from "reactjrx"
import { first, from, map, mergeMap, of } from "rxjs"
import { latestDatabase$ } from "../rxdb/RxDbProvider"
import { DeepReadonlyObject } from "rxdb"
import { latestDatabase$ } from "../rxdb/useCreateDatabase"

export const useRepair = () => {
return useMutation({
Expand Down

0 comments on commit dd187fa

Please sign in to comment.