import { useNavigate, useSearchParams } from "@solidjs/router"; import { createSignal, Show } from "solid-js"; import { createStore } from "solid-js/store"; import PostPublish from "../components/posts/PostPublish.tsx"; import PostList from "../components/posts/PostList.tsx"; import { closeModel, openModel } from "../scripts/modals.ts"; export default function SearchPage() { const [searchParams] = useSearchParams(); const [error, setError] = createSignal(null); const [page, setPage] = createSignal(0); const [info, setInfo] = createSignal(null); const navigate = useNavigate(); async function readPosts(pn?: number) { if (pn) setPage(pn); const res = await fetch("/api/posts?" + new URLSearchParams({ take: (10).toString(), offset: ((page() - 1) * 10).toString(), ...searchParams })); if (res.status !== 200) { setError(await res.text()); } else { setError(null); setInfo(await res.json()); } } function setMeta(data: any, field: string, open = true) { const meta: { [id: string]: any } = { reposting: null, replying: null, editing: null }; meta[field] = data; setPublishMeta(meta); if (open) openModel("#post-publish"); else closeModel("#post-publish"); } const [publishMeta, setPublishMeta] = createStore({ replying: null, reposting: null, editing: null }); function getDescribe() { let builder = []; if (searchParams["category"]) { builder.push("category is #" + searchParams["category"]); } else if (searchParams["tag"]) { builder.push("tag is #" + searchParams["tag"]); } return builder.join(" and "); } function back() { if (window.history.length > 0) { window.history.back(); } else { navigate("/"); } } return ( <>

Search

setMeta(item, "reposting")} onReply={(item) => setMeta(item, "replying")} onEdit={(item) => setMeta(item, "editing")} /> ); }