Skip to content

Commit

Permalink
Merge branch 'main' into harden-headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jabolol authored Sep 20, 2023
2 parents 7dfdf4a + c6229a4 commit 1f981be
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 95 deletions.
14 changes: 7 additions & 7 deletions routes/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
import { AppProps } from "$fresh/server.ts";
import Header from "@/components/Header.tsx";
import Footer from "@/components/Footer.tsx";
import type { State } from "@/middleware/session.ts";
import { defineApp } from "$fresh/server.ts";

export default function App(props: AppProps<undefined, State>) {
export default defineApp<State>((_, ctx) => {
return (
<div class="dark:bg-gray-900">
<div class="flex flex-col min-h-screen mx-auto max-w-7xl w-full dark:text-white">
<Header
url={props.url}
sessionUser={props.state?.sessionUser}
url={ctx.url}
sessionUser={ctx.state?.sessionUser}
/>
<props.Component />
<Footer url={props.url} />
<ctx.Component />
<Footer url={ctx.url} />
</div>
</div>
);
}
});
12 changes: 5 additions & 7 deletions routes/account/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
import type { PageProps } from "$fresh/server.ts";
import { defineRoute } from "$fresh/server.ts";
import type { SignedInState } from "@/middleware/session.ts";
import { BUTTON_STYLES } from "@/utils/constants.ts";
import { isStripeEnabled } from "@/utils/stripe.ts";
import Head from "@/components/Head.tsx";
import GitHubAvatarImg from "@/components/GitHubAvatarImg.tsx";

