Skip to content
This repository was archived by the owner on Apr 30, 2026. It is now read-only.

Commit b3097e5

Browse files
committed
Use useHistory from react-router
1 parent b2d957f commit b3097e5

4 files changed

Lines changed: 122 additions & 138 deletions

File tree

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
"test": "yarn lint && yarn build"
2020
},
2121
"dependencies": {
22-
"@material-ui/core": "^4.5.1",
23-
"@material-ui/styles": "^4.5.0",
24-
"chrome-extension-async": "^3.4.0",
22+
"@material-ui/core": "^4.6.0",
23+
"@material-ui/styles": "^4.6.0",
24+
"chrome-extension-async": "^3.4.1",
2525
"clean-webpack-plugin": "^3.0.0",
2626
"js-beautify": "^1.10.2",
2727
"lodash": "^4.17.15",
@@ -36,12 +36,12 @@
3636
},
3737
"devDependencies": {
3838
"@types/chrome": "^0.0.91",
39-
"@types/jasmine": "^3.4.4",
40-
"@types/jest": "^24.0.20",
39+
"@types/jasmine": "^3.4.6",
40+
"@types/jest": "^24.0.22",
4141
"@types/react": "^16.9.11",
4242
"@types/react-dom": "^16.9.3",
43-
"@typescript-eslint/eslint-plugin": "^2.5.0",
44-
"@typescript-eslint/parser": "^2.5.0",
43+
"@typescript-eslint/eslint-plugin": "^2.6.1",
44+
"@typescript-eslint/parser": "^2.6.1",
4545
"babel-eslint": "^10.0.3",
4646
"chrome-webstore-upload-cli": "^1.2.0",
4747
"codecov": "^3.6.1",
@@ -54,7 +54,7 @@
5454
"eslint": "^6.6.0",
5555
"eslint-plugin-typescript": "^0.14.0",
5656
"file-loader": "^4.2.0",
57-
"fork-ts-checker-webpack-plugin": "^2.0.0",
57+
"fork-ts-checker-webpack-plugin": "^3.0.1",
5858
"hard-source-webpack-plugin": "^0.13.1",
5959
"html-loader": "^0.5.5",
6060
"html-webpack-plugin": "^3.2.0",
@@ -78,9 +78,9 @@
7878
"terser-webpack-plugin": "^2.2.1",
7979
"ts-jest": "^24.1.0",
8080
"ts-loader": "^6.2.1",
81-
"typescript": "^3.6.4",
81+
"typescript": "^3.7.2",
8282
"typescript-eslint-parser": "^22.0.0",
83-
"web-ext": "^3.2.0",
83+
"web-ext": "^3.2.1",
8484
"webpack": "4.39.3",
8585
"webpack-bundle-analyzer": "^3.6.0",
8686
"webpack-dev-server": "^3.9.0",

src/js/components/Hosts.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React from 'react'
22
import { getHostKey } from 'libs'
3-
import { withRouter } from 'react-router'
3+
import { useHistory } from 'react-router-dom'
44
import queryString from 'query-string'
55
import { useStore } from './StoreContext'
66
import { observer } from 'mobx-react'
77
import { MenuItem, FormControl, Select } from '@material-ui/core'
88

9-
const Hosts = observer(props => {
9+
export default observer(props => {
10+
const history = useHistory()
1011
const { hosts, matchedHost = '' } = useStore().AppStore
1112
const options = hosts.map(host => {
1213
const key = getHostKey(host)
@@ -29,13 +30,11 @@ const Hosts = observer(props => {
2930
} else {
3031
Object.assign(query, value)
3132
}
32-
props.history.push(`?${queryString.stringify(query)}`)
33+
history.push(`?${queryString.stringify(query)}`)
3334
}}
3435
>
3536
{options}
3637
</Select>
3738
</FormControl>
3839
)
3940
})
40-
41-
export default withRouter(Hosts)

src/js/components/NewPattern.tsx

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { withRouter } from 'react-router'
2+
import { useHistory } from 'react-router-dom'
33
import queryString from 'query-string'
44
import { useStore } from './StoreContext'
55
import { observer } from 'mobx-react'
@@ -26,49 +26,48 @@ const Content = () => (
2626
</DialogContentText>
2727
)
2828

29-
const NewPatternDialog = withRouter(
30-
observer(props => {
31-
const { NewPatternStore } = useStore()
32-
const { closeDialog, error, validPattern, pattern } = NewPatternStore
33-
return (
34-
<Dialog open onClose={closeDialog}>
35-
<DialogTitle>New RegExp Pattern</DialogTitle>
36-
<DialogContent>
37-
<Content />
38-
<FormControl fullWidth error={!validPattern}>
39-
<TextField
40-
autoFocus
41-
margin='dense'
42-
type='text'
43-
placeholder='.*github.com'
44-
label='RegExp Pattern'
45-
error={!validPattern}
46-
value={pattern}
47-
onChange={e => {
48-
NewPatternStore.setPattern(e.target.value)
49-
}}
50-
/>
51-
<FormHelperText>{error}</FormHelperText>
52-
</FormControl>
53-
</DialogContent>
54-
<DialogActions>
55-
<Button onClick={closeDialog}>Cancel</Button>
56-
<Button
57-
color='primary'
58-
onClick={() => {
59-
const { addToHosts, host } = NewPatternStore
60-
addToHosts()
61-
props.history.push(`?${queryString.stringify(host)}`)
29+
const NewPatternDialog = observer(() => {
30+
const history = useHistory()
31+
const { NewPatternStore } = useStore()
32+
const { closeDialog, error, validPattern, pattern } = NewPatternStore
33+
return (
34+
<Dialog open onClose={closeDialog}>
35+
<DialogTitle>New RegExp Pattern</DialogTitle>
36+
<DialogContent>
37+
<Content />
38+
<FormControl fullWidth error={!validPattern}>
39+
<TextField
40+
autoFocus
41+
margin='dense'
42+
type='text'
43+
placeholder='.*github.com'
44+
label='RegExp Pattern'
45+
error={!validPattern}
46+
value={pattern}
47+
onChange={e => {
48+
NewPatternStore.setPattern(e.target.value)
6249
}}
63-
disabled={!validPattern}
64-
>
65-
Add
66-
</Button>
67-
</DialogActions>
68-
</Dialog>
69-
)
70-
})
71-
)
50+
/>
51+
<FormHelperText>{error}</FormHelperText>
52+
</FormControl>
53+
</DialogContent>
54+
<DialogActions>
55+
<Button onClick={closeDialog}>Cancel</Button>
56+
<Button
57+
color='primary'
58+
onClick={() => {
59+
const { addToHosts, host } = NewPatternStore
60+
addToHosts()
61+
history.push(`?${queryString.stringify(host)}`)
62+
}}
63+
disabled={!validPattern}
64+
>
65+
Add
66+
</Button>
67+
</DialogActions>
68+
</Dialog>
69+
)
70+
})
7271

7372
export default observer(() => {
7473
// TODO: support to use current domain

0 commit comments

Comments
 (0)