import { getAtk, useUserinfo } from "../stores/userinfo.tsx"; import { createSignal, For, Show } from "solid-js"; import styles from "./feed.module.css"; export default function DashboardPage() { const userinfo = useUserinfo(); const [error, setError] = createSignal(null); const [loading, setLoading] = createSignal(true); const [submitting, setSubmitting] = createSignal(false); const [posts, setPosts] = createSignal([]); const [postCount, setPostCount] = createSignal(0); const [page, setPage] = createSignal(1); async function readPosts() { setLoading(true); const res = await fetch("/api/posts?" + new URLSearchParams({ take: (10).toString(), skip: ((page() - 1) * 10).toString() })); if (res.status !== 200) { setError(await res.text()); } else { const data = await res.json(); setPosts(data["data"]); setPostCount(data["count"]); setError(null); } setLoading(false); } async function doPost(evt: SubmitEvent) { evt.preventDefault(); const form = evt.target as HTMLFormElement; const data = Object.fromEntries(new FormData(form)); if (!data.content) return; setSubmitting(true); const res = await fetch("/api/posts", { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${getAtk()}` }, body: JSON.stringify({ alias: data.alias ?? crypto.randomUUID().replace(/-/g, ""), title: data.title, content: data.content }) }); if (res.status !== 200) { setError(await res.text()); } else { await readPosts(); form.reset(); setError(null); } setSubmitting(false); } readPosts(); return (
{userinfo?.displayName.substring(0, 1)}}> avatar