Skip to content

Commit a24abb1

Browse files
committed
Change to TypeScript
1 parent 1deb4a8 commit a24abb1

31 files changed

+16115
-100
lines changed

.eslintrc.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"env": {
3+
"browser": true
4+
},
5+
"extends": [
6+
"plugin:react/recommended",
7+
"standard"
8+
],
9+
"parser": "@typescript-eslint/parser",
10+
"parserOptions": {
11+
"ecmaFeatures": {
12+
"jsx": true
13+
},
14+
"ecmaVersion": 12,
15+
"sourceType": "module"
16+
},
17+
"plugins": [
18+
"react",
19+
"@typescript-eslint"
20+
],
21+
"rules": {
22+
"no-use-before-define": "off",
23+
"@typescript-eslint/no-use-before-define": "off"
24+
}
25+
}

package-lock.json

Lines changed: 15252 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@
77
"@testing-library/jest-dom": "^4.2.4",
88
"@testing-library/react": "^9.3.2",
99
"@testing-library/user-event": "^7.1.2",
10+
"@types/classnames": "^2.2.10",
11+
"@types/jest": "^26.0.14",
12+
"@types/node": "^14.11.2",
13+
"@types/react": "^16.9.49",
14+
"@types/react-dom": "^16.9.8",
15+
"@types/react-redux": "^7.1.9",
1016
"classnames": "^2.2.6",
11-
"date-fns": "^2.12.0",
17+
"date-fns": "^2.16.1",
1218
"faker": "^4.1.0",
1319
"miragejs": "^0.1.35",
1420
"react": "^16.13.1",
1521
"react-dom": "^16.13.1",
1622
"react-redux": "^7.2.0",
1723
"react-router-dom": "^5.1.2",
18-
"react-scripts": "3.4.1",
24+
"react-scripts": "^3.4.3",
1925
"seedrandom": "^3.0.5",
2026
"txtgen": "^2.2.4"
2127
},
@@ -41,6 +47,12 @@
4147
]
4248
},
4349
"devDependencies": {
44-
"prettier": "^2.0.2"
50+
"@types/react-router-dom": "^5.1.5",
51+
"@typescript-eslint/eslint-plugin": "^4.3.0",
52+
"@typescript-eslint/parser": "^4.3.0",
53+
"eslint": "^6.6.0",
54+
"prettier": "^2.0.2",
55+
"standardx": "^5.0.0",
56+
"typescript": "^4.0.3"
4557
}
4658
}

prettier.config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
module.exports = {
2-
"semi": false,
3-
"singleQuote": true
2+
semi: false,
3+
singleQuote: true
44
}
5-

src/App.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/App.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from 'react'
2+
import {
3+
BrowserRouter as Router,
4+
Switch,
5+
Route,
6+
Redirect
7+
} from 'react-router-dom'
8+
9+
import { Navbar } from './app/Navbar'
10+
import { PostsList } from './features/posts/PostsList'
11+
import { AddPostForm } from './features/posts/AddPostForm'
12+
import { SinglePostPage } from './features/posts/SinglePostPage'
13+
import { EditPostForm } from './features/posts/EditPostForm'
14+
import UserPage from './features/users/UserPage'
15+
import { NotificationsList } from './features/notifications/notificationList'
16+
import UsersList from './features/users/UsersList'
17+
18+
function App () {
19+
return (
20+
<Router>
21+
<Navbar />
22+
<div className='App'>
23+
<Switch>
24+
<Route
25+
exact
26+
path='/'
27+
render={() => (
28+
<>
29+
<AddPostForm />
30+
<PostsList />
31+
</>
32+
)}
33+
/>
34+
<Route exact path='/posts/:postId' component={SinglePostPage} />
35+
<Route exact path='/editPost/:postId' component={EditPostForm} />
36+
<Route exact path='/users' component={UsersList} />
37+
<Route exact path='/users/:userId' component={UserPage} />
38+
<Route exact path='/notifications' component={NotificationsList} />
39+
<Redirect to='/' />
40+
</Switch>
41+
</div>
42+
</Router>
43+
)
44+
}
45+
46+
export default App

src/api/client.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// A tiny wrapper around fetch(), borrowed from
22
// https://kentcdodds.com/blog/replace-axios-with-a-simple-custom-fetch-wrapper
33

