MCPcopy Create free account
hub / github.com/atomicdata-dev/atomic-data-browser / Data

Function Data

data-browser/src/routes/DataRoute.tsx:16–110  ·  view source on GitHub ↗

Renders the data of some Resource

()

Source from the content-addressed store, hash-verified

14
15/** Renders the data of some Resource */
16function Data(): JSX.Element {
17 const [subject] = useCurrentSubject();
18 const resource = useResource(subject);
19 const [textResponse, setTextResponse] = useState(null);
20 const [textResponseLoading, setTextResponseLoading] = useState(false);
21 const [err, setErr] = useState(null);
22 const { agent } = useSettings();
23 const store = useStore();
24
25 if (resource.loading) {
26 return <ContainerNarrow>Loading {subject}...</ContainerNarrow>;
27 }
28 if (resource.error) {
29 return (
30 <ContainerNarrow>
31 <ErrorLook>{resource.getError().message}</ErrorLook>
32 </ContainerNarrow>
33 );
34 }
35
36 async function fetchAs(contentType: string) {
37 let headers: HeadersInit = new Headers();
38 headers.set('Accept', contentType);
39 if (agent) {
40 headers = await signRequest(subject, agent, headers);
41 }
42 setTextResponseLoading(true);
43 try {
44 const resp = await window.fetch(subject, { headers });
45 const body = await resp.text();
46 setTextResponseLoading(false);
47 setTextResponse(body);
48 setErr(null);
49 } catch (e) {
50 setTextResponseLoading(false);
51 setErr(e);
52 }
53 }
54
55 return (
56 <ContainerNarrow about={subject}>
57 <h1>data view</h1>
58 <PropValRow columns>
59 <PropertyLabel title='The URL of the resource'>subject:</PropertyLabel>
60 <AtomicLink subject={subject}>{subject}</AtomicLink>
61 </PropValRow>
62 <AllProps resource={resource} editable columns />
63 {resource.getCommitBuilder().hasUnsavedChanges() ? (
64 <>
65 <h2>⚠️ contains uncommitted changes</h2>
66 <p>This means that (some) of your local changes are not yet saved.</p>
67 {resource.commitError && (
68 <ErrMessage>{resource.commitError.message}</ErrMessage>
69 )}
70 <Button onClick={() => resource.save(store)}>save</Button>
71 </>
72 ) : null}
73 <div>

Callers

nothing calls this directly

Calls 9

useCurrentSubjectFunction · 0.90
useResourceFunction · 0.90
useSettingsFunction · 0.90
useStoreFunction · 0.90
fetchAsFunction · 0.85
getErrorMethod · 0.80
hasUnsavedChangesMethod · 0.80
getCommitBuilderMethod · 0.80
saveMethod · 0.80

Tested by

no test coverage detected