-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from mahdi-sharifimehr/RN-Tutorial-33
commit
- Loading branch information
Showing
22 changed files
with
373 additions
and
547 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,16 @@ | ||
export const SET_USER_NAME = 'SET_USER_NAME'; | ||
export const SET_USER_AGE = 'SET_USER_AGE'; | ||
export const INCREASE_AGE = 'INCREASE_AGE'; | ||
export const GET_CITIES = 'GET_CITIES'; | ||
export const SET_TASKS = 'SET_TASKS'; | ||
export const SET_TASK_ID = 'SET_TASK_ID'; | ||
|
||
const API_URL = 'https://mocki.io/v1/aac8b81a-139c-4235-82e6-0dbadf33f2b7'; | ||
|
||
export const getCities = () => { | ||
try { | ||
return async dispatch => { | ||
const result = await fetch(API_URL, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
const json = await result.json(); | ||
if (json) { | ||
dispatch({ | ||
type: GET_CITIES, | ||
payload: json | ||
}); | ||
} else { | ||
console.log('Unable to fetch!'); | ||
} | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} | ||
|
||
export const setName = name => dispatch => { | ||
export const setTasks = tasks => dispatch => { | ||
dispatch({ | ||
type: SET_USER_NAME, | ||
payload: name, | ||
type: SET_TASKS, | ||
payload: tasks, | ||
}); | ||
}; | ||
|
||
export const setAge = age => dispatch => { | ||
export const setTaskID = taskID => dispatch => { | ||
dispatch({ | ||
type: SET_USER_AGE, | ||
payload: age, | ||
type: SET_TASK_ID, | ||
payload: taskID, | ||
}); | ||
}; | ||
|
||
export const increaseAge = age => dispatch => { | ||
dispatch({ | ||
type: INCREASE_AGE, | ||
payload: age, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,19 @@ | ||
import { SET_USER_NAME, SET_USER_AGE, INCREASE_AGE, GET_CITIES } from './actions'; | ||
import { SET_TASKS, SET_TASK_ID } from './actions'; | ||
|
||
const initialState = { | ||
name: '', | ||
age: 0, | ||
cities: [], | ||
tasks: [], | ||
taskID: 1, | ||
} | ||
|
||
function userReducer(state = initialState, action) { | ||
function taskReducer(state = initialState, action) { | ||
switch (action.type) { | ||
case SET_USER_NAME: | ||
return { ...state, name: action.payload }; | ||
case SET_USER_AGE: | ||
return { ...state, age: action.payload }; | ||
case INCREASE_AGE: | ||
return { ...state, age: state.age + 1 }; | ||
case GET_CITIES: | ||
return { ...state, cities: action.payload }; | ||
case SET_TASKS: | ||
return { ...state, tasks: action.payload }; | ||
case SET_TASK_ID: | ||
return { ...state, taskID: action.payload }; | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export default userReducer; | ||
export default taskReducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { createStore, combineReducers, applyMiddleware } from 'redux'; | ||
import thunk from 'redux-thunk'; | ||
import userReducer from './reducers'; | ||
import taskReducer from './reducers'; | ||
|
||
const rootReducer = combineReducers({ userReducer }); | ||
const rootReducer = combineReducers({ taskReducer }); | ||
|
||
export const Store = createStore(rootReducer, applyMiddleware(thunk)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react' | ||
import { StyleSheet, Text, View } from 'react-native' | ||
|
||
export default function Done() { | ||
return ( | ||
<View> | ||
<Text>Done</Text> | ||
</View> | ||
) | ||
} | ||
|
||
const styles = StyleSheet.create({}) |
Oops, something went wrong.