Skip to content

Commit 5dafe52

Browse files
committed
junk: REVERT ME
1 parent bee7880 commit 5dafe52

20 files changed

Lines changed: 624 additions & 651 deletions

File tree

src/components/controllers/page.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import style from './style.module.css';
99
// Supports generic pages like `/`, `/about/*`, `/blog`, etc.
1010
export function Page() {
1111
const { path } = useRoute();
12-
const isValidRoute = navRoutes[path];
12+
const isValidRoute = true;
1313

1414
return (
1515
<ErrorBoundary>

src/components/controllers/tutorial/index.jsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import { TutorialContext, SolutionContext } from './contexts';
1313
import { parseStackTrace } from '../repl/errors';
1414
import cx from '../../../lib/cx';
1515
import { CodeEditor, Runner, ErrorOverlay, Splitter } from '../../routes';
16-
import { useLanguage } from '../../../lib/i18n';
17-
import config from '../../../config.json';
1816
import { MarkdownRegion } from '../markdown-region';
1917
import style from './style.module.css';
18+
import englishTranslations from '../../../locales/en.json';
2019

2120
const resultHandlers = new Set();
2221
const realmHandlers = new Set();
@@ -75,7 +74,6 @@ export function Tutorial({ html, meta }) {
7574
return () => clearTimeout(delay);
7675
}, [editorCode]);
7776

78-
7977
const useResult = fn => {
8078
useEffect(() => {
8179
resultHandlers.add(fn);
@@ -197,15 +195,15 @@ export function Tutorial({ html, meta }) {
197195
components={TUTORIAL_COMPONENTS}
198196
/>
199197

200-
{meta.tutorial?.setup &&
198+
{meta.tutorial?.setup && (
201199
<TutorialSetupBlock
202200
code={meta.tutorial.setup}
203201
runner={runner}
204202
useResult={useResult}
205203
useRealm={useRealm}
206204
useError={useError}
207205
/>
208-
}
206+
)}
209207

210208
<ButtonContainer meta={meta} showCode={showCode} help={help} />
211209
</div>
@@ -217,13 +215,11 @@ export function Tutorial({ html, meta }) {
217215
}
218216

219217
function ButtonContainer({ meta, showCode, help }) {
220-
const [lang] = useLanguage();
221-
222218
return (
223219
<div class={style.buttonContainer}>
224220
{meta.prev && (
225221
<a class={style.prevButton} href={meta.prev}>
226-
{config.i18n.previous[lang] || config.i18n.previous.en}
222+
{englishTranslations.previous}
227223
</a>
228224
)}
229225
{meta.solvable && (
@@ -233,16 +229,14 @@ function ButtonContainer({ meta, showCode, help }) {
233229
disabled={!showCode}
234230
title="Show solution to this example"
235231
>
236-
{config.i18n.tutorial.solve[lang] ||
237-
config.i18n.tutorial.solve.en}
232+
{englishTranslations.tutorial.solve}
238233
</button>
239234
)}
240235
{meta.next && (
241236
<a class={style.nextButton} href={meta.next}>
242237
{meta.code == false
243-
? (config.i18n.tutorial.begin[lang] || config.i18n.tutorial.begin.en)
244-
: (config.i18n.next[lang] || config.i18n.next.en)
245-
}
238+
? englishTranslations.tutorial.begin
239+
: englishTranslations.next}
246240
</a>
247241
)}
248242
</div>

src/components/header/index.jsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import ReleaseLink from './gh-version';
88
import Corner from './corner';
99
import { useOverlayToggle } from '../../lib/toggle-overlay';
1010
import { useLocation } from 'preact-iso';
11-
import { useLanguage, useTranslation, useNavTranslation } from '../../lib/i18n';
11+
import {
12+
useLanguage,
13+
useTranslation,
14+
usePathTranslation
15+
} from '../../lib/i18n';
1216
import { prefetchContent } from '../../lib/use-content';
1317
import { ReplPage, TutorialPage, CodeEditor } from '../routes';
1418

@@ -44,7 +48,7 @@ export default function Header() {
4448

4549
function MainNav() {
4650
const { path, route } = useLocation();
47-
const about = useNavTranslation('/about');
51+
const about = usePathTranslation('/about');
4852

4953
const brandingRedirect = e => {
5054
e.preventDefault();
@@ -255,9 +259,13 @@ const prefetchAndPreload = href => {
255259
prefetchContent(href);
256260
};
257261

262+
/**
263+
* @typedef {import('../../locales/en.json')} Translations
264+
*/
265+
258266
/**
259267
* @typedef {Object} NavLinkProps
260-
* @property {string} props.href
268+
* @property {keyof Translations['headerNav']} props.href
261269
* @property {string} [props.clsx]
262270
* @property {import('preact').ComponentChildren} [props.flair]
263271
* @property {boolean} [props.isOpen]
@@ -268,7 +276,7 @@ const prefetchAndPreload = href => {
268276
*/
269277
function NavLink({ href, flair, clsx, isOpen, ...rest }) {
270278
const { path } = useLocation();
271-
const label = useNavTranslation(href);
279+
const label = usePathTranslation(href);
272280

273281
return (
274282
<a

src/components/sidebar/index.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import SidebarNav from './sidebar-nav';
44
import config from '../../config.json';
55
import { useOverlayToggle } from '../../lib/toggle-overlay';
66
import {
7-
useLanguage,
8-
getSidebarRouteName,
9-
getHeaderRouteName
7+
useLanguage
8+
//getSidebarRouteName,
9+
//getHeaderRouteName
1010
} from '../../lib/i18n';
1111
import style from './style.module.css';
1212

@@ -21,26 +21,26 @@ export default function Sidebar() {
2121
for (const item of config.docs[version]) {
2222
if ('routes' in item) {
2323
navItems.push({
24-
text: getSidebarRouteName(item.name, lang),
24+
text: '',
2525
level: 2,
2626
href: null,
2727
routes: item.routes.map(nested => ({
28-
text: getSidebarRouteName(nested.name, lang),
28+
text: '',
2929
level: 3,
3030
href: `/guide/${version}${nested.path}`
3131
}))
3232
});
3333
} else {
3434
navItems.push({
35-
text: getSidebarRouteName(item.name, lang),
35+
text: '',
3636
level: 2,
3737
href: `/guide/${version}${item.path}`
3838
});
3939
}
4040
}
4141

4242
// TODO: Is "Guide" really the best label for the button?
43-
const mobileButtonLabel = getHeaderRouteName('guide', lang);
43+
const mobileButtonLabel = '';
4444

4545
return (
4646
<div class={style.wrapper} data-open={open}>

src/config.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* @typedef {import('./locales/en.json')} Translations
3+
*/
4+
5+
/**
6+
* @type {Record<string, { label: keyof Translations['headerNav'] }>}
7+
*/
8+
export const headerNav = {
9+
'/': {
10+
label: 'home'
11+
},
12+
'/tutorial': {
13+
label: 'tutorial'
14+
},
15+
'/guide/v10/getting-started': {
16+
label: 'guide'
17+
},
18+
'/about': {
19+
label: 'about'
20+
},
21+
'/about/we-are-using': {
22+
label: 'weAreUsing'
23+
},
24+
'/about/libraries-addons': {
25+
label: 'librariesAddons'
26+
},
27+
'/about/demos-examples': {
28+
label: 'demosExamples'
29+
},
30+
'/about/project-goals': {
31+
label: 'projectGoals'
32+
},
33+
'/about/browser-support': {
34+
label: 'browserSupport'
35+
},
36+
'/blog': {
37+
label: 'blog'
38+
},
39+
'/repl': {
40+
label: 'repl'
41+
}
42+
};
43+
44+
/**
45+
* @type {Record<string, { label: keyof Translations['tutorialPages'] }>}
46+
*/
47+
export const tutorialPages = {
48+
'/tutorial': {
49+
label: 'learnPreact'
50+
},
51+
'/tutorial/01-vdom': {
52+
label: 'virtualDom'
53+
},
54+
'/tutorial/02-events': {
55+
label: 'events'
56+
},
57+
'/tutorial/03-components': {
58+
label: 'components'
59+
},
60+
'/tutorial/04-state': {
61+
label: 'state'
62+
},
63+
'/tutorial/05-refs': {
64+
label: 'refs'
65+
},
66+
'/tutorial/06-context': {
67+
label: 'context'
68+
},
69+
'/tutorial/07-side-effects': {
70+
label: 'sideEffects'
71+
},
72+
'/tutorial/08-keys': {
73+
label: 'keys'
74+
},
75+
'/tutorial/09-error-handling': {
76+
label: 'errorHandling'
77+
},
78+
'/tutorial/10-links': {
79+
label: 'congratulations'
80+
}
81+
};

0 commit comments

Comments
 (0)