Skip to content

Commit e64573e

Browse files
zhouzigaearon
authored andcommitted
Fix real world to be case insensitive (#1685)
1 parent 004b780 commit e64573e

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

examples/real-world/containers/RepoPage.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ RepoPage.propTypes = {
7373
}
7474

7575
function mapStateToProps(state, ownProps) {
76-
const { login, name } = ownProps.params
76+
// We need to lower case the login/name due to the way GitHub's API behaves.
77+
// Have a look at ../middleware/api.js for more details.
78+
const login = ownProps.params.login.toLowerCase()
79+
const name = ownProps.params.name.toLowerCase()
80+
7781
const {
7882
pagination: { stargazersByRepo },
7983
entities: { users, repos }

examples/real-world/containers/UserPage.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ UserPage.propTypes = {
7373
}
7474

7575
function mapStateToProps(state, ownProps) {
76-
const { login } = ownProps.params
76+
// We need to lower case the login due to the way GitHub's API behaves.
77+
// Have a look at ../middleware/api.js for more details.
78+
const login = ownProps.params.login.toLowerCase()
79+
7780
const {
7881
pagination: { starredByUser },
7982
entities: { users, repos }

examples/real-world/middleware/api.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,17 @@ function callApi(endpoint, schema) {
5050

5151
// Read more about Normalizr: https://github.com/gaearon/normalizr
5252

53+
// GitHub's API may return results with uppercase letters while the query
54+
// doesn't contain any. For example, "someuser" could result in "SomeUser"
55+
// leading to a frozen UI as it wouldn't find "someuser" in the entities.
56+
// That's why we're forcing lower cases down there.
57+
5358
const userSchema = new Schema('users', {
54-
idAttribute: 'login'
59+
idAttribute: user => user.login.toLowerCase()
5560
})
5661

5762
const repoSchema = new Schema('repos', {
58-
idAttribute: 'fullName'
63+
idAttribute: repo => repo.fullName.toLowerCase()
5964
})
6065

6166
repoSchema.define({

0 commit comments

Comments
 (0)