|
1 |
| -/** @jsx h */ |
2 |
| -/** @jsxFrag Fragment */ |
3 |
| - |
4 |
| -import { h, tw, useEffect, useState } from "../client_deps.ts"; |
5 |
| - |
| 1 | +import { useEffect, useState } from "preact/hooks"; |
| 2 | +import Placeholder from "../components/Placeholder.tsx"; |
| 3 | +import * as marked from "https://cdn.jsdelivr.net/npm/marked/marked.min.js"; |
6 | 4 | // deno-lint-ignore no-explicit-any
|
7 |
| -function Card({name, description}: any) { |
8 |
| - const title = tw`px-4 py-3 mb-4 font-bold text(2xl gray-900 center)`; |
9 |
| - const subtitle = tw`px-4 py-3 mb-4 text(xl gray-600 center)`; |
| 5 | +function Card({name, summary, description, version, source_code}: any) { |
| 6 | + const title = `px-4 py-3 mb-4 font-bold text(2xl gray-900 center)`; |
| 7 | + const subtitle = `px-4 py-3 mb-4 text(xl gray-600 center)`; |
| 8 | + const descript = `px-4 py-3 mb-4 text(lg gray-400 center) mt-4 max-h-24 overflow-y-auto`; |
| 9 | + const num = `px-2 py-2 mb-4 font-bold text(sm gray-500 center)`; |
10 | 10 |
|
11 | 11 | return (
|
12 | 12 | <div>
|
13 |
| - <div class={title}>{name}</div> |
14 |
| - <div class={subtitle}>{description}</div> |
| 13 | + <div class={title}>{name} <a class={`bi bi-github`} href={source_code} style="font-size: 1rem;" ></a> <a class={num}>v.{version}</a></div> |
| 14 | + <div class={subtitle}>{summary}</div> |
| 15 | + |
| 16 | + <div class={descript} dangerouslySetInnerHTML={{ __html: marked.parse(description) }}></div> |
15 | 17 | </div>
|
16 | 18 | );
|
17 | 19 | }
|
18 | 20 |
|
19 | 21 | export default function Module({name}:any) {
|
20 |
| - const [data, setData] = useState(<div>loading...</div> as h.JSX.Element); |
21 |
| - const container = tw`max-w-screen-sm mx-auto px(4 sm:4 md:4) space-y-3`; |
| 22 | + const [data, setData] = useState(<Placeholder /> as h.JSX.Element); |
| 23 | + const container = `max-w-screen-sm mx-auto px(4 sm:4 md:4) space-y-3`; |
22 | 24 | useEffect(() => {
|
23 | 25 | fetch(
|
24 | 26 | `https://pypi.org/pypi/${name}/json/`,
|
25 | 27 | )
|
26 | 28 | .then((r) => r.json())
|
27 | 29 | .then((r) => {
|
28 |
| - console.log(r) |
29 |
| - setData(<Card name={r.info.name} description={r.info.summary} />); |
| 30 | + setData(<Card name={r.info.name} summary={r.info.summary} description={r.info.description} version={r.info.version} source_code={r.info.project_urls["Source Code"]}/>); |
30 | 31 | });
|
31 | 32 | }, []);
|
32 | 33 | return (
|
33 |
| - <div class={container} onLoad={() => setData(<div>loading...</div> as h.JSX.Element)}> |
| 34 | + <div class={container} onLoad={() => setData(<Placeholder /> as h.JSX.Element)}> |
34 | 35 | {data}
|
35 | 36 | </div>
|
36 | 37 | );
|
|
0 commit comments