Skip to content

Commit 8841ecd

Browse files
Merge pull request #7431 from rishiraj38/fix-gsoc-dropdown
fix: restore gsoc dropdown on program pages
2 parents 328a5a1 + 32fe9d0 commit 8841ecd

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

gatsby-node.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,10 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
328328
programs.forEach((program) => {
329329
envCreatePage({
330330
path: program.fields.slug,
331-
component: `${ProgramPostTemplate}?__contentFilePath=${program.internal.contentFilePath}`,
331+
component: `${MultiProgramPostTemplate}?__contentFilePath=${program.internal.contentFilePath}`,
332332
context: {
333333
slug: program.fields.slug,
334+
program: program.frontmatter.program,
334335
},
335336
});
336337
});

src/sections/Careers/Careers-Programs-single/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const ProgramsSingle = ({ data, children, options, setActiveOption, activeOption
3030
styles={selectStyles}
3131
options={options}
3232
value={options[activeOption]}
33-
onChange={(e) => setActiveOption(() => e.value)}
33+
onChange={(e) => setActiveOption(e.value)}
3434
theme={dropdownTheme}
3535
/>}
3636
</div>

src/templates/program-multiple.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from "react";
1+
import React, { useMemo } from "react";
22
import { graphql } from "gatsby";
33

44
import SEO from "../components/seo";
@@ -23,17 +23,21 @@ export const query = graphql`query ProgramByName($program: String!) {
2323
}
2424
}`;
2525

26-
const ProgramsPage = ({ data, children }) => {
27-
const [activeOption] = useState(0);
26+
const ProgramsPage = ({ data, children, pageContext }) => {
2827
const programs = data.allMdx.nodes;
2928
const { navigate } = require("gatsby");
3029

31-
const options = programs.map((program) => {
30+
const activeOption = useMemo(() => {
31+
const initialIndex = programs.findIndex((program) => program.fields.slug === pageContext.slug);
32+
return initialIndex !== -1 ? initialIndex : 0;
33+
}, [programs, pageContext.slug]);
34+
35+
const options = useMemo(() => programs.map((program) => {
3236
let optionItem = new Object();
3337
optionItem.label = program.frontmatter.title;
3438
optionItem.value = program.fields.slug;
3539
return optionItem;
36-
});
40+
}), [programs]);
3741
return (
3842

3943
<>

0 commit comments

Comments
 (0)