Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #26

Merged
merged 2 commits into from
Jan 12, 2025
Merged

Dev #26

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/entry.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { HydratedRouter } from "react-router/dom";
import { startTransition, StrictMode } from "react";
import { hydrateRoot } from "react-dom/client";

const { NODE_ENV, MOCKS } = process.env;
const { MOCKS } = process.env;

async function prepareApp() {
if (NODE_ENV === "development" && MOCKS === "true") {
if (MOCKS === "true") {
const { worker } = await import("./mocks/browser");
return worker.start();
}
Expand Down
32 changes: 29 additions & 3 deletions app/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Route } from "./+types/index";
import { getGamesToday } from "~/utils/games";
import { getGamesToday, type TodaysGames } from "~/utils/games";
import React from "react";
import { Await } from "react-router";
import { Await, data } from "react-router";
import SkeletonTodaysGames from "~/components/ui/loading/skeleton-todays-games";
import LatestGames from "~/components/latestGames";

Expand All @@ -15,15 +15,41 @@ export function meta() {
export async function loader() {
const gamesData = getGamesToday();

return data(
{ gamesData },
{
headers: {
"Cache-Control": "max-age=3600, public",
},
}
);
}

clientLoader.hydrate = true;

let cache: { gamesData: TodaysGames };

export async function clientLoader({ serverLoader }: Route.ClientLoaderArgs) {
if (cache) return { gamesData: cache.gamesData };

const { gamesData } = (await serverLoader()) as unknown as {
gamesData: TodaysGames;
};
cache = { gamesData };

return { gamesData };
}

export function HydrateFallback() {
return <div>Loading...</div>;
}

export default function Index({
loaderData: { gamesData },
}: Route.ComponentProps) {
return (
<React.Suspense fallback={<SkeletonTodaysGames />}>
<Await resolve={gamesData}>
<Await resolve={gamesData as unknown as Promise<{ data: TodaysGames }>}>
{(gamesData) => <LatestGames data={gamesData.data} />}
</Await>
</React.Suspense>
Expand Down
Loading