From 00292692e0253e537b4c82109263c6d28c5d638a Mon Sep 17 00:00:00 2001 From: Frangel Rodriguez Date: Fri, 12 Jun 2020 20:18:03 -0400 Subject: [PATCH] #2 Calling Api Show Listing Jobs --- src/screens/Listing/index.js | 137 ++++++++++++++++++++++++++++------- src/utils/api.js | 10 +-- 2 files changed, 111 insertions(+), 36 deletions(-) diff --git a/src/screens/Listing/index.js b/src/screens/Listing/index.js index 595bcf2..0bfaed8 100644 --- a/src/screens/Listing/index.js +++ b/src/screens/Listing/index.js @@ -1,7 +1,11 @@ -import React from 'react'; +import React, { Component } from 'react'; import { Container } from '../../components/Container'; import { JobCard } from '../../components/JobCard'; import { ResultsTitle, SearchResult } from './styles'; +import { RefreshControl } from 'react-native'; + +import { API_SUBSCRIPTION_KEY } from 'react-native-dotenv'; +import API from './../../utils/api'; export const results = [ { @@ -149,35 +153,112 @@ export const results = [ HowToApply: '

Enviar fille detallando trabajos de integraciones con carta de referencia  a:  c.alonso@turinter.com

\r\n\r\n

 

\r\n\r\n\r\n\r\n\r\n\r\n

', }, - { - Link: '1330', - CompanyName: 'Wepsys SRL', - Title: 'Full Stack Developer', - JobType: 'Tiempo Completo', - Location: 'Santo Domingo, RD', - PublishedDate: '2019-12-04T19:49:21.597', - IsRemote: false, - ViewCount: 65, - Likes: 0, - CompanyLogoUrl: null, - Description: '

- FRONTEND DEVELOPER

- BACKEND DEVELOPER

', - HowToApply: - '

Enviar curriculum actualizado al correo rrhh@wepsys.com.do

', - }, ]; -const ListingScreen = () => { - return ( - - - {results.length || 0} empleos disponibles - {results.map(job => { - return ; - })} - - - ); -}; +class ListingScreen extends Component { + constructor(props) { + super(props); + + this.state = { + data: [], + isLoading: true, + pageNo: 1, + loadingMore: false, + isFetching: false, + }; + } + + componentDidMount() { + this.loadInitData(); + } + + loadInitData = () => { + const { pageNo } = this.state; + + return fetch(`${API}jobs?page=${pageNo}&pageSize=10`, { + method: 'GET', + headers: { 'Ocp-Apim-Subscription-Key': API_SUBSCRIPTION_KEY }, + }) + .then(response => response.json()) + .then(response => { + console.log(response); + this.setState((prevState, nextProps) => ({ + data: + pageNo === 1 + ? response.Jobs + : this.state.data.concat(response.Jobs), + loading: false, + })); + + console.log('consulta Ejecutada exitosamente'); + }) + .catch(error => { + console.error(error); + }) + .finally(() => { + console.log('consulta Finalizada exitosamente'); + }); + }; + + loadNextData = () => { + this.setState( + (prevState, nextProps) => ({ + pageNo: prevState.pageNo + 1, + loadingMore: true, + }), + () => { + this.loadInitData(); + }, + ); + }; + + resetData = () => { + fetch(`${API}jobs?page=1&pageSize=10`, { + method: 'GET', + headers: { 'Ocp-Apim-Subscription-Key': API_SUBSCRIPTION_KEY }, + }) + .then(response => response.json()) + .then(response => { + // console.log(response) + this.setState({ data: response.Jobs }); + }) + .catch(error => { + console.error(error); + }), + () => { + this.loadInitData(); + }; + + this.setState({ isFetching: false }, () => { + this.state.pageNo = 1; + }); + }; + + render() { + const { data, isLoading, loadingMore, isFetching } = this.state; + return ( + + this.resetData()} + /> + }> + + {data.length ? data.length : 0} empleos disponibles + + {/*{results.length || 0} empleos disponibles*/} + {data.map(job => { + return ; + })} + + + ); + } +} ListingScreen.navigationOptions = screenProps => ({ title: screenProps.navigation.getParam('query'), diff --git a/src/utils/api.js b/src/utils/api.js index 2e5914d..a82d678 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -1,9 +1,3 @@ -import axios from 'axios'; +const API_BASE_URL = 'https://emplea-apm.azure-api.net/v1/api/'; -const API_BASE_URL = 'https://emplea-apm.azure-api.net/v1/api'; - -const API = axios.create({ - baseUrl: API_BASE_URL, -}); - -export default API; +export default API_BASE_URL;