-
Notifications
You must be signed in to change notification settings - Fork 172
i18n support for sicp #3133
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
base: master
Are you sure you want to change the base?
i18n support for sicp #3133
Changes from 11 commits
5b990d8
f796bda
da13343
8546da1
32df0bd
ee2eae2
9ed14ba
859f560
f02d7dd
eb61bfd
2e63b78
62bc3dc
7356b7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,9 +1,15 @@ | ||||||||||||||
import { Tree, TreeNodeInfo } from '@blueprintjs/core'; | ||||||||||||||
import { NonIdealState, Spinner } from '@blueprintjs/core'; | ||||||||||||||
import { cloneDeep } from 'lodash'; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
import React, { useState } from 'react'; | ||||||||||||||
import { useNavigate } from 'react-router'; | ||||||||||||||
import Constants from 'src/commons/utils/Constants'; | ||||||||||||||
import { readSicpLangLocalStorage } from 'src/features/sicp/utils/SicpUtils'; | ||||||||||||||
|
||||||||||||||
import toc from '../../../features/sicp/data/toc.json'; | ||||||||||||||
import fallbackToc from '../../../features/sicp/data/toc.json'; | ||||||||||||||
|
||||||||||||||
const baseUrl = Constants.sicpBackendUrl + 'json/'; | ||||||||||||||
const loadingComponent = <NonIdealState title="Loading Content" icon={<Spinner />} />; | ||||||||||||||
|
||||||||||||||
type TocProps = OwnProps; | ||||||||||||||
|
||||||||||||||
|
@@ -14,8 +20,9 @@ type OwnProps = { | |||||||||||||
/** | ||||||||||||||
* Table of contents of SICP. | ||||||||||||||
*/ | ||||||||||||||
const SicpToc: React.FC<TocProps> = props => { | ||||||||||||||
const [sidebarContent, setSidebarContent] = useState(toc as TreeNodeInfo[]); | ||||||||||||||
|
||||||||||||||
const Toc: React.FC<{ toc: TreeNodeInfo[]; props: TocProps }> = ({ toc, props }) => { | ||||||||||||||
const [sidebarContent, setSidebarContent] = useState(toc); | ||||||||||||||
const navigate = useNavigate(); | ||||||||||||||
|
||||||||||||||
const handleNodeExpand = (_node: TreeNodeInfo, path: integer[]) => { | ||||||||||||||
|
@@ -40,15 +47,61 @@ const SicpToc: React.FC<TocProps> = props => { | |||||||||||||
[navigate, props] | ||||||||||||||
); | ||||||||||||||
|
||||||||||||||
return ( | ||||||||||||||
<Tree | ||||||||||||||
className="sicp-toc-tree" | ||||||||||||||
contents={sidebarContent} | ||||||||||||||
onNodeClick={handleNodeClicked} | ||||||||||||||
onNodeCollapse={handleNodeCollapse} | ||||||||||||||
onNodeExpand={handleNodeExpand} | ||||||||||||||
/> | ||||||||||||||
); | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
const SicpToc: React.FC<TocProps> = props => { | ||||||||||||||
const [lang, setLang] = useState(readSicpLangLocalStorage()); | ||||||||||||||
const [toc, setToc] = useState([] as TreeNodeInfo[]); | ||||||||||||||
const [loading, setLoading] = useState(true); | ||||||||||||||
const [error, setError] = useState(false); | ||||||||||||||
|
||||||||||||||
React.useEffect(() => { | ||||||||||||||
const handleLangChange = () => { | ||||||||||||||
setLang(readSicpLangLocalStorage()); | ||||||||||||||
}; | ||||||||||||||
window.addEventListener('sicp-tb-lang-change', handleLangChange); | ||||||||||||||
return () => window.removeEventListener('sicp-tb-lang-change', handleLangChange); | ||||||||||||||
}, []); | ||||||||||||||
|
||||||||||||||
React.useEffect(() => { | ||||||||||||||
setLoading(true); | ||||||||||||||
fetch(baseUrl + lang + '/toc.json') | ||||||||||||||
.then(response => { | ||||||||||||||
if (!response.ok) { | ||||||||||||||
throw Error(response.statusText); | ||||||||||||||
} | ||||||||||||||
return response.json(); | ||||||||||||||
}) | ||||||||||||||
.then(json => { | ||||||||||||||
setToc(json as TreeNodeInfo[]); | ||||||||||||||
}) | ||||||||||||||
.catch(error => { | ||||||||||||||
console.log(error); | ||||||||||||||
setError(true); | ||||||||||||||
}) | ||||||||||||||
.finally(() => { | ||||||||||||||
setLoading(false); | ||||||||||||||
}); | ||||||||||||||
}, [lang]); | ||||||||||||||
|
||||||||||||||
return ( | ||||||||||||||
<div className="sicp-toc"> | ||||||||||||||
<Tree | ||||||||||||||
className="sicp-toc-tree" | ||||||||||||||
contents={sidebarContent} | ||||||||||||||
onNodeClick={handleNodeClicked} | ||||||||||||||
onNodeCollapse={handleNodeCollapse} | ||||||||||||||
onNodeExpand={handleNodeExpand} | ||||||||||||||
/> | ||||||||||||||
{loading ? ( | ||||||||||||||
<div className="sicp-content">{loadingComponent}</div> | ||||||||||||||
) : error ? ( | ||||||||||||||
<Toc toc={fallbackToc as TreeNodeInfo[]} props={props} /> | ||||||||||||||
) : ( | ||||||||||||||
<Toc toc={toc} props={props} /> | ||||||||||||||
Comment on lines
+101
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Rather than passing a single
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
)} | ||||||||||||||
</div> | ||||||||||||||
); | ||||||||||||||
}; | ||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -50,6 +50,7 @@ const commonChildrenRoutes: RouteObject[] = [ | |||||||||||||
{ path: 'contributors', lazy: Contributors }, | ||||||||||||||
{ path: 'callback/github', lazy: GitHubCallback }, | ||||||||||||||
{ path: 'sicpjs/:section?', lazy: Sicp }, | ||||||||||||||
{ path: 'sicpjs/:param_lang/:section?', lazy: Sicp }, | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The route parameter is defined as
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback
Comment on lines
52
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This generic
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
{ path: 'features', lazy: Features } | ||||||||||||||
]; | ||||||||||||||
|
||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.