Skip to content

Commit

Permalink
defer shows loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo committed Sep 15, 2024
1 parent e2ff333 commit 05d3108
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/routes/_index/route.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import type { LoaderFunctionArgs } from "@remix-run/node";
import { json, NavLink, useLoaderData } from "@remix-run/react";
import { Await, defer, NavLink, useLoaderData } from "@remix-run/react";
import classes from "./index.module.css";
import { Shows } from "~/components/Shows";
import Layout from "~/components/Layout";
import SocialIcons from "~/components/SocialIcons";
import NewsletterSignup from "~/components/NewsletterSignup";
import { Suspense } from "react";

export const loader = async ({ context: { payload } }: LoaderFunctionArgs) => {
// today, 00:00:00
const today = new Date();
today.setHours(0, 0, 0, 0);

const shows = await payload.find({
const shows = payload.find({
collection: "shows",
sort: "date",
where: {
Expand All @@ -20,7 +21,8 @@ export const loader = async ({ context: { payload } }: LoaderFunctionArgs) => {
},
},
});
return json({ shows }, { status: 200 });

return defer({ shows }, { status: 200 });
};

export default function Index() {
Expand All @@ -30,7 +32,11 @@ export default function Index() {
<Layout className={classes.container}>
<h1>Walls & Birds</h1>
<h2 className={classes.tour}>tour dates</h2>
<Shows shows={shows} className={classes.shows} />
<Suspense fallback={<div>Loading...</div>}>
<Await resolve={shows}>
{(shows) => <Shows shows={shows} className={classes.shows} />}
</Await>
</Suspense>

<hr />
<h2>email newsletter</h2>
Expand Down

0 comments on commit 05d3108

Please sign in to comment.