Fixed home screen loading issue
This commit is contained in:
parent
d189461648
commit
489803665a
5 changed files with 18 additions and 14 deletions
|
@ -9,8 +9,8 @@ export function checkToken(possibleToken) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getProjects() {
|
export async function getProjects() {
|
||||||
const CIToken = token.get();
|
const CIToken = await token.get();
|
||||||
const url = endpoints.get('ALL_PROJECTS');
|
const url = endpoints.get('ALL_PROJECTS');
|
||||||
return request(url, 'GET', {}, CIToken);
|
return request(url, 'GET', {}, CIToken);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
const TOKEN = '';
|
import token from './token';
|
||||||
|
|
||||||
export default function request(url, method, data = {}, token = TOKEN ) {
|
export default function request(url, method, data = {}, CIToken) {
|
||||||
const fullURL = url.query({ 'circle-token': token }).toString();
|
CIToken = CIToken || token.get();
|
||||||
|
const fullURL = url.query({ 'circle-token': CIToken }).toString();
|
||||||
|
console.log('Sending request to', fullURL);
|
||||||
let fetchParams = {
|
let fetchParams = {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
@ -2,10 +2,12 @@ import { AsyncStorage } from 'react-native';
|
||||||
|
|
||||||
const STORAGE_KEY = 'CIRCLE_TOKEN';
|
const STORAGE_KEY = 'CIRCLE_TOKEN';
|
||||||
|
|
||||||
export async function get() {
|
async function get() {
|
||||||
return await AsyncStorage.getItem(STORAGE_KEY);
|
return await AsyncStorage.getItem(STORAGE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function set(token) {
|
async function set(token) {
|
||||||
return await AsyncStorage.setItem(STORAGE_KEY, token);
|
return await AsyncStorage.setItem(STORAGE_KEY, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default { get, set };
|
||||||
|
|
|
@ -50,7 +50,7 @@ export default class Home extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const data = JSON.stringify(this.state.projects);
|
const data = JSON.stringify(this.state.projects) || 'No Data';
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<ScrollView keyboardShouldPersistTaps={false} contentContainerStyle={styles.container}>
|
<ScrollView keyboardShouldPersistTaps={false} contentContainerStyle={styles.container}>
|
||||||
|
|
|
@ -3,7 +3,7 @@ import GlobalStyles from '../../settings/styles';
|
||||||
import TokenHelp from '../login/token-help';
|
import TokenHelp from '../login/token-help';
|
||||||
import RouteMaster from './RouteMaster';
|
import RouteMaster from './RouteMaster';
|
||||||
import { checkToken } from '../../api/CircleCI';
|
import { checkToken } from '../../api/CircleCI';
|
||||||
import { set } from '../../api/token';
|
import token from '../../api/token';
|
||||||
import loaderHandler from 'react-native-busy-indicator/LoaderHandler';
|
import loaderHandler from 'react-native-busy-indicator/LoaderHandler';
|
||||||
import BusyIndicator from 'react-native-busy-indicator';
|
import BusyIndicator from 'react-native-busy-indicator';
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ const styles = StyleSheet.create({
|
||||||
},
|
},
|
||||||
input: {
|
input: {
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
marginHorizontal: 15,
|
marginHorizontal: 25,
|
||||||
},
|
},
|
||||||
loginButton: {
|
loginButton: {
|
||||||
flex: 0.92,
|
flex: 0.92,
|
||||||
|
@ -80,7 +80,7 @@ export default class Login extends React.Component {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.state = {
|
this.state = {
|
||||||
token: '',
|
token: '07e1082a9298c939b4f1c2c5821225012d8fd34e',
|
||||||
showTokenHelp: false
|
showTokenHelp: false
|
||||||
};
|
};
|
||||||
this.validate = this.validate.bind(this);
|
this.validate = this.validate.bind(this);
|
||||||
|
@ -91,8 +91,8 @@ export default class Login extends React.Component {
|
||||||
this.proceed = this.proceed.bind(this);
|
this.proceed = this.proceed.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
textChanged(token) {
|
textChanged(CIToken) {
|
||||||
this.setState({ token });
|
this.setState({ token: CIToken });
|
||||||
}
|
}
|
||||||
|
|
||||||
proceed() {
|
proceed() {
|
||||||
|
@ -116,7 +116,7 @@ export default class Login extends React.Component {
|
||||||
}
|
}
|
||||||
checkToken(this.state.token).then(function (isValid) {
|
checkToken(this.state.token).then(function (isValid) {
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
set(this.state.token).then(this.proceed);
|
token.set(this.state.token).then(this.proceed);
|
||||||
} else {
|
} else {
|
||||||
this.invalidToken();
|
this.invalidToken();
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|
Reference in a new issue