Skip to content

Commit

Permalink
[FEATURE]: improve user experience (slow 3G) with page transitions wh…
Browse files Browse the repository at this point in the history
…en fetching data (#68)

* feature: needed native tailwind colours for gradient map effect

* feature: page transition for fetching data--gradient map
  • Loading branch information
slackermorris authored Mar 19, 2023
1 parent d00fa86 commit bc5a5b3
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 65 deletions.
23 changes: 23 additions & 0 deletions app/components/pageTransition/GradientMapTransition.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from "react";
import type { PropsWithChildren } from "react";
import { useTransition } from "@remix-run/react";
import classNames from "classnames";

const GradientMapTransition = ({
children,
classNameProps,
}: PropsWithChildren<{ classNameProps?: Array<string> }>) => {
const transition = useTransition();

if (transition.state === "loading") {
return (
<div className={classNames(classNameProps?.join(" "))}>
<div className="h-full w-full animate-ping bg-[radial-gradient(ellipse_at_center,_var(--tw-gradient-stops))] from-rose-100 to-teal-100" />
</div>
);
}

return <>{children}</>;
};

export default GradientMapTransition;
7 changes: 6 additions & 1 deletion app/components/pageTransition/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import MorphingTransition from "./MorphingTransition";
import FlowerBlobTransition from "./FlowerBlobTransition";
import GradientMapTransition from "./GradientMapTransition";

export { MorphingTransition, FlowerBlobTransition };
export default {
MorphingTransition,
FlowerBlobTransition,
GradientMapTransition,
};
6 changes: 3 additions & 3 deletions app/routes/braindumps.list.$braindumpId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Paragraph from "~/components/Paragraph";
import Title from "~/components/Title";
import CodeBlock from "~/components/CodeBlock";
import A from "~/components/A";
import { FlowerBlobTransition } from "~/components/pageTransition";
import PageTransition from "~/components/pageTransition";

//? TYPES
import type { PropsWithChildren } from "react";
Expand Down Expand Up @@ -193,7 +193,7 @@ export default function BraindumpIndex() {

return (
<div className="relative">
<FlowerBlobTransition
<PageTransition.FlowerBlobTransition
key={braindumpMeta["id"]}
animationKey={braindumpMeta["id"]}
>
Expand All @@ -206,7 +206,7 @@ export default function BraindumpIndex() {
</div>
</InnerLayout>
</div>
</FlowerBlobTransition>
</PageTransition.FlowerBlobTransition>
</div>
);
}
Expand Down
21 changes: 15 additions & 6 deletions app/routes/braindumps/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React from "react";
import { Link } from "@remix-run/react";

//? components
import Title from "~/components/Title";
import Layout from "~/components/Layout";
import { AnimatedButton } from "~/components/button";
import { Link } from "@remix-run/react";
import PageTransition from "~/components/pageTransition";

const Introduction = () => {
//! NB: h-[calc(100vh-4rem)] needed to explicitly set the height otherwise we get scrollbars
//! https://github.com/slackermorris/better-brain-blogging/issues/10#issuecomment-1437429507
return (
<div className="flex h-[calc(100vh-4rem)] w-2/3">
<Layout.FullHeight classNameProp={["w-2/3"]}>
<div className="flex flex-col space-y-32 p-16">
<Title.H3>
Inside is a collection of braindumps. These are things I have tried to
Expand All @@ -25,10 +28,16 @@ const Introduction = () => {
</Link>
</div>
</div>
</div>
</Layout.FullHeight>
);
};

export default function BraindumpsIndex() {
return <Introduction />;
return (
<PageTransition.GradientMapTransition
classNameProps={["h-[calc(100vh-4rem)]", "w-2/3", "overflow-hidden"]}
>
<Introduction />
</PageTransition.GradientMapTransition>
);
}
114 changes: 59 additions & 55 deletions app/routes/braindumps/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import notionClient from "~/integrations/notion";
import { retrieveBraindumpsFromNotionDatabase } from "./notion-crm";

//? COMPONENTS
import { Link } from "@remix-run/react";
import P from "~/components/P";
import Title from "~/components/Title";
import { MorphingTransition } from "~/components/pageTransition";
import { Link } from "@remix-run/react";
import Layout from "~/components/Layout";
import PageTransition from "~/components/pageTransition";

// @ts-ignore
// ! EXPORT PROPER TYPE DEFINITONS
Expand All @@ -28,7 +29,6 @@ import type { NotionDatabaseAPIMapperResponse } from "./notion-crm";
// @ts-ignore
// ! EXPORT PROPER TYPE DEFINITONS
import fuzzyScrawlStyles from "fuzzy-scrawl-styles";
import Layout from "../../components/Layout";

type ThrownResponses = ThrownResponse<404, string>;

Expand Down Expand Up @@ -94,59 +94,63 @@ export default function BraindumpsList() {
if (!braindumps) return null;

return (
<Layout.FullHeight classNameProp={["w-2/3"]}>
<MorphingTransition>
<div className="p-24">
{Object.entries(braindumps).map(
(
[category, relatedBraindumps]: [
category: string,
relatedBraindumps: NotionDatabaseAPIMapperResponse
],
keyOfCategories: number
) => {
return (
<div key={keyOfCategories} className="w-full pb-8">
<Title.H3
styleProps={[
"py-3.5",
"text-4xl",
"font-extrabold",
"uppercase",
"tracking-tight",
]}
>
{category}
</Title.H3>

<div className="bg-white pl-3.5">
{relatedBraindumps.map(
(
braindump: NotionDatabaseAPIMapperResponse[0],
index: number,
braindumps: NotionDatabaseAPIMapperResponse
) => {
const showFuzzyScrawl =
index ===
Math.floor(Math.random() * braindumps.length);

return (
<BraindumpDetails
key={index}
braindump={braindump}
showFuzzyScrawl={showFuzzyScrawl}
/>
);
}
)}
<PageTransition.GradientMapTransition
classNameProps={["h-[calc(100vh-4rem)]", "w-2/3", "overflow-hidden"]}
>
<Layout.FullHeight classNameProp={["w-2/3"]}>
<PageTransition.MorphingTransition>
<div className="p-24">
{Object.entries(braindumps).map(
(
[category, relatedBraindumps]: [
category: string,
relatedBraindumps: NotionDatabaseAPIMapperResponse
],
keyOfCategories: number
) => {
return (
<div key={keyOfCategories} className="w-full pb-8">
<Title.H3
styleProps={[
"py-3.5",
"text-4xl",
"font-extrabold",
"uppercase",
"tracking-tight",
]}
>
{category}
</Title.H3>

<div className="bg-white pl-3.5">
{relatedBraindumps.map(
(
braindump: NotionDatabaseAPIMapperResponse[0],
index: number,
braindumps: NotionDatabaseAPIMapperResponse
) => {
const showFuzzyScrawl =
index ===
Math.floor(Math.random() * braindumps.length);

return (
<BraindumpDetails
key={index}
braindump={braindump}
showFuzzyScrawl={showFuzzyScrawl}
/>
);
}
)}
</div>
</div>
</div>
);
}
)}
</div>
</MorphingTransition>
</Layout.FullHeight>
);
}
)}
</div>
</PageTransition.MorphingTransition>
</Layout.FullHeight>
</PageTransition.GradientMapTransition>
);
}

Expand Down
2 changes: 2 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module.exports = {
},
colors: {
black: colors.black,
rose: colors.rose,
teal: colors.teal,
graphite: {
lightest: "#E1DFE1",
light: "#C7C7C7",
Expand Down

0 comments on commit bc5a5b3

Please sign in to comment.