1
0
Fork 0
mirror of https://github.com/kou029w/quot.git synced 2025-01-19 08:28:09 +00:00
quot/app/views/pages/index.tsx
2022-09-12 23:34:05 +09:00

34 lines
897 B
TypeScript

import { createResource, For } from "solid-js";
import type Pages from "../../protocol/pages";
import Cards from "../components/cards";
import Card from "../components/card";
async function fetchPages(): Promise<Pages.Response> {
const jwt = window.localStorage.getItem("jwt");
const res = await fetch(
`${import.meta.env.QUOT_API_ENDPOINT}/pages?order=updated.desc&limit=24`,
{ headers: jwt ? { authorization: `Bearer ${jwt}` } : {} }
);
const data = (await res.json()) as Pages.Response;
return data;
}
export default () => {
const [pages] = createResource("pages", fetchPages);
return (
<main>
{() => (
<Cards>
<For each={pages()}>
{(page) => (
<a href={`/${page.id.toString(16)}`}>
<Card {...page} />
</a>
)}
</For>
</Cards>
)}
</main>
);
};