Skip to content

Commit

Permalink
removed defer (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
CVVSAI authored Nov 22, 2024
1 parent cffc173 commit 0aaeafc
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 56 deletions.
4 changes: 2 additions & 2 deletions app/routes/about._index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Navbar from "~/components/layout/Navbar";
import { defer } from "@remix-run/node";
import { dataHosts } from "~/config";
import { useLoaderData } from "@remix-run/react";
import "~/styles/about.css";
Expand All @@ -13,11 +12,12 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {

const wpData: TWordPressData[] = await wpResponse.json();

return defer({ wpData: wpData[0] });
return { wpData: wpData[0] };
};

const About = () => {
const { wpData } = useLoaderData<{ wpData: TWordPressData }>();

return (
<div>
<Navbar />
Expand Down
4 changes: 2 additions & 2 deletions app/routes/about.bibliography.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Navbar from "~/components/layout/Navbar";
import { defer } from "@remix-run/node";

import { dataHosts } from "~/config";
import { useLoaderData } from "@remix-run/react";
import "~/styles/about.css";
Expand All @@ -13,7 +13,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {

const wpData: TWordPressData[] = await wpResponse.json();

return defer({ wpData: wpData[0] });
return { wpData: wpData[0] };
};

const About = () => {
Expand Down
18 changes: 14 additions & 4 deletions app/routes/explore.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useContext, useState, useEffect, Suspense } from "react";
import { MapContext } from "~/contexts";
import { useLoaderData, defer, useNavigation } from "@remix-run/react";
import { useLoaderData, useNavigation, Await } from "@remix-run/react";
import { fetchCounties, fetchPlacesByType } from "~/data/coredata";
import IntroModal from "~/components/layout/IntroModal";
import Loading from "~/components/layout/Loading";
Expand All @@ -13,7 +13,7 @@ import Islands from "~/components/mapping/Islands";
export const loader: LoaderFunction = async () => {
const islands: TPlace[] = await fetchPlacesByType("Barrier Island");
const counties: TCounty[] = await fetchCounties();
return defer({ islands, counties });
return { islands, counties };
};

export const HydrateFallback = () => {
Expand All @@ -40,8 +40,18 @@ const Explore = () => {
>
<IntroModal isOpen={isModalOpen} setIsOpen={setIsModalOpen} />
<Suspense fallback={<Loading />}>
<Counties counties={counties} />
<Islands islands={islands} />
<Await resolve={islands}>
{(resolvedIslands) => (
<Await resolve={counties}>
{(resolvedCounties) => (
<>
<Counties counties={resolvedCounties} />
<Islands islands={resolvedIslands} />
</>
)}
</Await>
)}
</Await>
</Suspense>
</div>
);
Expand Down
42 changes: 23 additions & 19 deletions app/routes/islands.$id.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
useNavigation,
useRouteError,
isRouteErrorResponse,
defer,
Await
} from "@remix-run/react";
import { dataHosts } from "~/config.ts";
import { fetchPlaceBySlug } from "~/data/coredata";
Expand Down Expand Up @@ -36,7 +36,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {

const wpData: TWordPressData[] = await wpResponse.json();

return defer({ place, wpData: wpData[0] });
return { place, wpData: wpData[0] };
};

// export const clientLoader = async ({
Expand Down Expand Up @@ -103,23 +103,27 @@ const IslandPage = () => {
}}
>
<Suspense fallback={<HydrateFallback />}>
<PlaceContent>
<Heading
as="h1"
className="text-2xl px-4 pt-4 sticky top-0 z-10 bg-white"
>
{place.name}
</Heading>
<div ref={topRef} className="relative -top-12 z-10 min-h-10">
<FeaturedMedium record={place} />
</div>
<div
className="relative px-4 -mt-12 primary-content"
dangerouslySetInnerHTML={{
__html: wpData?.content.rendered ?? place.description,
}}
/>
</PlaceContent>
<Await resolve={wpData}>
{(resolvedWpData) => (
<PlaceContent>
<Heading
as="h1"
className="text-2xl px-4 pt-4 sticky top-0 z-10 bg-white"
>
{place.name}
</Heading>
<div className="relative -top-12 z-10 min-h-10">
<FeaturedMedium record={place} />
</div>
<div
className="relative px-4 -mt-12 primary-content"
dangerouslySetInnerHTML={{
__html: resolvedWpData?.content.rendered ?? place.description,
}}
/>
</PlaceContent>
)}
</Await>
</Suspense>
</PlaceContext.Provider>
);
Expand Down
62 changes: 34 additions & 28 deletions app/routes/places.$id.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Suspense, useEffect, useRef, useState } from "react";
import {
useLoaderData,
defer,
useNavigate,
useLocation,
Await
} from "@remix-run/react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faArrowLeft } from "@fortawesome/free-solid-svg-icons";
Expand Down Expand Up @@ -34,7 +34,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {
});
}

return defer({ place });
return { place };
};
const PlacePage = () => {
const { place } = useLoaderData<TPlaceRecord>();
Expand Down Expand Up @@ -63,33 +63,39 @@ const PlacePage = () => {
}}
>
<Suspense fallback={<Loading />}>
<PlaceContent>
{backTo && (
<button
onClick={() => navigate(-1)}
className="bg-gray-300 hover:bg-gray-400 border-spacing-1 drop-shadow-sm px-6 py-2 rounded-lg text-left w-max m-4 text-xs"
>
<FontAwesomeIcon icon={faArrowLeft} /> Back to {backTo}
</button>
<Await resolve={place}>
{(resolvedPlace) => (
<>
<PlaceContent>
{backTo && (
<button
onClick={() => navigate(-1)}
className="bg-gray-300 hover:bg-gray-400 border-spacing-1 drop-shadow-sm px-6 py-2 rounded-lg text-left w-max m-4 text-xs"
>
<FontAwesomeIcon icon={faArrowLeft} /> Back to {backTo}
</button>
)}
<Heading
as="h1"
className="text-2xl px-4 pt-4 sticky top-0 z-10 bg-white"
>
{resolvedPlace.name}
</Heading>
<div ref={topRef} className="relative -top-12 z-10 min-h-10">
<FeaturedMedium record={resolvedPlace} />
</div>
<div
className="relative px-4 -mt-12 primary-content"
dangerouslySetInnerHTML={{
__html: resolvedPlace.description,
}}
/>
</PlaceContent>
{/* <RelatedRecords /> */}
{resolvedPlace.geojson && <PlaceGeoJSON />}
</>
)}
<Heading
as="h1"
className="text-2xl px-4 pt-4 sticky top-0 z-10 bg-white"
>
{place.name}
</Heading>
<div ref={topRef} className="relative -top-12 z-10 min-h-10">
<FeaturedMedium record={place} />
</div>
<div
className="relative px-4 -mt-12 primary-content"
dangerouslySetInnerHTML={{
__html: place.description,
}}
/>
</PlaceContent>
{/* <RelatedRecords /> */}
{place.geojson && <PlaceGeoJSON />}
</Await>
</Suspense>
</PlaceContext.Provider>
);
Expand Down
6 changes: 5 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ installGlobals();

export default defineConfig({
plugins: [
remix(),
remix({
future: {
v3_singleFetch: true,
},
}),
tsconfigPaths(),
SiteMap({
hostname: "https://georgiacoastatlas.org",
Expand Down

0 comments on commit 0aaeafc

Please sign in to comment.