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

✨ New Feature - Incremental Static Regeneration #1098

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0196f42
Refactored to have livestream info come from getstaticprops
Harry-Ross Jul 21, 2023
6047c27
Fixed incorrect livestream parameter
Harry-Ross Jul 21, 2023
fbec20b
Refactored code to useMemo in custom hook
Harry-Ross Jul 25, 2023
ebd2052
Added const time for revalidation
Harry-Ross Jul 25, 2023
3953960
Merge branch 'main' into 1076-isr-events
Harry-Ross Jul 25, 2023
4ea4626
Merge branch 'main' into 1076-isr-events
Harry-Ross Jul 25, 2023
0a13b4a
Changed logic to throw error instead
Harry-Ross Jul 25, 2023
f5ad34c
Added additional checks to getEvents for missing env variables
Harry-Ross Jul 25, 2023
031a9a8
Added specific checking of environemnt variables
Harry-Ross Jul 25, 2023
a374530
Added log for env variables
Harry-Ross Jul 25, 2023
6c0a676
Added SharePoint env variables to build step
Harry-Ross Jul 26, 2023
4669c83
Changed to correct key vault config in build step
Harry-Ross Jul 26, 2023
ec226f1
Merge branch 'main' into 1076-isr-events
Harry-Ross Jul 26, 2023
e208a7b
Added echo-ing of SharePoint environment variables to share them to G…
Harry-Ross Jul 26, 2023
72c2729
Changed to correct names in KV
Harry-Ross Jul 26, 2023
4fea94c
Flow - echoing variables
amankumarrr Jul 26, 2023
7ce3e3f
Added logging of environment variable
Harry-Ross Jul 26, 2023
0b497e2
Changed to reveal every value
Harry-Ross Jul 26, 2023
acd2ef1
Updating the variables name
amankumarrr Jul 26, 2023
f382856
Removed debug logging statements
Harry-Ross Jul 26, 2023
fd5bae5
Merge branch '1076-isr-events' of https://github.com/SSWConsulting/SS…
Harry-Ross Jul 26, 2023
9976832
Merge branch 'main' into 1076-isr-events
Harry-Ross Jul 26, 2023
334256e
Merge branch 'main' into 1076-isr-events
Harry-Ross Jul 28, 2023
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
24 changes: 22 additions & 2 deletions .github/workflows/template-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,23 @@ jobs:
id: KeyVaultSecrets
run: |
# KV - Secret
$GoogleRecaptchaSiteKey = (az keyvault secret show --name Google-Recaptcha-Site-KEY --vault-name ${{ env.KEY_VAULT}} --query value -o tsv)
$GoogleRecaptchaSiteKey = (az keyvault secret show --name Google-Recaptcha-Site-KEY --vault-name ${{ env.KEY_VAULT }} --query value -o tsv)
$MICROSOFT_OAUTH_TENANT_ID = (az keyvault secret show --name MICROSOFT-OAUTH-TENANT-ID --vault-name ${{ env.KEY_VAULT }} --query value -o tsv)
$MICROSOFT_OAUTH_CLIENT_ID = (az keyvault secret show --name MICROSOFT-OAUTH-CLIENT-ID --vault-name ${{ env.KEY_VAULT }} --query value -o tsv)
$MICROSOFT_OAUTH_CLIENT_SECRET = (az keyvault secret show --name MICROSOFT-OAUTH-CLIENT-SECRET --vault-name ${{ env.KEY_VAULT }} --query value -o tsv)
$SHAREPOINT_SITE_ID = (az keyvault secret show --name SHAREPOINT-SITE-ID --vault-name ${{ env.KEY_VAULT }} --query value -o tsv)
$SHAREPOINT_EVENTS_LIST_ID = (az keyvault secret show --name SHAREPOINT-EVENTS-LIST-ID --vault-name ${{ env.KEY_VAULT }} --query value -o tsv)
$SHAREPOINT_EXTERNAL_PRESENTERS_LIST_ID = (az keyvault secret show --name SHAREPOINT-EXTERNAL-PRESENTERS-LIST-ID --vault-name ${{ env.KEY_VAULT }} --query value -o tsv)

