Fixed home screen loading issue

This commit is contained in:
Jake Howard 2016-02-14 19:19:11 +00:00
parent d189461648
commit 489803665a
5 changed files with 18 additions and 14 deletions

View file

@ -9,8 +9,8 @@ export function checkToken(possibleToken) {
});
}
export function getProjects() {
const CIToken = token.get();
export async function getProjects() {
const CIToken = await token.get();
const url = endpoints.get('ALL_PROJECTS');
return request(url, 'GET', {}, CIToken);
}

View file

@ -1,7 +1,9 @@
const TOKEN = '';
import token from './token';
export default function request(url, method, data = {}, token = TOKEN ) {
const fullURL = url.query({ 'circle-token': token }).toString();
export default function request(url, method, data = {}, CIToken) {
CIToken = CIToken || token.get();
const fullURL = url.query({ 'circle-token': CIToken }).toString();
console.log('Sending request to', fullURL);
let fetchParams = {
method,
headers: {

View file

@ -2,10 +2,12 @@ import { AsyncStorage } from 'react-native';
const STORAGE_KEY = 'CIRCLE_TOKEN';
export async function get() {
async function get() {
return await AsyncStorage.getItem(STORAGE_KEY);
}
export async function set(token) {
async function set(token) {
return await AsyncStorage.setItem(STORAGE_KEY, token);
}
export default { get, set };

View file

@ -50,7 +50,7 @@ export default class Home extends React.Component {
}
render() {
const data = JSON.stringify(this.state.projects);
const data = JSON.stringify(this.state.projects) || 'No Data';
return (
<View style={styles.container}>
<ScrollView keyboardShouldPersistTaps={false} contentContainerStyle={styles.container}>

View file

@ -3,7 +3,7 @@ import GlobalStyles from '../../settings/styles';
import TokenHelp from '../login/token-help';
import RouteMaster from './RouteMaster';
import { checkToken } from '../../api/CircleCI';
import { set } from '../../api/token';
import token from '../../api/token';
import loaderHandler from 'react-native-busy-indicator/LoaderHandler';
import BusyIndicator from 'react-native-busy-indicator';
@ -34,7 +34,7 @@ const styles = StyleSheet.create({
},
input: {
fontSize: 13,
marginHorizontal: 15,
marginHorizontal: 25,
},
loginButton: {
flex: 0.92,
@ -80,7 +80,7 @@ export default class Login extends React.Component {
constructor() {
super();
this.state = {
token: '',
token: '07e1082a9298c939b4f1c2c5821225012d8fd34e',
showTokenHelp: false
};
this.validate = this.validate.bind(this);
@ -91,8 +91,8 @@ export default class Login extends React.Component {
this.proceed = this.proceed.bind(this);
}
textChanged(token) {
this.setState({ token });
textChanged(CIToken) {
this.setState({ token: CIToken });
}
proceed() {
@ -116,7 +116,7 @@ export default class Login extends React.Component {
}
checkToken(this.state.token).then(function (isValid) {
if (isValid) {
set(this.state.token).then(this.proceed);
token.set(this.state.token).then(this.proceed);
} else {
this.invalidToken();
this.setState({