Skip to content

Commit 03caab8

Browse files
fixing localeSelector by including page slug into graphql localeData fetch
1 parent 9d67dd0 commit 03caab8

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

configs/createPages.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ async function handleActivity(
9090
locale: activity.locale,
9191
id: activity.id,
9292
strapi_id: activity.strapi_id,
93+
slug: activityPath,
9394
},
9495
};
9596

@@ -150,6 +151,7 @@ async function handleActivityGroup(
150151
id: activityGroup?.id,
151152
strapi_id: activityGroup?.strapi_id,
152153
ageGroupId: activityGroupData?.age_group.strapi_id,
154+
slug: activityGroupPath,
153155
},
154156
};
155157

@@ -190,6 +192,7 @@ async function handleAgeGroup(
190192
locale: ageGroup?.locale,
191193
id: ageGroup.id,
192194
strapi_id: ageGroup.strapi_id,
195+
slug: ageGroupPath,
193196
},
194197
};
195198

@@ -360,6 +363,7 @@ async function createContentPage(
360363
locale: pageDataResponse.data?.strapiContentPage.locale,
361364
id: pageDataResponse?.data?.strapiContentPage.id,
362365
strapi_id: pageDataResponse?.data?.strapiContentPage.strapi_id,
366+
slug: pagePath,
363367
},
364368
};
365369

configs/typeDefs.gql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type SitePageContext @dontInfer {
1616
id: Int!
1717
strapi_id: Int
1818
ageGroupId: Int
19+
slug: String
1920
}
2021

2122
type ActivityLogo implements Node @dontInfer {

src/templates/activityGroupTemplate/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ query Query(
145145
$strapi_id: Int,
146146
$locale: String,
147147
$ageGroupId: Int,
148+
$slug: String,
148149
) {
149-
localeData: allSitePage(filter: { context: { locale: { eq: $locale } } }) {
150+
localeData: allSitePage(filter: { context: { locale: { eq: $locale }, slug: { eq: $slug } } }) {
150151
nodes {
151152
...SitePageLocaleFragment
152153
}

src/templates/activityTemplate/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ const ActivityPageTemplate = ({ path, data }: PageProps<ActivityQueryType, Activ
7474
export default ActivityPageTemplate;
7575

7676
export const query = graphql`
77-
query getActivity($strapi_id: Int, $locale: String, $type: String) {
78-
localeData: allSitePage(filter: { context: { locale: { eq: $locale }, type: { eq: $type } } }) {
77+
query getActivity(
78+
$strapi_id: Int,
79+
$locale: String,
80+
$type: String,
81+
$slug: String,
82+
) {
83+
localeData: allSitePage(filter: { context: { locale: { eq: $locale }, type: { eq: $type }, slug: { eq: $slug } } }) {
7984
nodes {
8085
...SitePageLocaleFragment
8186
}

src/templates/ageGroupTemplate/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,14 @@ const AgeGroupTemplate = ({ path, data }: PageProps<QueryType, AgeGroupPageTempl
103103
export default AgeGroupTemplate;
104104

105105
export const query = graphql`
106-
query AgeGroupQuery($locale: String, $strapi_id: Int, $id: String) {
106+
query AgeGroupQuery(
107+
$locale: String,
108+
$strapi_id: Int,
109+
$id: String,
110+
$slug: String,
111+
) {
107112
localeData: allSitePage(
108-
filter: {context: {locale: {eq: $locale}, type: {eq: "ActivityGroup"}}}
113+
filter: {context: {locale: {eq: $locale}, type: {eq: "ActivityGroup"}, slug: { eq: $slug }}}
109114
) {
110115
nodes {
111116
...SitePageLocaleFragment

src/templates/contentPageTemplate/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,13 @@ const ContentPageTemplate = ({ path, data }: PageProps<ContentPageQueryType, Con
6666
export default ContentPageTemplate;
6767

6868
export const query = graphql`
69-
query getContentPage($locale: String, $type: String, $id: String) {
70-
localeData: allSitePage(filter: { context: { locale: { eq: $locale }, type: { eq: $type } } }) {
69+
query getContentPage(
70+
$locale: String,
71+
$type: String,
72+
$id: String,
73+
$slug: String,
74+
) {
75+
localeData: allSitePage(filter: { context: { locale: { eq: $locale }, type: { eq: $type }, slug: { eq: $slug } } }) {
7176
nodes {
7277
...SitePageLocaleFragment
7378
}

0 commit comments

Comments
 (0)