parent
a603cc02f4
commit
8ce936a901
File diff suppressed because it is too large
Load Diff
@ -1,10 +1,38 @@ |
|||||||
import React from "react"; |
import React, { useCallback, useEffect, useMemo } from "react"; |
||||||
import type { FunctionComponent } from "react"; |
import type { FunctionComponent } from "react"; |
||||||
|
import { UploadButton } from "./UploadButton"; |
||||||
|
import { useSolidAuth } from "@ldo/solid-react"; |
||||||
|
|
||||||
export const Dashboard: FunctionComponent = () => { |
export const Dashboard: FunctionComponent = () => { |
||||||
|
const { session } = useSolidAuth(); |
||||||
|
|
||||||
|
const containerUri = useMemo(() => { |
||||||
|
if (!session.webId) return ""; |
||||||
|
// HACK: this is a hard coded hack to find the root container. Solid doesn't
|
||||||
|
// have an official way of doing this.
|
||||||
|
const rootContainer = session.webId.replace("profile/card#me", ""); |
||||||
|
return `${rootContainer}demo-ldo/`; |
||||||
|
}, [session.webId]); |
||||||
|
|
||||||
|
// const mainContainer = useContainerResource(containerUri);
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// // Upon load check to see if the root folder exists
|
||||||
|
// mainContainer.checkExists().then(async (doesExist) => {
|
||||||
|
// // If not, create it
|
||||||
|
// if (!doesExist) {
|
||||||
|
// await mainContainer.create();
|
||||||
|
// const accessRules = mainContainer.accessRules;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }, [mainContainer]);
|
||||||
|
|
||||||
return ( |
return ( |
||||||
<div> |
<div> |
||||||
<p>Dashboard</p> |
<div> |
||||||
|
<UploadButton /> |
||||||
|
</div> |
||||||
|
<hr /> |
||||||
</div> |
</div> |
||||||
); |
); |
||||||
}; |
}; |
||||||
|
@ -0,0 +1,10 @@ |
|||||||
|
import React, { useCallback } from "react"; |
||||||
|
import type { FunctionComponent } from "react"; |
||||||
|
|
||||||
|
export const UploadButton: FunctionComponent = () => { |
||||||
|
const upload = useCallback(() => { |
||||||
|
const _message = prompt("Type a message for your post"); |
||||||
|
}, []); |
||||||
|
|
||||||
|
return <button onClick={upload}>Make a New Post</button>; |
||||||
|
}; |
@ -0,0 +1,20 @@ |
|||||||
|
import { useMemo } from "react"; |
||||||
|
import type { UseDocumentOptions } from "./useDocument"; |
||||||
|
import { useTrackStateUpdate } from "./useDocument"; |
||||||
|
import type { Resource } from "@ldo/solid"; |
||||||
|
import { useSolidLdoDataset } from "../SolidLdoProvider"; |
||||||
|
|
||||||
|
export function useAccessRules( |
||||||
|
resource: string | Resource, |
||||||
|
options?: UseDocumentOptions, |
||||||
|
) { |
||||||
|
const solidLdoDataset = useSolidLdoDataset(); |
||||||
|
|
||||||
|
const document = useMemo(() => { |
||||||
|
return solidLdoDataset.getAccessRules(resource); |
||||||
|
}, [resource, solidLdoDataset]); |
||||||
|
|
||||||
|
useTrackStateUpdate(document, options); |
||||||
|
|
||||||
|
return document; |
||||||
|
} |
@ -0,0 +1,16 @@ |
|||||||
|
import { useMemo } from "react"; |
||||||
|
import { useSolidLdoDataset } from "../SolidLdoProvider"; |
||||||
|
import type { UseDocumentOptions } from "./useDocument"; |
||||||
|
import { useTrackStateUpdate } from "./useDocument"; |
||||||
|
|
||||||
|
export function useBinaryResource(uri: string, options?: UseDocumentOptions) { |
||||||
|
const solidLdoDataset = useSolidLdoDataset(); |
||||||
|
|
||||||
|
const document = useMemo(() => { |
||||||
|
return solidLdoDataset.getBinaryResource(uri); |
||||||
|
}, [uri, solidLdoDataset]); |
||||||
|
|
||||||
|
useTrackStateUpdate(document, options); |
||||||
|
|
||||||
|
return document; |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
import { useMemo } from "react"; |
||||||
|
import type { UseDocumentOptions } from "./useDocument"; |
||||||
|
import { useTrackStateUpdate } from "./useDocument"; |
||||||
|
import { useSolidLdoDataset } from "../SolidLdoProvider"; |
||||||
|
|
||||||
|
export function useContainerResource( |
||||||
|
uri: string, |
||||||
|
options?: UseDocumentOptions, |
||||||
|
) { |
||||||
|
const solidLdoDataset = useSolidLdoDataset(); |
||||||
|
|
||||||
|
const document = useMemo(() => { |
||||||
|
return solidLdoDataset.getContainerResource(uri); |
||||||
|
}, [uri, solidLdoDataset]); |
||||||
|
|
||||||
|
useTrackStateUpdate(document, options); |
||||||
|
|
||||||
|
return document; |
||||||
|
} |
@ -0,0 +1,16 @@ |
|||||||
|
import { useMemo } from "react"; |
||||||
|
import { useSolidLdoDataset } from "../SolidLdoProvider"; |
||||||
|
import type { UseDocumentOptions } from "./useDocument"; |
||||||
|
import { useTrackStateUpdate } from "./useDocument"; |
||||||
|
|
||||||
|
export function useDataResource(uri: string, options?: UseDocumentOptions) { |
||||||
|
const solidLdoDataset = useSolidLdoDataset(); |
||||||
|
|
||||||
|
const document = useMemo(() => { |
||||||
|
return solidLdoDataset.getDataResource(uri); |
||||||
|
}, [uri, solidLdoDataset]); |
||||||
|
|
||||||
|
useTrackStateUpdate(document, options); |
||||||
|
|
||||||
|
return document; |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
import { useEffect } from "react"; |
||||||
|
import type { FetchableDocument } from "@ldo/solid"; |
||||||
|
import { useForceUpdate } from "../util/useForceReload"; |
||||||
|
|
||||||
|
export interface UseDocumentOptions { |
||||||
|
suppressLoadOnMount: boolean; |
||||||
|
} |
||||||
|
|
||||||
|
export function useTrackStateUpdate( |
||||||
|
document: FetchableDocument, |
||||||
|
options?: UseDocumentOptions, |
||||||
|
) { |
||||||
|
const forceUpdate = useForceUpdate(); |
||||||
|
|
||||||
|
useEffect(() => { |
||||||
|
// Set up the listener for state update
|
||||||
|
function onStateUpdateCallback() { |
||||||
|
forceUpdate(); |
||||||
|
} |
||||||
|
document.onStateUpdate(onStateUpdateCallback); |
||||||
|
// Load the resource if load on mount is true
|
||||||
|
if (!options?.suppressLoadOnMount) { |
||||||
|
document.read(); |
||||||
|
} |
||||||
|
return () => document.offStateUpdate(onStateUpdateCallback); |
||||||
|
}, []); |
||||||
|
} |
@ -1,2 +1,8 @@ |
|||||||
export * from "./BrowserSolidLdoProvider"; |
export * from "./BrowserSolidLdoProvider"; |
||||||
export * from "./SolidAuthContext"; |
export * from "./SolidAuthContext"; |
||||||
|
|
||||||
|
// documentHooks
|
||||||
|
export * from "./documentHooks/useAccessRules"; |
||||||
|
export * from "./documentHooks/useBinaryResource"; |
||||||
|
export * from "./documentHooks/useContainerResource"; |
||||||
|
export * from "./documentHooks/useDataResource"; |
||||||
|
@ -0,0 +1,6 @@ |
|||||||
|
import { useState } from "react"; |
||||||
|
|
||||||
|
export function useForceUpdate() { |
||||||
|
const [, setValue] = useState(0); |
||||||
|
return () => setValue((value) => value + 1); |
||||||
|
} |
@ -1,11 +0,0 @@ |
|||||||
import type { FetchableDocument } from "../FetchableDocument"; |
|
||||||
import { DocumentError } from "./DocumentError"; |
|
||||||
|
|
||||||
export class DocumentFetchError extends DocumentError { |
|
||||||
public readonly status: number; |
|
||||||
|
|
||||||
constructor(document: FetchableDocument, status: number, message: string) { |
|
||||||
super(document, message); |
|
||||||
this.status = status; |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue