Skip to content

refactor: migrate search screen to the new API #758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 0 additions & 103 deletions __tests__/tests/reducers/search.reducer.js

This file was deleted.

2 changes: 0 additions & 2 deletions root.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { userReducer } from 'user';
import { repositoryReducer } from 'repository';
import { organizationReducer } from 'organization';
import { issueReducer } from 'issue';
import { searchReducer } from 'search';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pew pew pew 🔫

import { notificationsReducer } from 'notifications';
import { entities, pagination } from 'api/reducers';

Expand All @@ -14,7 +13,6 @@ export const rootReducer = combineReducers({
repository: repositoryReducer,
organization: organizationReducer,
issue: issueReducer,
search: searchReducer,
notifications: notificationsReducer,
entities,
pagination,
Expand Down
3 changes: 2 additions & 1 deletion src/api/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const ACTIVITY_GET_EVENTS_RECEIVED = createPaginationActionSet(
export const ACTIVITY_GET_STARRED_REPOS_FOR_USER = createPaginationActionSet(
'ACTIVITY_GET_STARRED_REPOS_FOR_USER'
);
export const SEARCH_REPOS = createPaginationActionSet('SEARCH_REPOS');
export const SEARCH_USERS = createPaginationActionSet('SEARCH_USERS');
export const ORGS_GET_MEMBERS = createPaginationActionSet('ORGS_GET_MEMBERS');

export const ORGS_GET_BY_ID = createActionSet('ORGS_GET_BY_ID');
20 changes: 19 additions & 1 deletion src/api/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,24 @@ export class Client {
}));
},
};

search = {
repos: async (q, params) => {
return this.call(`search/repositories?q=${q}`, params).then(response => ({
response,
nextPageUrl: this.getNextPageUrl(response),
schema: Schemas.REPO_ARRAY,
normalizrKey: 'items',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the first use of normalizrKey.

The API response for this call looks like the following:

{
  total_count: 645354,
  incomplete_results: false,
  items: [
    { /* first repo object */},
    { /* second repo object */},
    ...
  ]
}

We only care for what's inside items, the array of repositories.

normalizrKey tells the dispatch proxy to only treat that property of the JSON, instead of all the JSON.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NICE ⭐️

}));
},
users: async (q, params) => {
return this.call(`search/users?q=${q}`, params).then(response => ({
response,
nextPageUrl: this.getNextPageUrl(response),
schema: Schemas.USER_ARRAY,
normalizrKey: 'items',
}));
},
};
orgs = {
getById: async (orgId, params) => {
return this.call(`orgs/${orgId}`, params).then(response => ({
Expand All @@ -162,6 +179,7 @@ export class Client {
response,
nextPageUrl: this.getNextPageUrl(response),
schema: Schemas.USER_ARRAY,

}));
},
};
Expand Down
2 changes: 2 additions & 0 deletions src/api/reducers/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,7 @@ export const pagination = combineReducers({
ACTIVITY_GET_STARRED_REPOS_FOR_USER: paginate(
Actions.ACTIVITY_GET_STARRED_REPOS_FOR_USER
),
SEARCH_REPOS: paginate(Actions.SEARCH_REPOS),
SEARCH_USERS: paginate(Actions.SEARCH_USERS),
ORGS_GET_MEMBERS: paginate(Actions.ORGS_GET_MEMBERS),
});
4 changes: 0 additions & 4 deletions src/search/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
export * from './search.action';
export * from './search.reducer';
export * from './search.type';

export * from './screens';
Loading