forked from FLiotta/Yasei
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
93 additions
and
36 deletions.
There are no files selected for viewing
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,45 @@ | ||
import axios from 'axios'; | ||
import cogoToast from 'cogo-toast'; | ||
import api from '../api/api'; | ||
|
||
const API = new api(); | ||
|
||
export const | ||
DISCOVER_USERS = 'DISCOVER_USERS', | ||
RESTART_STATE = 'RESTART_STATE', | ||
SET_LOADING = 'SET_LOADING'; | ||
|
||
export const discoverUsers = (username) => { | ||
return (dispatch, getState) => { | ||
const state = getState(); | ||
|
||
dispatch(setLoading(true)); | ||
|
||
API.get('discover/users') | ||
.then(res => { | ||
if (res.data.code == 200) | ||
dispatch({ | ||
type: DISCOVER_USERS, | ||
payload: res.data.response | ||
}) | ||
|
||
dispatch(setLoading(false)); | ||
}) | ||
.catch(e => console.log(e)); | ||
} | ||
} | ||
|
||
export const setLoading = loading => { | ||
return dispatch => dispatch({ | ||
type: SET_LOADING, | ||
payload: { | ||
loading | ||
} | ||
}) | ||
} | ||
|
||
export const restartState = (data) => { | ||
return dispatch => dispatch({ | ||
type: RESTART_STATE | ||
}) | ||
} |
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
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,25 @@ | ||
import {DISCOVER_USERS, SET_LOADING, RESTART_STATE} from '../actions/users'; | ||
import { parseImageUrl } from '../utils/util'; | ||
const defaultState = { | ||
loading: false, | ||
items: [] | ||
} | ||
|
||
export default (state = defaultState, action) => { | ||
switch(action.type) { | ||
case DISCOVER_USERS: | ||
return { | ||
...state, | ||
items: action.payload.map(user => ({...user, profilePic: parseImageUrl(user.profilePic)})) | ||
} | ||
case SET_LOADING: | ||
return { | ||
...state, | ||
loading: action.payload.loading | ||
} | ||
case RESTART_STATE: | ||
return defaultState; | ||
default: | ||
return state; | ||
} | ||
} |
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