diff --git a/components/Search.tsx b/components/Search.tsx new file mode 100644 index 0000000..a6ce800 --- /dev/null +++ b/components/Search.tsx @@ -0,0 +1,9 @@ +export default function Search(props: {defaultValue: string}) { + return ( +
+ + + +
+ ); +} diff --git a/components/SeriesCard.tsx b/components/SeriesCard.tsx index 244051a..d74ce01 100644 --- a/components/SeriesCard.tsx +++ b/components/SeriesCard.tsx @@ -1,13 +1,14 @@ import { Serie } from "../lib/nrk.ts" -export function SerieCard(props: { serie: Serie }) { +export function SerieCard(props: { serie: Serie, origin: string }) { + const feedUrl = new URL(`/api/feeds/${props.serie.seriesId}`, props.origin); - return
-

{props.serie.title}

-

{props.serie.description}

- -

- Feed: https://{location.hostname}{`/api/feeds/${props.serie.seriesId}`} -

-
; + return ( +
+

{props.serie.title}

+

{props.serie.description}

+ +

Feed: {feedUrl.toString()}

+
+ ); } diff --git a/fresh.gen.ts b/fresh.gen.ts index 8ef575a..756abf4 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -6,8 +6,6 @@ import config from "./deno.json" assert { type: "json" }; import * as $0 from "./routes/api/feeds/[seriesId].ts"; import * as $1 from "./routes/api/search.ts"; import * as $2 from "./routes/index.tsx"; -import * as $$0 from "./islands/Counter.tsx"; -import * as $$1 from "./islands/Search.tsx"; const manifest = { routes: { @@ -15,10 +13,7 @@ const manifest = { "./routes/api/search.ts": $1, "./routes/index.tsx": $2, }, - islands: { - "./islands/Counter.tsx": $$0, - "./islands/Search.tsx": $$1, - }, + islands: {}, baseUrl: import.meta.url, config, }; diff --git a/islands/Counter.tsx b/islands/Counter.tsx deleted file mode 100644 index 1b437bf..0000000 --- a/islands/Counter.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import { useState } from "preact/hooks"; -import { Button } from "../components/Button.tsx"; - -interface CounterProps { - start: number; -} - -export default function Counter(props: CounterProps) { - const [count, setCount] = useState(props.start); - return ( -
-

{count}

- - -
- ); -} diff --git a/islands/Search.tsx b/islands/Search.tsx deleted file mode 100644 index 5e3ee4c..0000000 --- a/islands/Search.tsx +++ /dev/null @@ -1,37 +0,0 @@ - -import { Head } from "$fresh/runtime.ts"; -import { useState } from "preact/hooks"; -import { post, OK } from "https://deno.land/x/kall@v0.1.0/mod.ts"; -import { Serie } from "../lib/nrk.ts"; -import { SerieCard } from "../components/SeriesCard.tsx"; - -export default function Search() { - - const [query, setQuery] = useState(""); - const [result, setResult] = useState([]); - - const onSearch = async (event: any) => { - - const [status, response] = await post("/api/search", { - query - }); - - setResult(response.series as Serie[]) - } - - return ( -
- { setQuery(event.target.value) }} /> - -
- {result.map(result => )} -
-
- ); -} diff --git a/routes/index.tsx b/routes/index.tsx index 098a487..e5a6b4f 100644 --- a/routes/index.tsx +++ b/routes/index.tsx @@ -1,10 +1,29 @@ import { Head } from "$fresh/runtime.ts"; -import { useState } from "preact/hooks"; -import { post, OK } from "https://deno.land/x/kall@v0.1.0/mod.ts"; -import Search from "../islands/Search.tsx" +import { Handlers, PageProps } from "$fresh/server.ts"; +import Search from "../components/Search.tsx" +import { SerieCard } from "../components/SeriesCard.tsx"; +import { nrkRadio, Serie } from "../lib/nrk.ts"; -export default function Home() { +interface HandlerData { + query: string; + result?: Serie[]; + origin: string; +} +export const handler: Handlers = { + async GET(request, ctx) { + const url = new URL(request.url); + console.log(url) + const query = url.searchParams.get("query"); + let result: Serie[] | undefined; + if (query) { + result = await nrkRadio.search(query); + } + return ctx.render({ query: query || "", result, origin: url.origin }); + }, + }; + +export default function Home({ data }: PageProps) { return ( <> @@ -12,7 +31,12 @@ export default function Home() {

NRSS - NRK-podcast som RSS

- + + {data.result ? ( +
+ {data.result.map(result => )} +
+ ) : null}

Hva er dette?

Hei! Denne løsningen er laget som en reaksjon på at statsfinnansierte NRK lukker ned innholdet sitt til sin egen app fremfor å bygge oppunder åpne standarder som RSS. Denne siden er laget i dag (09.03.23), fort og gæli - den er ustabil og kommer til å krasje :) Sjekk gjerne ut kildekoden.

Hvordan bruker jeg dette?