echo "GoogleRecaptchaSiteKey=$GoogleRecaptchaSiteKey" >> $env:GITHUB_OUTPUT
Write-Host '✅ KV - Secret retrieved'
echo "MICROSOFT_OAUTH_TENANT_ID=$MICROSOFT_OAUTH_TENANT_ID" >> $env:GITHUB_OUTPUT
echo "MICROSOFT_OAUTH_CLIENT_ID=$MICROSOFT_OAUTH_CLIENT_ID" >> $env:GITHUB_OUTPUT
echo "MICROSOFT_OAUTH_CLIENT_SECRET=$MICROSOFT_OAUTH_CLIENT_SECRET" >> $env:GITHUB_OUTPUT
echo "SHAREPOINT_SITE_ID=$SHAREPOINT_SITE_ID" >> $env:GITHUB_OUTPUT
echo "SHAREPOINT_EVENTS_LIST_ID=$SHAREPOINT_EVENTS_LIST_ID" >> $env:GITHUB_OUTPUT
echo "SHAREPOINT_EXTERNAL_PRESENTERS_LIST_ID=$SHAREPOINT_EXTERNAL_PRESENTERS_LIST_ID" >> $env:GITHUB_OUTPUT

Comment on lines +92 to +107
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to condense KV block

Write-Host '✅ KV - Secrets retrieved'

- name: AppInsight - Connection Strings
shell: pwsh
Expand Down Expand Up @@ -124,6 +138,12 @@ jobs:
GOOGLE_RECAPTCHA_SITE_KEY: ${{ steps.KeyVaultSecrets.outputs.GoogleRecaptchaSiteKey }}
KEY_VAULT: ${{ env.KEY_VAULT }}
NEXT_PUBLIC_APP_INSIGHT_CONNECTION_STRING: ${{ steps.AppInsight.outputs.AppInsightConnectionString }}
MICROSOFT_OAUTH_TENANT_ID: ${{ steps.KeyVaultSecrets.outputs.MICROSOFT_OAUTH_TENANT_ID }}
MICROSOFT_OAUTH_CLIENT_ID: ${{ steps.KeyVaultSecrets.outputs.MICROSOFT_OAUTH_CLIENT_ID }}
MICROSOFT_OAUTH_CLIENT_SECRET: ${{ steps.KeyVaultSecrets.outputs.MICROSOFT_OAUTH_CLIENT_SECRET }}
SHAREPOINT_SITE_ID: ${{ steps.KeyVaultSecrets.outputs.SHAREPOINT_SITE_ID }}
SHAREPOINT_EVENTS_LIST_ID: ${{ steps.KeyVaultSecrets.outputs.SHAREPOINT_EVENTS_LIST_ID }}
SHAREPOINT_EXTERNAL_PRESENTERS_LIST_ID: ${{ steps.KeyVaultSecrets.outputs.SHAREPOINT_EXTERNAL_PRESENTERS_LIST_ID }}
TINA_TOKEN: ${{ secrets.TINA_TOKEN }}
SITE_URL: https://www.ssw.com.au

Expand Down
37 changes: 13 additions & 24 deletions components/layout/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { Footer } from "./footer";
import { Header } from "./header";
import { Theme } from "./theme";

import dayjs from "dayjs";
import dynamic from "next/dynamic";
import { Open_Sans } from "next/font/google";
import layoutData from "../../content/global/index.json";
import { EventInfo } from "../../services/server/events";

