diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8edf14..1dc9c2d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,4 +34,4 @@ jobs: run: deno lint - name: Test - run: deno task start && CHROME_BIN=$(which chrome) deno task test --quiet + run: deno task dev & deno task start && CHROME_BIN=$(which chrome) deno task test --quiet diff --git a/fresh.gen.ts b/fresh.gen.ts index 799a93f..438897e 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -3,10 +3,12 @@ // This file is automatically updated during development when running `dev.ts`. import * as $0 from "./routes/index.tsx"; +import * as $1 from "./routes/jobs/[job].tsx"; const manifest = { routes: { "./routes/index.tsx": $0, + "./routes/jobs/[job].tsx": $1, }, islands: {}, baseUrl: import.meta.url, diff --git a/routes/index.tsx b/routes/index.tsx index 6071486..c21cda0 100644 --- a/routes/index.tsx +++ b/routes/index.tsx @@ -1,7 +1,21 @@ /** @jsx h */ import { h } from "preact"; -export default function Home() { +import type { Handlers, PageProps } from "$fresh/server.ts"; + +export const handler: Handlers = { + async POST(req, ctx) { + const formData = await req.formData(); + + const job = formData.get("job") as string; + + return job + ? Response.redirect(`http://localhost:8000/jobs/${job}`) + : ctx.render("error: empty input"); + }, +}; + +export default function Home({ data }: PageProps) { return (
@@ -13,6 +27,13 @@ export default function Home() {

Skill Test (Software Engineer)

+ +
+ + +
+ + {data ?

{data}

: null}
); } diff --git a/routes/jobs/[job].tsx b/routes/jobs/[job].tsx new file mode 100644 index 0000000..e5aec33 --- /dev/null +++ b/routes/jobs/[job].tsx @@ -0,0 +1,18 @@ +/** @jsx h */ +import { h } from "preact"; + +import type { PageProps } from "$fresh/server.ts"; + +function searchJob(job: string) { + if (job === "engineer") { + return `Job "engineer" is open for you!`; + } + + return `Job "${job}" is not available`; +} + +export default function JobPage(props: PageProps) { + const { job } = props.params; + + return
{searchJob(job)}
; +}