parent
1ce4e46d50
commit
93514fd11a
@ -1,12 +1,16 @@ |
||||
import React from "react"; |
||||
import type { FunctionComponent } from "react"; |
||||
import { useParams } from "react-router-dom"; |
||||
import { useNavigate, useParams } from "react-router-dom"; |
||||
import { MediaPost } from "./MediaPost"; |
||||
|
||||
export const MediaPage: FunctionComponent = () => { |
||||
const navigate = useNavigate(); |
||||
const { uri } = useParams(); |
||||
if (!uri) { |
||||
return <p>No URI present</p>; |
||||
} |
||||
return <MediaPost uri={uri} />; |
||||
|
||||
return ( |
||||
<div> |
||||
<button onClick={() => navigate("/")}>Back to Feed</button> |
||||
{uri ? <MediaPost uri={uri} /> : <p>No URI Present</p>} |
||||
</div> |
||||
); |
||||
}; |
||||
|
@ -1,11 +1,42 @@ |
||||
import React from "react"; |
||||
import React, { useCallback } from "react"; |
||||
import type { FunctionComponent } from "react"; |
||||
import { useLdo, useResource, useSubject } from "@ldo/solid-react"; |
||||
import { PostShShapeType } from "../.ldo/post.shapeTypes"; |
||||
import { useNavigate } from "react-router-dom"; |
||||
import { PostedBy } from "./PostedBy"; |
||||
|
||||
export const MediaPost: FunctionComponent<{ uri: string }> = ({ uri }) => { |
||||
const navigate = useNavigate(); |
||||
const mediaResource = useResource(`${uri}index.ttl`); |
||||
const post = useSubject(PostShShapeType, mediaResource.uri); |
||||
const { getResource } = useLdo(); |
||||
const deletePost = useCallback(async () => { |
||||
const postContainer = getResource(uri); |
||||
const result = await postContainer.delete(); |
||||
if (result.isError) { |
||||
alert(result.message); |
||||
} |
||||
}, [uri]); |
||||
|
||||
if (mediaResource.isReading()) { |
||||
return <p>Loading Post...</p>; |
||||
} else if (mediaResource.status.isError) { |
||||
return <p>Error: {mediaResource.status.message}</p>; |
||||
} else if (mediaResource.isAbsent()) { |
||||
return <p>Post does not exist.</p>; |
||||
} |
||||
|
||||
return ( |
||||
<div> |
||||
<p>Media: {uri}</p> |
||||
<hr /> |
||||
{post.publisher?.["@id"] && <PostedBy webId={post.publisher["@id"]} />} |
||||
<div |
||||
onClick={() => navigate(`/media/${encodeURIComponent(uri)}`)} |
||||
style={{ cursor: "pointer" }} |
||||
> |
||||
{post.articleBody && <p>{post.articleBody}</p>} |
||||
{post.image && <img src={post.image["@id"]} style={{ height: 300 }} />} |
||||
</div> |
||||
<button onClick={deletePost}>Delete Post</button> |
||||
</div> |
||||
); |
||||
}; |
||||
|
@ -0,0 +1,16 @@ |
||||
import type { FunctionComponent } from "react"; |
||||
import React from "react"; |
||||
import { useResource, useSubject } from "@ldo/solid-react"; |
||||
import { SolidProfileShapeShapeType } from "../.ldo/solidProfile.shapeTypes"; |
||||
|
||||
export const PostedBy: FunctionComponent<{ webId: string }> = ({ webId }) => { |
||||
const webIdResource = useResource(webId); |
||||
const profile = useSubject(SolidProfileShapeShapeType, webId); |
||||
|
||||
if (webIdResource.isReading()) { |
||||
return <p>Loading Profile...</p>; |
||||
} else if (webIdResource.status.isError) { |
||||
return <p>Error: {webIdResource.status.message}</p>; |
||||
} |
||||
return <p>Posted By: {profile.fn}</p>; |
||||
}; |
Loading…
Reference in new issue