export const openSans = Open_Sans({
variable: "--open-sans-font",
Expand Down Expand Up @@ -50,26 +50,15 @@ const LiveStreamBanner = dynamic(
}
);

export const Layout = ({ children, className = "" }) => {
const liveStreamProps = useLiveStreamProps();
const router = useRouter();

const rightnow = dayjs().utc();

const isLive =
liveStreamProps?.countdownMins &&
liveStreamProps?.countdownMins <= 0 &&
!!liveStreamProps?.event &&
rightnow.isBefore(liveStreamProps?.event?.EndDateTime);
type LayoutProps = {
className?: string;
children: React.ReactNode;
event?: EventInfo;
};

const showBanner =
!!liveStreamProps?.event &&
dayjs().isBetween(
dayjs(liveStreamProps?.event.StartShowBannerDateTime),
dayjs(liveStreamProps?.event.EndShowBannerDateTime),
null,
"[)"
);
export const Layout = ({ children, className = "", event }: LayoutProps) => {
const liveStreamProps = useLiveStreamProps(event);
const router = useRouter();

return (
<>
Expand Down Expand Up @@ -120,14 +109,14 @@ export const Layout = ({ children, className = "" }) => {
)}
>
<header className="no-print">
{(showBanner || router.query.liveBanner) && (
<LiveStreamBanner {...liveStreamProps} isLive={isLive} />
{(liveStreamProps?.showBanner || router.query.liveBanner) && (
<LiveStreamBanner {...liveStreamProps} event={event} />
)}
<div className="mx-auto max-w-9xl px-6 sm:px-8">
<Header />
<MenuBar />
{(isLive || router.query.liveStream) && (
<LiveStreamWidget {...liveStreamProps} isLive={isLive} />
{(liveStreamProps?.isLive || router.query.liveStream) && (
<LiveStreamWidget {...liveStreamProps} event={event} />
)}
</div>
</header>
Expand Down
2 changes: 2 additions & 0 deletions components/liveStream/liveStreamBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import dayjs from "dayjs";
import Link from "next/link";
import { useEffect, useState } from "react";
import countdownTextFormat from "../../helpers/countdownTextFormat";
import { EventInfo } from "../../services/server/events";
import { LiveStreamProps } from "./useLiveStreamProps";

type LiveStreamBannerProps = {
isLive?: boolean;
event?: EventInfo;
} & LiveStreamProps;

export const LiveStreamBanner = ({
Expand Down
3 changes: 2 additions & 1 deletion components/liveStream/liveStreamWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { TfiAngleDown, TfiAngleUp } from "react-icons/tfi";
import { Tooltip } from "react-tooltip";
import layoutData from "../../content/global/index.json";
import { getYouTubeId } from "../../helpers/embeds";
import { SpeakerInfo } from "../../services/server/events";
import { EventInfo, SpeakerInfo } from "../../services/server/events";
import { YouTubeEmbed } from "../embeds/youtubeEmbed";
import { SubNewsLettersForm } from "../subNewsletter/subNewsletterForm";
import { SocialIcons, SocialTypes } from "../util/socialIcons";
import { LiveStreamProps } from "./useLiveStreamProps";

type LiveStreamWidgetProps = {
isLive?: boolean;
event?: EventInfo;
} & LiveStreamProps;

export const LiveStreamWidget = ({ isLive, event }: LiveStreamWidgetProps) => {
Expand Down
50 changes: 28 additions & 22 deletions components/liveStream/useLiveStreamProps.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
import axios from "axios";
import dayjs from "dayjs";
import { useEffect, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { EventInfo } from "../../services/server/events";

export type LiveStreamProps = {
countdownMins?: number;
liveStreamDelayMinutes: number;
event?: EventInfo;
isLive?: boolean;
showBanner?: boolean;
};

const INTERVAL_MINUTES = 1;

export function useLiveStreamProps(): LiveStreamProps {
export function useLiveStreamProps(event: EventInfo): LiveStreamProps {
const [countdownMins, setCountdownMins] = useState<number>();
const [event, setEvent] = useState<EventInfo>();
const [liveStreamDelayMinutes, setLiveStreamDelayMinutes] = useState(0);

useEffect(() => {
const fetchEvent = async () => {
const res = await axios.get<EventInfo[]>("/api/get-livestream-banner");

if (res?.status !== 200 || !res?.data?.length) {
setEvent(undefined);

return;
}

setEvent(res.data[0]);
};

fetchEvent();
}, []);

useEffect(() => {
if (!event?.StartDateTime || !event?.EndDateTime) {
return;
Expand All @@ -58,9 +41,32 @@ export function useLiveStreamProps(): LiveStreamProps {
return () => clearInterval(timer);
}, [event]);

const isLive = useMemo(() => {
const rightnow = dayjs().utc();
return (
countdownMins &&
countdownMins <= 0 &&
!!event &&
rightnow.isBefore(event?.EndDateTime)
);
}, [event, countdownMins]);

const showBanner = useMemo(() => {
return (
!!event &&
dayjs().isBetween(
dayjs(event.StartShowBannerDateTime),
dayjs(event.EndShowBannerDateTime),
null,
"[)"
)
);
}, [event]);

return {
countdownMins,
liveStreamDelayMinutes,
event,
showBanner,
isLive,
};
}
1 change: 1 addition & 0 deletions components/util/constants/config.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isrRevalidateTime = 120;
1 change: 0 additions & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
8 changes: 7 additions & 1 deletion pages/[filename].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import { Blocks } from "../components/blocks-renderer";
import { Breadcrumbs } from "../components/blocks/breadcrumbs";
import { componentRenderer } from "../components/blocks/mdxComponentRenderer";
import { Layout } from "../components/layout";
import { isrRevalidateTime } from "../components/util/constants/config";
import { Container } from "../components/util/container";
import { Section } from "../components/util/section";
import { SEO } from "../components/util/seo";
import { removeExtension } from "../services/client/utils.service";
import { getLiveStreamInfo } from "../services/server/events";

export default function HomePage(
props: InferGetStaticPropsType<typeof getStaticProps>
Expand All @@ -34,7 +36,7 @@ export default function HomePage(
return (
<>
<SEO seo={data.page.seo} />
<Layout>
<Layout event={props.liveStreamEvent}>
{data.page.breadcrumbs ? (
<Section className="mx-auto -mb-20 w-full max-w-9xl px-8 py-5">
<Breadcrumbs
Expand Down Expand Up @@ -74,6 +76,8 @@ export default function HomePage(
}

export const getStaticProps = async ({ params }) => {
const events = await getLiveStreamInfo();

const tinaProps = await client.queries.contentQuery({
relativePath: `${params.filename}.mdx`,
});
Expand All @@ -82,7 +86,9 @@ export const getStaticProps = async ({ params }) => {
data: tinaProps.data,
query: tinaProps.query,
variables: tinaProps.variables,
liveStreamEvent: events[0],
},
revalidate: isrRevalidateTime,
};
};

Expand Down
62 changes: 0 additions & 62 deletions pages/api/get-livestream-banner.ts

This file was deleted.

8 changes: 7 additions & 1 deletion pages/consulting/[filename].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ import { Layout } from "../../components/layout";
import { Marketing } from "../../components/marketing/Marketing";
import TechnologyCards from "../../components/technologyCard/technologyCards";
import { TestimonialRow } from "../../components/testimonials/TestimonialRow";
import { isrRevalidateTime } from "../../components/util/constants/config";
import { Benefits } from "../../components/util/consulting/benefits";
import { Container } from "../../components/util/container";
import { Section } from "../../components/util/section";
import { SEO } from "../../components/util/seo";
import { RecaptchaContext } from "../../context/RecaptchaContext";
import { removeExtension } from "../../services/client/utils.service";
import { getLiveStreamInfo } from "../../services/server/events";

export default function ConsultingPage(
props: InferGetStaticPropsType<typeof getStaticProps>
Expand Down Expand Up @@ -57,7 +59,7 @@ export default function ConsultingPage(
value={{ recaptchaKey: props.env.GOOGLE_RECAPTCHA_SITE_KEY }}
>
<SEO seo={props.seo} />
<Layout>
<Layout event={props.liveStreamEvent}>
<Section className="mx-auto w-full max-w-9xl px-8 py-5">
<Breadcrumbs
path={removeExtension(props.variables.relativePath)}
Expand Down Expand Up @@ -183,6 +185,8 @@ const parseCallToAction = (
};

export const getStaticProps = async ({ params }) => {
const events = await getLiveStreamInfo();

const tinaProps = await client.queries.consultingContentQuery({
relativePath: `${params.filename}.mdx`,
});
Expand Down Expand Up @@ -254,7 +258,9 @@ export const getStaticProps = async ({ params }) => {
process.env.GOOGLE_RECAPTCHA_SITE_KEY || null,
},
seo,
liveStreamEvent: events[0],
},
revalidate: isrRevalidateTime,
};
};

Expand Down
Loading
Loading