Small UX improvements and basic mobile UI #3

Merged
olaven merged 1 commits from feat/ui-works-on-mobile into main 2023-03-10 13:00:57 +00:00
6 changed files with 55 additions and 26 deletions
Showing only changes of commit 84ac24e173 - Show all commits

View File

@ -1,12 +0,0 @@
import { JSX } from "preact";
import { IS_BROWSER } from "$fresh/runtime.ts";
export function Button(props: JSX.HTMLAttributes<HTMLButtonElement>) {
return (
<button
{...props}
disabled={!IS_BROWSER || props.disabled}
class="px-2 py-1 border(gray-100 2) hover:bg-gray-200"
/>
);
}

View File

@ -1,9 +1,9 @@
export default function Search(props: { defaultValue: string }) {
return (
<form className="flex flex-col w-1/2 mx-auto my-4">
<form className="flex flex-col w-full lg:w-2/3 mx-auto my-4">
<label className="sr-only" htmlFor="query">Program</label>
<input placeholder="NRK-podcast" className="border-2" name="query" id="query" defaultValue={props.defaultValue} />
<button type="submit" className="my-2 bg-gray-100">Søk</button>
<input placeholder="NRK-podcast" className="border-2 rounded-md px-2" name="query" id="query" defaultValue={props.defaultValue} />
<button type="submit" className="my-2 bg-gray-100 rounded-md">Søk</button>
</form>
);
}

View File

@ -1,14 +1,21 @@
import { Serie } from "../lib/nrk.ts"
import CopyButton from "../islands/CopyButton.tsx";
export function SerieCard(props: { serie: Serie, origin: string }) {
const feedUrl = new URL(`/api/feeds/${props.serie.seriesId}`, props.origin);
console.log(feedUrl.toString())
return (
<div className="border-2 my-2 mx-4">
<h2 className="text-4xl">{props.serie.title}</h2>
<p className="text-2xl">{props.serie.description}</p>
<div className="border-2 my-2 p-2">
<div className="mx-auto h-full w-full">
<h2 className="text-xl">{props.serie.title}</h2>
<p className="text-md">{props.serie.description}</p>
<img src={props.serie.images[0].uri} />
<p>Feed: {feedUrl.toString()}</p>
<CopyButton text={feedUrl.toString()}>
Kopier URL
</CopyButton>
</div>
</div >
);
}

View File

@ -6,6 +6,7 @@ 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/CopyButton.tsx";
const manifest = {
routes: {
@ -13,7 +14,9 @@ const manifest = {
"./routes/api/search.ts": $1,
"./routes/index.tsx": $2,
},
islands: {},
islands: {
"./islands/CopyButton.tsx": $$0,
},
baseUrl: import.meta.url,
config,
};

28
islands/CopyButton.tsx Normal file
View File

@ -0,0 +1,28 @@
import Preact from "preact";
import { useState } from "preact/hooks"
import { IS_BROWSER } from "$fresh/runtime.ts";
export default function CopyButton(props: { textBefore: string, textAfter: string } & Preact.PropsWithChildren) {
const [clicked, setClicked] = useState(false);
const startReset = () => {
setTimeout(() => {
setClicked(false);
}, 2_000);
}
return (
<button
onClick={() => {
navigator.clipboard.writeText(props.text.toString());
setClicked(true);
startReset();
}}
disabled={!IS_BROWSER || props.disabled}
class="px-2 py-1 border(gray-100 2) hover:bg-gray-200 mx-auto"
>
{clicked ? "Kopiert!" : props.children}
</button>
);
}

View File

@ -29,10 +29,13 @@ export default function Home({ data }: PageProps<HandlerData>) {
<title>NRSS</title>
</Head>
<div className="p-4 mx-auto max-w-screen-md bg-blue-400">
<h1 className="text-4xl text-center">NRSS - NRK-podcast som RSS</h1>
<div className="text-center">
<h1 className="text-2xl lg:text-3xl">NRSS</h1>
<h2 className="lg:text-xl">NRK-podcast som RSS</h2>
</div>
<Search defaultValue={data.query} />
{data.result ? (
<div className="w-1/2 mx-auto my-4">
<div className="w-full mx-auto my-4">
{data.result.map(result => <SerieCard serie={result} origin={data.origin} />)}
</div>
) : null}