parent
108b1d677b
commit
e3582de92b
@ -1 +1,13 @@ |
||||
export * from "./createLdoReactMethods"; |
||||
|
||||
export * from "./methods/useLdo"; |
||||
export * from "./methods/useMatchObject"; |
||||
export * from "./methods/useMatchSubject"; |
||||
export * from "./methods/useResource"; |
||||
export * from "./methods/useSubject"; |
||||
export * from "./methods/useSubscribeToResource"; |
||||
|
||||
export * from "./util/TrackingProxyContext"; |
||||
export * from "./util/TrackingSetProxy"; |
||||
export * from "./util/TrackingSubjectProxy"; |
||||
export * from "./util/useTrackingProxy"; |
||||
|
@ -1,31 +0,0 @@ |
||||
import type { Container, ContainerUri } from "@ldo/solid"; |
||||
import { useEffect, useState } from "react"; |
||||
import type { UseResourceOptions } from "./useResource"; |
||||
import { useResource } from "./useResource"; |
||||
import { useLdo } from "./SolidLdoProvider"; |
||||
|
||||
export function useRootContainerFor( |
||||
uri?: string, |
||||
options?: UseResourceOptions, |
||||
): Container | undefined { |
||||
const { getResource } = useLdo(); |
||||
|
||||
const [rootContainerUri, setRootContainerUri] = useState< |
||||
ContainerUri | undefined |
||||
>(undefined); |
||||
|
||||
useEffect(() => { |
||||
if (uri) { |
||||
const givenResource = getResource(uri); |
||||
givenResource.getRootContainer().then((result) => { |
||||
if (!result.isError) { |
||||
setRootContainerUri(result.uri); |
||||
} |
||||
}); |
||||
} else { |
||||
setRootContainerUri(undefined); |
||||
} |
||||
}, [uri]); |
||||
|
||||
return useResource(rootContainerUri, options); |
||||
} |
@ -0,0 +1,38 @@ |
||||
import { useEffect, useState } from "react"; |
||||
import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected"; |
||||
import type { |
||||
SolidConnectedPlugin, |
||||
SolidContainer, |
||||
SolidContainerUri, |
||||
SolidLeafUri, |
||||
} from "@ldo/connected-solid"; |
||||
import type { UseResourceOptions, createUseResource } from "@ldo/react"; |
||||
|
||||
export function createUseRootContainerFor( |
||||
dataset: ConnectedLdoDataset<SolidConnectedPlugin[]>, |
||||
useResource: ReturnType<typeof createUseResource<ConnectedPlugin[]>>, |
||||
) { |
||||
return function useRootContainerFor( |
||||
uri?: SolidContainerUri | SolidLeafUri, |
||||
options?: UseResourceOptions<"solid">, |
||||
): SolidContainer | undefined { |
||||
const [rootContainerUri, setRootContainerUri] = useState< |
||||
SolidContainerUri | undefined |
||||
>(undefined); |
||||
|
||||
useEffect(() => { |
||||
if (uri) { |
||||
const givenResource = dataset.getResource(uri); |
||||
givenResource.getRootContainer().then((result) => { |
||||
if (!result.isError) { |
||||
setRootContainerUri(result.uri); |
||||
} |
||||
}); |
||||
} else { |
||||
setRootContainerUri(undefined); |
||||
} |
||||
}, [uri]); |
||||
|
||||
return useResource(rootContainerUri, options) as SolidContainer | undefined; |
||||
}; |
||||
} |
Loading…
Reference in new issue