@@ -2,14 +2,21 @@ import React, { createContext, useContext, useState } from 'react'
22import { CodeLanguage , PlaygroundArticleT } from 'components/playground/types'
33import { useRouter } from 'next/router'
44
5- import jsArticle from 'components/playground/content/building-and-testing/nodejs'
6- import pyArticle from 'components/playground/content/building-and-testing/python'
5+ import actionsJsArticle from 'components/playground/content/actions/guides/building-and-testing-nodejs-or-python/nodejs'
6+ import actionsPyArticle from 'components/playground/content/actions/guides/building-and-testing-nodejs-or-python/python'
7+ import codespacesJsArticle from 'components/playground/content/codespaces/setting-up-your-project-for-codespaces/setting-up-your-project-for-codespaces/nodejs'
8+ import codespacesPyArticle from 'components/playground/content/codespaces/setting-up-your-project-for-codespaces/setting-up-your-project-for-codespaces/python'
9+ import codespacesNetArticle from 'components/playground/content/codespaces/setting-up-your-project-for-codespaces/setting-up-your-project-for-codespaces/dotnet'
10+ import codespacesJavaArticle from 'components/playground/content/codespaces/setting-up-your-project-for-codespaces/setting-up-your-project-for-codespaces/java'
711
8- const articles = [ jsArticle , pyArticle ]
9- const articlesByLangId = articles . reduce ( ( obj , item ) => {
10- obj [ item . codeLanguageId ] = item
11- return obj
12- } , { } as Record < string , PlaygroundArticleT | undefined > )
12+ const articles = [
13+ actionsJsArticle ,
14+ actionsPyArticle ,
15+ codespacesJsArticle ,
16+ codespacesPyArticle ,
17+ codespacesJavaArticle ,
18+ codespacesNetArticle ,
19+ ]
1320
1421const codeLanguages : Array < CodeLanguage > = [
1522 {
@@ -20,6 +27,14 @@ const codeLanguages: Array<CodeLanguage> = [
2027 id : 'py' ,
2128 label : 'Python' ,
2229 } ,
30+ {
31+ id : 'dotnet' ,
32+ label : 'C#' ,
33+ } ,
34+ {
35+ id : 'java' ,
36+ label : 'Java' ,
37+ } ,
2338]
2439
2540type PlaygroundContextT = {
@@ -48,19 +63,26 @@ export const PlaygroundContextProvider = (props: { children: React.ReactNode })
4863 const router = useRouter ( )
4964 const [ activeSectionIndex , setActiveSectionIndex ] = useState ( 0 )
5065 const [ scrollToSection , setScrollToSection ] = useState < number > ( )
66+ const path = router . asPath . split ( '?' ) [ 0 ]
67+ const relevantArticles = articles . filter ( ( { slug } ) => slug === path )
68+
5169 const { langId } = router . query
52- const currentLanguage = codeLanguages . find ( ( { id } ) => id === langId ) || codeLanguages [ 0 ]
53- const availableLanguages = codeLanguages . filter ( ( { id } ) => ! ! articlesByLangId [ id ] )
70+ const availableLanguageIds = relevantArticles . map ( ( { codeLanguageId } ) => codeLanguageId )
71+ const currentLanguage =
72+ codeLanguages . find ( ( { id } ) => id === langId ) ||
73+ ( codeLanguages . find ( ( { id } ) => id === availableLanguageIds [ 0 ] ) as CodeLanguage )
5474
55- const article = articlesByLangId [ currentLanguage . id ]
75+ const article = relevantArticles . find (
76+ ( { codeLanguageId } ) => codeLanguageId === currentLanguage ?. id
77+ )
5678
5779 const context = {
5880 activeSectionIndex,
5981 setActiveSectionIndex,
6082 scrollToSection,
6183 setScrollToSection,
6284 currentLanguage,
63- codeLanguages : availableLanguages ,
85+ codeLanguages : codeLanguages . filter ( ( { id } ) => availableLanguageIds . includes ( id ) ) ,
6486 article,
6587 }
6688
0 commit comments