import { createMemo, createSignal, For, Show } from "solid-js"; import styles from "./PostList.module.css"; import PostItem from "./PostItem.tsx"; import { getAtk } from "../stores/userinfo.tsx"; export default function PostList(props: { noRelated?: boolean, info: { data: any[], count: number } | null, onRepost?: (post: any) => void, onReply?: (post: any) => void, onEdit?: (post: any) => void, onUpdate: (pn: number, filter?: any) => Promise, onError: (message: string | null) => void }) { const [loading, setLoading] = createSignal(true); const posts = createMemo(() => props.info?.data); const postCount = createMemo(() => props.info?.count ?? 0); const [page, setPage] = createSignal(1); const pageCount = createMemo(() => Math.ceil(postCount() / 10)); async function readPosts(filter?: any) { setLoading(true); await props.onUpdate(page(), filter); setLoading(false); } readPosts(); async function deletePost(item: any) { if (!confirm(`Are you sure to delete post#${item.id}?`)) return; setLoading(true); const res = await fetch(`/api/posts/${item.id}`, { method: "DELETE", headers: { "Authorization": `Bearer ${getAtk()}` } }); if (res.status !== 200) { props.onError(await res.text()); } else { await readPosts(); props.onError(null); } setLoading(false); } function changePage(pn: number) { setPage(pn); readPosts().then(() => { setTimeout(() => window.scrollTo({ top: 0, behavior: "smooth" }), 16); }); } return (
{item => readPosts()} onError={props.onError} /> }

Creating fake news...

); }