export default function AccountPage(
props: PageProps<undefined, SignedInState>,
) {
const { sessionUser } = props.state;
export default defineRoute<SignedInState>((_req, ctx) => {
const { sessionUser } = ctx.state;
const action = sessionUser.isSubscribed ? "Manage" : "Upgrade";

return (
<>
<Head title="Account" href={props.url.href} />
<Head title="Account" href={ctx.url.href} />
<main class="max-w-lg m-auto w-full flex-1 p-4 flex flex-col justify-center">
<GitHubAvatarImg
login={sessionUser.login}
Expand Down Expand Up @@ -60,4 +58,4 @@ export default function AccountPage(
</main>
</>
);
}
});
9 changes: 3 additions & 6 deletions routes/account/manage.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
import type { RouteContext } from "$fresh/server.ts";
import { defineRoute } from "$fresh/server.ts";
import type { SignedInState } from "@/middleware/session.ts";
import { redirect } from "@/utils/http.ts";
import { isStripeEnabled, stripe } from "@/utils/stripe.ts";

export default async function AccountManagePage(
_req: Request,
ctx: RouteContext<undefined, SignedInState>,
) {
export default defineRoute<SignedInState>(async (_req, ctx) => {
const { sessionUser } = ctx.state;
if (!isStripeEnabled() || sessionUser.stripeCustomerId === undefined) {
return ctx.renderNotFound();
Expand All @@ -18,4 +15,4 @@ export default async function AccountManagePage(
return_url: ctx.url.origin + "/account",
});
return redirect(url);
}
});
9 changes: 3 additions & 6 deletions routes/account/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
import type { RouteContext } from "$fresh/server.ts";
import { defineRoute } from "$fresh/server.ts";
import type { SignedInState } from "@/middleware/session.ts";
import { redirect } from "@/utils/http.ts";
import {
Expand All @@ -8,10 +8,7 @@ import {
stripe,
} from "@/utils/stripe.ts";

export default async function AccountUpgradePage(
_req: Request,
ctx: RouteContext<undefined, SignedInState>,
) {
export default defineRoute<SignedInState>(async (_req, ctx) => {
if (!isStripeEnabled()) return ctx.renderNotFound();
const stripePremiumPlanPriceId = getStripePremiumPlanPriceId();
if (stripePremiumPlanPriceId === undefined) {
Expand All @@ -34,4 +31,4 @@ export default async function AccountUpgradePage(
if (url === null) return ctx.renderNotFound();

return redirect(url);
}
});
6 changes: 3 additions & 3 deletions routes/blog/[slug].tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
import type { RouteContext } from "$fresh/server.ts";
import { defineRoute } from "$fresh/server.ts";
import { CSS, render } from "$gfm";
import { getPost } from "@/utils/posts.ts";
import Head from "@/components/Head.tsx";
import Share from "@/components/Share.tsx";

export default async function BlogPostPage(_req: Request, ctx: RouteContext) {
export default defineRoute(async (_req, ctx) => {
const post = await getPost(ctx.params.slug);
if (post === null) return await ctx.renderNotFound();

Expand Down Expand Up @@ -37,4 +37,4 @@ export default async function BlogPostPage(_req: Request, ctx: RouteContext) {
</main>
</>
);
}
});
6 changes: 3 additions & 3 deletions routes/blog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
import type { RouteContext } from "$fresh/server.ts";
import { defineRoute } from "$fresh/server.ts";
import { getPosts, type Post } from "@/utils/posts.ts";
import Head from "@/components/Head.tsx";
import { HEADING_WITH_MARGIN_STYLES } from "@/utils/constants.ts";
Expand Down Expand Up @@ -29,7 +29,7 @@ function PostCard(props: Post) {
);
}

export default async function BlogPage(_req: Request, ctx: RouteContext) {
export default defineRoute(async (_req, ctx) => {
const posts = await getPosts();

return (
Expand All @@ -43,4 +43,4 @@ export default async function BlogPage(_req: Request, ctx: RouteContext) {
</main>
</>
);
}
});
10 changes: 5 additions & 5 deletions routes/dashboard/stats.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
import type { PageProps } from "$fresh/server.ts";
import Chart from "@/islands/Chart.tsx";
import Head from "@/components/Head.tsx";
import TabsBar from "@/components/TabsBar.tsx";
import { HEADING_WITH_MARGIN_STYLES } from "@/utils/constants.ts";
import { defineRoute } from "$fresh/server.ts";

function randomNumbers(length: number) {
return Array.from({ length }, () => Math.floor(Math.random() * 1000));
}

export default function DashboardStatsPage(props: PageProps) {
export default defineRoute((_req, ctx) => {
const labels = [
"Monday",
"Tuesday",
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function DashboardStatsPage(props: PageProps) {

return (
<>
<Head title="Dashboard" href={props.url.href} />
<Head title="Dashboard" href={ctx.url.href} />
<main class="flex-1 p-4 flex flex-col">
<h1 class={HEADING_WITH_MARGIN_STYLES}>Dashboard</h1>
<TabsBar
Expand All @@ -55,7 +55,7 @@ export default function DashboardStatsPage(props: PageProps) {
path: "/dashboard/users",
innerText: "Users",
}]}
currentPath={props.url.pathname}
currentPath={ctx.url.pathname}
/>
<div class="flex-1 relative">
<Chart
Expand Down Expand Up @@ -90,4 +90,4 @@ export default function DashboardStatsPage(props: PageProps) {
</main>
</>
);
}
});
10 changes: 5 additions & 5 deletions routes/dashboard/users.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
import type { PageProps } from "$fresh/server.ts";
import Head from "@/components/Head.tsx";
import TabsBar from "@/components/TabsBar.tsx";
import { HEADING_WITH_MARGIN_STYLES } from "@/utils/constants.ts";
import UsersTable from "@/islands/UsersTable.tsx";
import { defineRoute } from "$fresh/server.ts";

export default function DashboardUsersPage(props: PageProps) {
export default defineRoute((_req, ctx) => {
const endpoint = "/api/users";

return (
<>
<Head title="Users" href={props.url.href}>
<Head title="Users" href={ctx.url.href}>
<link
as="fetch"
crossOrigin="anonymous"
Expand All @@ -28,10 +28,10 @@ export default function DashboardUsersPage(props: PageProps) {
path: "/dashboard/users",
innerText: "Users",
}]}
currentPath={props.url.pathname}
currentPath={ctx.url.pathname}
/>
<UsersTable endpoint={endpoint} />
</main>
</>
);
}
});
6 changes: 3 additions & 3 deletions routes/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import { Feed } from "feed";
import { getPosts } from "@/utils/posts.ts";
import { SITE_NAME } from "@/utils/constants.ts";
import { RouteContext } from "$fresh/server.ts";
import { defineRoute } from "$fresh/server.ts";

const copyright = `Copyright ${new Date().getFullYear()} ${SITE_NAME}`;

// Use https://validator.w3.org/feed/ to validate RSS feed syntax.
export default async function FeedPage(_req: Request, ctx: RouteContext) {
export default defineRoute(async (_req, ctx) => {
const { origin } = ctx.url;
const feed = new Feed({
title: "Deno",
Expand Down Expand Up @@ -43,4 +43,4 @@ export default async function FeedPage(_req: Request, ctx: RouteContext) {
"content-type": "application/atom+xml; charset=utf-8",
},
});
}
});
10 changes: 5 additions & 5 deletions routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
import type { PageProps, RouteContext } from "$fresh/server.ts";
import type { State } from "@/middleware/session.ts";
import Head from "@/components/Head.tsx";
import ItemsList from "@/islands/ItemsList.tsx";
import { defineRoute } from "$fresh/server.ts";

const NEEDS_SETUP = Deno.env.get("GITHUB_CLIENT_ID") === undefined ||
Deno.env.get("GITHUB_CLIENT_SECRET") === undefined;
Expand Down Expand Up @@ -40,13 +40,13 @@ function SetupInstruction() {
);
}

export default function HomePage(props: PageProps<undefined, State>) {
const isSignedIn = props.state.sessionUser !== undefined;
export default defineRoute<State>((_req, ctx) => {
const isSignedIn = ctx.state.sessionUser !== undefined;
const endpoint = "/api/items";

return (
<>
<Head href={props.url.href}>
<Head href={ctx.url.href}>
<link
as="fetch"
crossOrigin="anonymous"
Expand All @@ -71,4 +71,4 @@ export default function HomePage(props: PageProps<undefined, State>) {
</main>
</>
);
}
});
9 changes: 3 additions & 6 deletions routes/pricing.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
import type { RouteContext } from "$fresh/server.ts";
import type { State } from "@/middleware/session.ts";
import { BUTTON_STYLES } from "@/utils/constants.ts";
import { assertIsPrice, isStripeEnabled, stripe } from "@/utils/stripe.ts";
import { formatCurrency } from "@/utils/display.ts";
import Stripe from "stripe";
import IconCheckCircle from "tabler_icons_tsx/circle-check.tsx";
import Head from "@/components/Head.tsx";
import { defineRoute } from "$fresh/server.ts";

const CARD_STYLES =
"shadow-md flex flex-col flex-1 space-y-8 p-8 ring-1 ring-gray-300 rounded-xl dark:bg-gray-700 bg-gradient-to-r";
Expand Down Expand Up @@ -160,10 +160,7 @@ function EnterprisePricingCard() {
);
}

export default async function PricingPage(
_req: Request,
ctx: RouteContext<undefined, State>,
) {
export default defineRoute<State>(async (_req, ctx) => {
if (!isStripeEnabled()) return await ctx.renderNotFound();

const { data } = await stripe.products.list({
Expand All @@ -190,4 +187,4 @@ export default async function PricingPage(
</main>
</>
);
}
});
8 changes: 4 additions & 4 deletions routes/submit.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
import type { PageProps } from "$fresh/server.ts";
import { HEADING_STYLES, INPUT_STYLES } from "@/utils/constants.ts";
import Head from "@/components/Head.tsx";
import IconCheckCircle from "tabler_icons_tsx/circle-check.tsx";
import IconCircleX from "tabler_icons_tsx/circle-x.tsx";
import { defineRoute } from "$fresh/server.ts";

export default function SubmitPage(props: PageProps) {
export default defineRoute((_req, ctx) => {
return (
<>
<Head title="Submit" href={props.url.href} />
<Head title="Submit" href={ctx.url.href} />
<main class="flex-1 flex flex-col justify-center mx-auto w-full space-y-16 p-4 max-w-6xl">
<div class="text-center">
<h1 class={HEADING_STYLES}>
Expand Down Expand Up @@ -87,4 +87,4 @@ export default function SubmitPage(props: PageProps) {
</main>
</>
);
}
});
Loading

0 comments on commit 1f981be

Please sign in to comment.