Skip to content

Commit 85f56e3

Browse files
authored
Merge pull request #1274 from dacadeorg/chore/isr-demo
chore(demo): implement ISR on the community view page
2 parents 26fda2b + 52e2378 commit 85f56e3

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/pages/communities/[slug]/index.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { fetchAllChallenges } from "@/store/services/communities/challenges";
1212
import { NotFoundError } from "@/utilities/errors/NotFoundError";
1313
import { fetchAllScoreboards } from "@/store/services/communities/scoreboard.service";
1414
import { useTranslation } from "next-i18next";
15+
import { fetchCommunities } from "@/services/community";
16+
import { GetStaticPathsContext } from "next";
1517

1618
export default function Slug(props: {
1719
pageProps: {
@@ -41,7 +43,7 @@ Slug.getLayout = function (page: ReactElement) {
4143
return <CommunityLayout>{page}</CommunityLayout>;
4244
};
4345

44-
export const getServerSideProps = wrapper.getServerSideProps((store) => async ({ params, locale }) => {
46+
export const getStaticProps = wrapper.getStaticProps((store: any) => async ({ locale, params }) => {
4547
try {
4648
const slug = params?.slug as string;
4749

@@ -59,10 +61,27 @@ export const getServerSideProps = wrapper.getServerSideProps((store) => async ({
5961
scoreboard,
6062
...translations,
6163
},
64+
65+
revalidate: 60 * 60 * 24,
6266
};
6367
} catch (error) {
6468
return {
6569
notFound: true,
6670
};
6771
}
6872
});
73+
74+
export const getStaticPaths = async (context: GetStaticPathsContext) => {
75+
const locale = context.defaultLocale;
76+
const communities = await fetchCommunities({ locale: locale ?? "en" });
77+
const paths = communities.map((community) => ({
78+
params: {
79+
slug: community.slug,
80+
},
81+
}));
82+
83+
return {
84+
paths,
85+
fallback: "blocking",
86+
};
87+
};

0 commit comments

Comments
 (0)