Skip to content

Commit 4c80ed8

Browse files
committed
refactor: Swap in useRoute where possible
1 parent c5c65d1 commit 4c80ed8

9 files changed

Lines changed: 24 additions & 24 deletions

File tree

src/components/controllers/blog-page.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRoute, useLocation } from 'preact-iso';
1+
import { useRoute } from 'preact-iso';
22
import { useContent } from '../../lib/use-resource';
33
import { useTitle, useDescription } from './utils';
44
import { NotFound } from './not-found';
@@ -20,7 +20,7 @@ export default function BlogPage() {
2020
}
2121

2222
function BlogLayout() {
23-
const { path } = useLocation();
23+
const { path } = useRoute();
2424
const [lang] = useLanguage();
2525

2626
const { html, meta } = useContent([lang, path === '/' ? 'index' : path]);

src/components/controllers/doc-page.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRoute, useLocation } from 'preact-iso';
1+
import { useRoute } from 'preact-iso';
22
import { useContent } from '../../lib/use-resource';
33
import { useTitle, useDescription } from './utils';
44
import config from '../../config.json';
@@ -24,7 +24,7 @@ export function DocPage() {
2424
}
2525

2626
export function DocLayout({ isGuide = false }) {
27-
const { path } = useLocation();
27+
const { path } = useRoute();
2828
const [lang] = useLanguage();
2929

3030
const { html, meta } = useContent([lang, path === '/' ? 'index' : path]);

src/components/controllers/markdown-region.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useLocation } from 'preact-iso';
1+
import { useRoute } from 'preact-iso';
22
import EditThisPage from '../edit-button';
33
import ContentRegion from '../content-region';
44
import BlogMeta from '../blog-meta';
@@ -10,7 +10,7 @@ import BlogMeta from '../blog-meta';
1010
* @propery {any} [components]
1111
*/
1212
export function MarkdownRegion({ html, meta, components }) {
13-
const { path } = useLocation();
13+
const { path } = useRoute();
1414

1515
const canEdit = path !== '/' && !path.startsWith('/tutorial');
1616
const isBlogArticle = path.startsWith('/blog/');

src/components/controllers/tutorial-page.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRoute, useLocation } from 'preact-iso';
1+
import { useRoute } from 'preact-iso';
22
import { SolutionProvider } from './tutorial/contexts';
33
import { useContent } from '../../lib/use-resource';
44
import { useTitle, useDescription } from './utils';
@@ -19,8 +19,7 @@ export default function TutorialPage() {
1919
}
2020

2121
function TutorialLayout() {
22-
const { path } = useLocation();
23-
const { params } = useRoute();
22+
const { path, params } = useRoute();
2423
const [lang] = useLanguage();
2524

2625
const { html, meta } = useContent([lang, !params.step ? 'tutorial/index' : path]);

src/components/controllers/tutorial/index.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
useMemo,
99
useCallback
1010
} from 'preact/hooks';
11-
import { useLocation } from 'preact-iso';
11+
import { useRoute } from 'preact-iso';
1212
import linkState from 'linkstate';
1313
import { TutorialContext, SolutionContext } from './contexts';
1414
import cx from '../../../lib/cx';
@@ -168,7 +168,7 @@ function TutorialView({
168168

169169
const [showCodeOverride, toggleCode] = useReducer(s => !s, true);
170170

171-
const { url } = useLocation();
171+
const { path } = useRoute();
172172
const [lang] = useLanguage();
173173
const { solved } = useContext(SolutionContext);
174174

@@ -183,7 +183,7 @@ function TutorialView({
183183
if (!loading && !initialLoad) {
184184
content.current.scrollTo(0, 0);
185185
}
186-
}, [url, loading, initialLoad]);
186+
}, [path, loading, initialLoad]);
187187

188188
const reRun = useCallback(() => {
189189
let code = tutorial.state.code;
@@ -211,7 +211,7 @@ function TutorialView({
211211
<div class={style.output} key="output">
212212
{!initialLoad && (
213213
<Runner
214-
key={url}
214+
key={path}
215215
ref={tutorial.runner}
216216
onSuccess={tutorial.onSuccess}
217217
onRealm={tutorial.onRealm}
@@ -226,7 +226,7 @@ function TutorialView({
226226
close
227227
</button>
228228
<ErrorOverlay
229-
key={'e:' + url}
229+
key={'e:' + path}
230230
class={style.error}
231231
name={error.name}
232232
message={error.message}
@@ -298,7 +298,7 @@ function TutorialView({
298298
</Splitter>
299299

300300
<InjectPrerenderData
301-
name={url}
301+
name={path}
302302
data={{
303303
html,
304304
meta

src/components/doc-version/index.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ export const AVAILABLE_DOCS = ['10', '8'];
1010
* Select box to switch the currently displayed docs version
1111
*/
1212
export default function DocVersion() {
13-
const { path, route } = useLocation();
14-
const { version, name } = useRoute().params;
13+
const { route } = useLocation();
14+
const { params, path } = useRoute();
15+
const { version, name } = params;
1516

1617
const onChange = useCallback(
1718
e => {

src/components/edit-button/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { useLocation } from 'preact-iso';
1+
import { useRoute } from 'preact-iso';
22
import { useLanguage } from '../../lib/i18n';
33
import style from './style.module.css';
44

55
export default function EditThisPage({ isFallback }) {
6-
let { path } = useLocation();
6+
let { path } = useRoute();
77
const [lang] = useLanguage();
88

99
path = !isFallback ? path + '.md' : '';

src/components/footer/index.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import config from '../../config.json';
22
import { useState, useEffect, useCallback } from 'preact/hooks';
3-
import { useLocation } from 'preact-iso';
3+
import { useRoute } from 'preact-iso';
44
import style from './style.module.css';
55
import { useLanguage } from '../../lib/i18n';
66

@@ -42,8 +42,8 @@ function useContributors(deps) {
4242
}
4343

4444
export default function Footer() {
45-
const { url } = useLocation();
46-
const contrib = useContributors([url]);
45+
const { path } = useRoute();
46+
const contrib = useContributors([path]);
4747
const [lang, setLang] = useLanguage();
4848

4949
const onSelect = useCallback(e => setLang(e.target.value), [setLang]);

src/components/sidebar/sidebar-nav.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useLocation } from 'preact-iso';
1+
import { useRoute } from 'preact-iso';
22
import cx from '../../lib/cx';
33
import style from './sidebar-nav.module.css';
44

@@ -13,7 +13,7 @@ import style from './sidebar-nav.module.css';
1313
* @param {SidebarNavProps} props
1414
*/
1515
export default function SidebarNav({ items, onClick }) {
16-
const { path } = useLocation();
16+
const { path } = useRoute();
1717

1818
return (
1919
<nav

0 commit comments

Comments
 (0)