diff --git a/pkg/view/src/components/PostItem.tsx b/pkg/view/src/components/PostItem.tsx index 240ad3d..2fdd92c 100644 --- a/pkg/view/src/components/PostItem.tsx +++ b/pkg/view/src/components/PostItem.tsx @@ -35,8 +35,14 @@ export default function PostItem(props: { setReacting(false); } - const element = ( - <> + const content = ( +
+ +
+ ); + + return ( +
@@ -59,9 +65,12 @@ export default function PostItem(props: {

{props.post.title}

-
- -
+ + +
+ {content} + +
@@ -92,7 +101,8 @@ export default function PostItem(props: { noControl post={props.post.repost_to} onError={props.onError} - onReact={props.onReact} /> + onReact={props.onReact} + />
@@ -105,7 +115,8 @@ export default function PostItem(props: { noControl post={props.post.reply_to} onError={props.onError} - onReact={props.onReact} /> + onReact={props.onReact} + />
@@ -170,20 +181,6 @@ export default function PostItem(props: {
- + ); - - if (props.noClick) { - return ( -
- {element} -
- ); - } else { - return ( - - {element} - - ); - } } \ No newline at end of file diff --git a/pkg/view/src/components/PostList.tsx b/pkg/view/src/components/PostList.tsx index e1581a9..ca7b91a 100644 --- a/pkg/view/src/components/PostList.tsx +++ b/pkg/view/src/components/PostList.tsx @@ -57,16 +57,18 @@ export default function PostList(props: {
- {item => readPosts()} - onError={props.onError} - />} + {item => + readPosts()} + onError={props.onError} + /> + }
diff --git a/pkg/view/src/pages/post.tsx b/pkg/view/src/pages/post.tsx index e0fc276..28d2a43 100644 --- a/pkg/view/src/pages/post.tsx +++ b/pkg/view/src/pages/post.tsx @@ -5,6 +5,7 @@ import { closeModel, openModel } from "../scripts/modals.ts"; import PostPublish from "../components/PostPublish.tsx"; import PostList from "../components/PostList.tsx"; import PostItem from "../components/PostItem.tsx"; +import { getAtk } from "../stores/userinfo.tsx"; export default function PostPage() { const [error, setError] = createSignal(null); @@ -37,6 +38,21 @@ export default function PostPage() { readPost(); + async function deletePost(item: any) { + if (!confirm(`Are you sure to delete post#${item.id}?`)) return; + + const res = await fetch(`/api/posts/${item.id}`, { + method: "DELETE", + headers: { "Authorization": `Bearer ${getAtk()}` } + }); + if (res.status !== 200) { + setError(await res.text()); + } else { + back(); + setError(null); + } + } + function setMeta(data: any, field: string, open = true) { const meta: { [id: string]: any } = { reposting: null, @@ -112,6 +128,7 @@ export default function PostPage() { post={info()} onError={setError} onReact={readPost} + onDelete={deletePost} onRepost={(item) => setMeta(item, "reposting")} onReply={(item) => setMeta(item, "replying")} onEdit={(item) => setMeta(item, "editing")}