Skip to content

Commit 318d387

Browse files
fix(website): fix scrolling and hashes
1 parent 14d2cc6 commit 318d387

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

packages/overmind-website/src/components/Api/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createElement, SFC, useState, useEffect } from 'react'
22
import { useOvermind } from '../../overmind'
33
import Doc from '../Doc'
44
import * as styles from './styles'
5-
import { compile, getGithubBaseUrl } from '../../utils'
5+
import { compile, getGithubBaseUrl, useScrollToPosition } from '../../utils'
66
import { css } from 'emotion'
77

88
function getGithubUrl(name) {
@@ -13,11 +13,13 @@ const Api: SFC = () => {
1313
const { state } = useOvermind()
1414
const [content, setContent] = useState(null)
1515

16+
useScrollToPosition(content)
17+
1618
useEffect(
1719
() => {
18-
import('../../../api/' + state.currentApi + '.md').then((module) =>
20+
import('../../../api/' + state.currentApi + '.md').then((module) => {
1921
setContent(module)
20-
)
22+
})
2123
},
2224
[state.currentApi]
2325
)

packages/overmind-website/src/overmind/effects.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,26 @@ export const router = (() => {
2323
view: storage.get('theme'),
2424
typescript: storage.get('typescript'),
2525
}
26+
let currentHash = location.hash
2627

2728
return {
2829
getPath() {
2930
return currentPath
3031
},
3132
route(url: string, action: (payload: RouteContext) => void) {
32-
page(url, ({ params, pathname, querystring }) => {
33+
page(url, ({ params, pathname, path, querystring }) => {
3334
// We want to preserve the query
3435
if (!querystring) {
36+
if (location.hash === currentHash) {
37+
currentHash = ''
38+
} else {
39+
currentHash = location.hash
40+
}
41+
3542
page.redirect(
3643
`${pathname}?view=${currentQuery.view}&typescript=${
3744
currentQuery.typescript
38-
}${location.hash}`
45+
}${currentHash}`
3946
)
4047
return
4148
}

0 commit comments

Comments
 (0)