♿ Fix UX in post list
This commit is contained in:
parent
8ea3e4763c
commit
a619f4ca23
@ -35,8 +35,14 @@ export default function PostItem(props: {
|
|||||||
setReacting(false);
|
setReacting(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const element = (
|
const content = (
|
||||||
<>
|
<article class="prose">
|
||||||
|
<SolidMarkdown children={props.post.content} />
|
||||||
|
</article>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class="post-item">
|
||||||
<Show when={!props.noAuthor}>
|
<Show when={!props.noAuthor}>
|
||||||
<a href={`/accounts/${props.post.author.name}`}>
|
<a href={`/accounts/${props.post.author.name}`}>
|
||||||
<div class="flex bg-base-200">
|
<div class="flex bg-base-200">
|
||||||
@ -59,9 +65,12 @@ export default function PostItem(props: {
|
|||||||
</Show>
|
</Show>
|
||||||
<div class="px-7">
|
<div class="px-7">
|
||||||
<h2 class="card-title">{props.post.title}</h2>
|
<h2 class="card-title">{props.post.title}</h2>
|
||||||
<article class="prose">
|
|
||||||
<SolidMarkdown children={props.post.content} />
|
<Show when={!props.noClick} fallback={content}>
|
||||||
</article>
|
<a href={`/posts/${props.post.id}`}>
|
||||||
|
{content}
|
||||||
|
</a>
|
||||||
|
</Show>
|
||||||
|
|
||||||
<div class="mt-2 flex gap-2">
|
<div class="mt-2 flex gap-2">
|
||||||
<For each={props.post.categories}>
|
<For each={props.post.categories}>
|
||||||
@ -92,7 +101,8 @@ export default function PostItem(props: {
|
|||||||
noControl
|
noControl
|
||||||
post={props.post.repost_to}
|
post={props.post.repost_to}
|
||||||
onError={props.onError}
|
onError={props.onError}
|
||||||
onReact={props.onReact} />
|
onReact={props.onReact}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
<Show when={!props.noRelated && props.post.reply_to}>
|
<Show when={!props.noRelated && props.post.reply_to}>
|
||||||
@ -105,7 +115,8 @@ export default function PostItem(props: {
|
|||||||
noControl
|
noControl
|
||||||
post={props.post.reply_to}
|
post={props.post.reply_to}
|
||||||
onError={props.onError}
|
onError={props.onError}
|
||||||
onReact={props.onReact} />
|
onReact={props.onReact}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
@ -170,20 +181,6 @@ export default function PostItem(props: {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
</>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (props.noClick) {
|
|
||||||
return (
|
|
||||||
<div class="post-item">
|
|
||||||
{element}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return (
|
|
||||||
<a class="post-item" href={`/posts/${props.post.id}`}>
|
|
||||||
{element}
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -57,16 +57,18 @@ export default function PostList(props: {
|
|||||||
<div id="post-list">
|
<div id="post-list">
|
||||||
<div id="posts">
|
<div id="posts">
|
||||||
<For each={posts()}>
|
<For each={posts()}>
|
||||||
{item => <PostItem
|
{item =>
|
||||||
post={item}
|
<PostItem
|
||||||
noRelated={props.noRelated}
|
post={item}
|
||||||
onRepost={props.onRepost}
|
noRelated={props.noRelated}
|
||||||
onReply={props.onReply}
|
onRepost={props.onRepost}
|
||||||
onEdit={props.onEdit}
|
onReply={props.onReply}
|
||||||
onDelete={deletePost}
|
onEdit={props.onEdit}
|
||||||
onReact={() => readPosts()}
|
onDelete={deletePost}
|
||||||
onError={props.onError}
|
onReact={() => readPosts()}
|
||||||
/>}
|
onError={props.onError}
|
||||||
|
/>
|
||||||
|
}
|
||||||
</For>
|
</For>
|
||||||
|
|
||||||
<div class="flex justify-center">
|
<div class="flex justify-center">
|
||||||
|
@ -5,6 +5,7 @@ import { closeModel, openModel } from "../scripts/modals.ts";
|
|||||||
import PostPublish from "../components/PostPublish.tsx";
|
import PostPublish from "../components/PostPublish.tsx";
|
||||||
import PostList from "../components/PostList.tsx";
|
import PostList from "../components/PostList.tsx";
|
||||||
import PostItem from "../components/PostItem.tsx";
|
import PostItem from "../components/PostItem.tsx";
|
||||||
|
import { getAtk } from "../stores/userinfo.tsx";
|
||||||
|
|
||||||
export default function PostPage() {
|
export default function PostPage() {
|
||||||
const [error, setError] = createSignal<string | null>(null);
|
const [error, setError] = createSignal<string | null>(null);
|
||||||
@ -37,6 +38,21 @@ export default function PostPage() {
|
|||||||
|
|
||||||
readPost();
|
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) {
|
function setMeta(data: any, field: string, open = true) {
|
||||||
const meta: { [id: string]: any } = {
|
const meta: { [id: string]: any } = {
|
||||||
reposting: null,
|
reposting: null,
|
||||||
@ -112,6 +128,7 @@ export default function PostPage() {
|
|||||||
post={info()}
|
post={info()}
|
||||||
onError={setError}
|
onError={setError}
|
||||||
onReact={readPost}
|
onReact={readPost}
|
||||||
|
onDelete={deletePost}
|
||||||
onRepost={(item) => setMeta(item, "reposting")}
|
onRepost={(item) => setMeta(item, "reposting")}
|
||||||
onReply={(item) => setMeta(item, "replying")}
|
onReply={(item) => setMeta(item, "replying")}
|
||||||
onEdit={(item) => setMeta(item, "editing")}
|
onEdit={(item) => setMeta(item, "editing")}
|
||||||
|
Loading…
Reference in New Issue
Block a user