4-
export async function client(endpoint, { body, ...customConfig } = {}) {
4+
export async function client (endpoint, { body, ...customConfig } = {}) {
55
const headers = { 'Content-Type': 'application/json' }
66

77
const config = {
88
method: body ? 'POST' : 'GET',
99
...customConfig,
1010
headers: {
1111
...headers,
12-
...customConfig.headers,
13-
},
12+
...customConfig.headers
13+
}
1414
}
1515

1616
if (body) {

src/api/server.js

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
belongsTo,
66
hasMany,
77
association,
8-
RestSerializer,
8+
RestSerializer
99
} from 'miragejs'
1010

1111
import { nanoid } from '@reduxjs/toolkit'
@@ -16,14 +16,14 @@ import { parseISO } from 'date-fns'
1616
import seedrandom from 'seedrandom'
1717

1818
const IdSerializer = RestSerializer.extend({
19-
serializeIds: 'always',
19+
serializeIds: 'always'
2020
})
2121

2222
// Set up a seeded random number generator, so that we get
2323
// a consistent set of users / entries each time the page loads.
2424
// This can be reset by deleting this localStorage value,
2525
// or turned off by setting `useSeededRNG` to false.
26-
let useSeededRNG = true
26+
const useSeededRNG = true
2727

2828
let rng = seedrandom()
2929

@@ -44,7 +44,7 @@ if (useSeededRNG) {
4444
faker.seed(seedDate.getTime())
4545
}
4646

47-
function getRandomInt(min, max) {
47+
function getRandomInt (min, max) {
4848
min = Math.ceil(min)
4949
max = Math.floor(max)
5050
return Math.floor(rng() * (max - min + 1)) + min
@@ -58,14 +58,15 @@ const randomFromArray = (array) => {
5858
const notificationTemplates = [
5959
'poked you',
6060
'says hi!',
61-
`is glad we're friends`,
62-
'sent you a gift',
61+
'is glad we\'re friends',
62+
'sent you a gift'
6363
]
6464

65+
// eslint-disable-next-line no-new
6566
new Server({
66-
routes() {
67+
routes () {
6768
this.namespace = 'fakeApi'
68-
//this.timing = 2000
69+
this.timing = 2000
6970

7071
this.resource('users')
7172
this.resource('posts')
@@ -120,7 +121,7 @@ new Server({
120121
message: template,
121122
user: user.id,
122123
read: false,
123-
isNew: true,
124+
isNew: true
124125
}
125126
})
126127

@@ -129,86 +130,86 @@ new Server({
129130
},
130131
models: {
131132
user: Model.extend({
132-
posts: hasMany(),
133+
posts: hasMany()
133134
}),
134135
post: Model.extend({
135136
user: belongsTo(),
136-
comments: hasMany(),
137+
comments: hasMany()
137138
}),
138139
comment: Model.extend({
139-
post: belongsTo(),
140+
post: belongsTo()
140141
}),
141-
notification: Model.extend({}),
142+
notification: Model.extend({})
142143
},
143144
factories: {
144145
user: Factory.extend({
145-
id() {
146+
id () {
146147
return nanoid()
147148
},
148-
firstName() {
149+
firstName () {
149150
return faker.name.firstName()
150151
},
151-
lastName() {
152+
lastName () {
152153
return faker.name.lastName()
153154
},
154-
name() {
155+
name () {
155156
return faker.name.findName(this.firstName, this.lastName)
156157
},
157-
username() {
158+
username () {
158159
return faker.internet.userName(this.firstName, this.lastName)
159160
},
160161

161-
afterCreate(user, server) {
162+
afterCreate (user, server) {
162163
server.createList('post', 3, { user })
163-
},
164+
}
164165
}),
165166
post: Factory.extend({
166-
id() {
167+
id () {
167168
return nanoid()
168169
},
169-
title() {
170+
title () {
170171
return sentence()
171172
},
172-
date() {
173+
date () {
173174
return faker.date.recent(7)
174175
},
175-
content() {
176+
content () {
176177
return article(1)
177178
},
178-
reactions() {
179+
reactions () {
179180
return {
180181
thumbsUp: 0,
181182
hooray: 0,
182183
heart: 0,
183184
rocket: 0,
184-
eyes: 0,
185+
eyes: 0
185186
}
186187
},
187-
afterCreate(post, server) {
188-
//server.createList('comment', 3, { post })
188+
afterCreate (post, server) {
189+
// server.createList('comment', 3, { post })
189190
},
190191

191-
user: association(),
192+
user: association()
192193
}),
193194
comment: Factory.extend({
194-
id() {
195+
id () {
195196
return nanoid()
196197
},
197-
date() {
198+
date () {
198199
return faker.date.past(2)
199200
},
200-
text() {
201+
text () {
201202
return paragraph()
202203
},
203-
post: association(),
204-
}),
204+
post: association()
205+
})
205206
},
206207
serializers: {
207208
user: IdSerializer,
208209
post: IdSerializer,
209-
comment: IdSerializer,
210+
comment: IdSerializer
210211
},
211-
seeds(server) {
212+
seeds (server) {
212213
server.createList('user', 3)
213-
},
214+
}
214215
})

src/app/Navbar.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)