summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package.json1
-rw-r--r--src/redux/github/actions.js33
-rw-r--r--src/redux/github/reducer.js33
-rw-r--r--src/redux/github/types.js3
-rw-r--r--src/redux/preference/types.js6
-rw-r--r--yarn.lock9
6 files changed, 81 insertions, 4 deletions
diff --git a/package.json b/package.json
index fca0718..98ab0a7 100644
--- a/package.json
+++ b/package.json
@@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
+ "axios": "^0.18.0",
"bootstrap": "^4.1.3",
"react": "^16.4.2",
"react-dom": "^16.4.2",
diff --git a/src/redux/github/actions.js b/src/redux/github/actions.js
new file mode 100644
index 0000000..2db93ce
--- /dev/null
+++ b/src/redux/github/actions.js
@@ -0,0 +1,33 @@
+import axios from 'axios';
+
+import {
+ FETCH_TRENDING_FAILED,
+ FETCH_TRENDING_SUCCESS,
+ PROCESS_FETCH_TRENDING
+} from './types';
+
+const API_URL = 'https://api.github.com/search/repositories';
+
+/**
+ * @param {object} filters
+ * @returns {Function}
+ */
+export const fetchTrending = function (filters) {
+ return dispatch => {
+ dispatch({ type: PROCESS_FETCH_TRENDING });
+
+ axios.get(API_URL, {
+ params: filters
+ }).then(response => {
+ dispatch({
+ type: FETCH_TRENDING_SUCCESS,
+ payload: response.data
+ });
+ }).catch(error => {
+ dispatch({
+ type: FETCH_TRENDING_FAILED,
+ payload: error
+ });
+ });
+ };
+};
diff --git a/src/redux/github/reducer.js b/src/redux/github/reducer.js
new file mode 100644
index 0000000..c752e36
--- /dev/null
+++ b/src/redux/github/reducer.js
@@ -0,0 +1,33 @@
+import { FETCH_TRENDING_FAILED, FETCH_TRENDING_SUCCESS, PROCESS_FETCH_TRENDING } from './types';
+
+export const initialState = {
+ processing: false,
+ error: null,
+ data: [],
+};
+
+export default function reducer(state = initialState, action) {
+ switch (action.type) {
+ case PROCESS_FETCH_TRENDING:
+ return {
+ ...state,
+ processing: true,
+ error: null
+ };
+ case FETCH_TRENDING_SUCCESS:
+ return {
+ ...state,
+ data: action.payload,
+ processing: false,
+ error: null
+ };
+ case FETCH_TRENDING_FAILED:
+ return {
+ ...state,
+ process: false,
+ error: action.payload
+ };
+ default:
+ return state;
+ }
+}
diff --git a/src/redux/github/types.js b/src/redux/github/types.js
new file mode 100644
index 0000000..a345496
--- /dev/null
+++ b/src/redux/github/types.js
@@ -0,0 +1,3 @@
+export const PROCESS_FETCH_TRENDING = 'PROCESS_FETCH_TRENDING';
+export const FETCH_TRENDING_SUCCESS = 'FETCH_TRENDING_SUCCESS';
+export const FETCH_TRENDING_FAILED = 'FETCH_TRENDING_FAILED';
diff --git a/src/redux/preference/types.js b/src/redux/preference/types.js
index ac613c6..84e1f8b 100644
--- a/src/redux/preference/types.js
+++ b/src/redux/preference/types.js
@@ -1,3 +1,3 @@
-export const UPDATE_OPTIONS = 'update_options';
-export const RESET_OPTIONS = 'reset_options';
-export const UPDATE_VIEW_TYPE = 'update_view_type';
+export const UPDATE_OPTIONS = 'UPDATE_OPTIONS';
+export const RESET_OPTIONS = 'RESET_OPTIONS';
+export const UPDATE_VIEW_TYPE = 'UPDATE_VIEW_TYPE';
diff --git a/yarn.lock b/yarn.lock
index acbb495..e017ff1 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -336,6 +336,13 @@ aws4@^1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"
+axios@^0.18.0:
+ version "0.18.0"
+ resolved "https://registry.yarnpkg.com/axios/-/axios-0.18.0.tgz#32d53e4851efdc0a11993b6cd000789d70c05102"
+ dependencies:
+ follow-redirects "^1.3.0"
+ is-buffer "^1.1.5"
+
axobject-query@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-0.1.0.tgz#62f59dbc59c9f9242759ca349960e7a2fe3c36c0"
@@ -2789,7 +2796,7 @@ flatten@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"
-follow-redirects@^1.0.0:
+follow-redirects@^1.0.0, follow-redirects@^1.3.0:
version "1.5.5"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.5.tgz#3c143ca599a2e22e62876687d68b23d55bad788b"
dependencies: