1
0
Fork 0
mirror of https://github.com/kou029w/quot.git synced 2025-01-19 16:38:06 +00:00
quot/app/views/pages/index.tsx

35 lines
897 B
TypeScript
Raw Normal View History

2022-08-24 17:43:32 +09:00
import { createResource, For } from "solid-js";
2022-09-01 23:54:20 +09:00
import type Pages from "../../protocol/pages";
2022-08-24 17:43:32 +09:00
import Cards from "../components/cards";
import Card from "../components/card";
2022-08-23 09:01:47 +09:00
2022-08-24 12:49:02 +09:00
async function fetchPages(): Promise<Pages.Response> {
const jwt = window.localStorage.getItem("jwt");
2022-08-29 01:02:47 +09:00
const res = await fetch(
2022-09-12 23:34:05 +09:00
`${import.meta.env.QUOT_API_ENDPOINT}/pages?order=updated.desc&limit=24`,
{ headers: jwt ? { authorization: `Bearer ${jwt}` } : {} }
2022-08-29 01:02:47 +09:00
);
2022-08-24 12:49:02 +09:00
const data = (await res.json()) as Pages.Response;
return data;
2022-08-23 09:01:47 +09:00
}
export default () => {
const [pages] = createResource("pages", fetchPages);
return (
<main>
2022-08-24 17:43:32 +09:00
{() => (
<Cards>
<For each={pages()}>
{(page) => (
2022-08-29 10:39:16 +09:00
<a href={`/${page.id.toString(16)}`}>
2022-08-24 17:43:32 +09:00
<Card {...page} />
</a>
)}
</For>
</Cards>
)}
2022-08-23 09:01:47 +09:00
</main>
);
};