Skip to content

Commit

Permalink
add state to manage limit
Browse files Browse the repository at this point in the history
  • Loading branch information
mariehposa committed Mar 26, 2024
1 parent 0537ca0 commit d9d601e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/redux/actionCreators.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import axios from "axios"
import * as types from "./actionTypes"

// export const increment = (value) => ({
// type: types.INCREMENT_COUNT,
// payload: value
// })
export const getCurrentLimit = (value) => ({
type: types.GET_CURRENT_LIMIT,
payload: value
})

export const getCryptocurrencies = () => {
export const getCryptocurrencies = (currentLimit) => {
return async (dispatch) => {
dispatch({type: types.GET_CRYPTO_START})
try {
const response = await axios.get(`${process.env.REACT_APP_API_URL}/assets`)
const response = await axios.get(`${process.env.REACT_APP_API_URL}/assets`, {params: {limit: currentLimit}})
dispatch({type: types.GET_CRYPTO_SUCCESS, payload: response.data.data})
} catch (error) {
dispatch({type: types.GET_CRYPTO_FAIL, payload: error.message})
Expand Down
3 changes: 2 additions & 1 deletion src/redux/actionTypes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const GET_CRYPTO_START = "GET_CRYPTO_START"
export const GET_CRYPTO_SUCCESS = "GET_CRYPTO_SUCCESS"
export const GET_CRYPTO_FAIL = "GET_CRYPTO_FAIL"
export const GET_CRYPTO_FAIL = "GET_CRYPTO_FAIL"
export const GET_CURRENT_LIMIT = "GET_CURRENT_LIMIT"
3 changes: 3 additions & 0 deletions src/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const initialState = {
loading: false,
assets: [],
error: "",
currentLimit: 20
}

const cryptoReducer = (state = initialState, action) => {
Expand All @@ -17,6 +18,8 @@ const cryptoReducer = (state = initialState, action) => {
return {...state, loading: false, assets: payload}
case types.GET_CRYPTO_FAIL:
return {...state, loading: false, error: payload}
case types.GET_CURRENT_LIMIT:
return {...state, currentLimit: payload}
default:
return state
}
Expand Down

0 comments on commit d9d601e

Please sign in to comment.