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

[Perf] Lazy load site banner #10899

Merged
merged 1 commit into from
Jul 8, 2024
Merged
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
28 changes: 28 additions & 0 deletions apps/web/src/components/Layout/BannerContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Alert } from "@gc-digital-talent/ui";
import { RichTextRenderer, htmlToRichTextJSON } from "@gc-digital-talent/forms";

interface BannerContentProps {
title: string;
message: string;
}

const BannerContent = ({ title, message }: BannerContentProps) => (
<div
data-h2-background-color="base(foreground) base:dark(white)"
data-h2-padding="base(x1, 0)"
>
<div data-h2-container="base(center, large, x1)">
<Alert.Root
type="warning"
live
data-h2-shadow="base(none)"
data-h2-margin="base(0, -x1, 0, -x1)"
>
<Alert.Title>{title}</Alert.Title>
<RichTextRenderer node={htmlToRichTextJSON(message)} />
</Alert.Root>
</div>
</div>
);

export default BannerContent;
25 changes: 7 additions & 18 deletions apps/web/src/components/Layout/SitewideBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { isAfter } from "date-fns/isAfter";
import { isBefore } from "date-fns/isBefore";
import { useQuery } from "urql";
import { useIntl } from "react-intl";
import { lazy, Suspense } from "react";

import { graphql } from "@gc-digital-talent/graphql";
import { parseDateTimeUtc } from "@gc-digital-talent/date-helpers";
import { Alert } from "@gc-digital-talent/ui";
import { Loading } from "@gc-digital-talent/ui";
import { getLocale } from "@gc-digital-talent/i18n";
import { RichTextRenderer, htmlToRichTextJSON } from "@gc-digital-talent/forms";

const BannerContent = lazy(() => import("./BannerContent"));

const SitewideBanner_Query = graphql(/* GraphQL */ `
query SitewideBanner {
Expand Down Expand Up @@ -66,22 +68,9 @@ const SitewideBanner = () => {

return (
showMaintenanceBanner && (
<div
data-h2-background-color="base(foreground) base:dark(white)"
data-h2-padding="base(x1, 0)"
>
<div data-h2-container="base(center, large, x1)">
<Alert.Root
type="warning"
live
data-h2-shadow="base(none)"
data-h2-margin="base(0, -x1, 0, -x1)"
>
<Alert.Title>{title}</Alert.Title>
<RichTextRenderer node={htmlToRichTextJSON(message)} />
</Alert.Root>
</div>
</div>
<Suspense fallback={<Loading inline />}>
<BannerContent title={title} message={message} />
</Suspense>
)
);
};
Expand Down
Loading