Skip to content

Commit eb3d878

Browse files
committed
✨ Features: added job card and create hooks to fetch apis
1 parent d567b14 commit eb3d878

File tree

6 files changed

+94
-11
lines changed

6 files changed

+94
-11
lines changed

babel.config.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
module.exports = function (api) {
1+
module.exports = function(api) {
22
api.cache(true);
33
return {
44
presets: ["babel-preset-expo"],
55
plugins: [
66
"@babel/plugin-proposal-export-namespace-from",
77
"react-native-reanimated/plugin",
88
require.resolve("expo-router/babel"),
9+
["module:react-native-dotenv", {
10+
"envName": "APP_ENV",
11+
"moduleName": "@env",
12+
"path": ".env",
13+
"blocklist": null,
14+
"allowlist": null,
15+
"safe": false,
16+
"allowUndefined": true,
17+
"verbose": false
18+
}]
919
],
1020
};
1121
};
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
import React from 'react'
2-
import { View, Text } from 'react-native'
2+
import { View, Text, TouchableOpacity, Image } from 'react-native'
33

44
import styles from './popularjobcard.style'
55

6-
const PopularJobCard = () => {
6+
const PopularJobCard = ({ item, selectedJob, handleCardPress }) => {
77
return (
8-
<View>
9-
<Text>PopularJobCard</Text>
10-
</View>
8+
<TouchableOpacity
9+
style={styles.container(selectedJob, item)}
10+
onPress={() => handleCardPress(item)}
11+
>
12+
<TouchableOpacity style={styles.logoContainer(selectedJob, item)}>
13+
<Image source={{ uri: item?.employer_logo }} resizeMode='contain' style={styles.logoImage} />
14+
</TouchableOpacity>
15+
<Text style={styles.companyName} numberOfLines={1}>{item?.employer_name}</Text>
16+
<View style={styles.infoContainer}>
17+
<Text style={styles.jobName(selectedJob, item)} numberOfLines={1}>{item?.job_title}</Text>
18+
<Text style={styles.location}>{item?.job_country}</Text>
19+
</View>
20+
</TouchableOpacity>
1121
)
1222
}
1323

14-
export default PopularJobCard
24+
export default PopularJobCard

components/home/popular/Popularjobs.jsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ import PopularJobCard from '../../common/cards/popular/PopularJobCard'
66
import styles from './popularjobs.style'
77
import { useRouter } from 'expo-router'
88
import { TouchableOpacity } from 'react-native-gesture-handler'
9+
import useFetch from '../../../hook/useFetch'
910

1011
const Popularjobs = () => {
1112
const router = useRouter();
12-
const isLoading = false
13-
const error = false
14-
13+
const { data, isLoading, error, refetch } = useFetch('search', {
14+
query: 'Python developer in Texas, USA',
15+
page: '1',
16+
num_pages: '1'
17+
})
18+
console.log(data)
1519

1620

1721
return (
@@ -26,7 +30,15 @@ const Popularjobs = () => {
2630
) : error ? (
2731
<Text>Something went worng</Text>
2832
) : (
29-
<FlatList />
33+
<FlatList
34+
data={data}
35+
renderItem={({ item }) => (
36+
<PopularJobCard item={item} />
37+
)}
38+
keyExtractor={item => item?.job_id}
39+
contentContainerStyle={{ columnGap: SIZES.medium }}
40+
horizontal
41+
/>
3042
)}
3143
</View>
3244
</View>

hook/useFetch.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { useEffect, useState } from 'react'
2+
import axios from 'axios';
3+
import { RAPID_API_KEY } from '@env';
4+
5+
const rapidApiKey = RAPID_API_KEY
6+
7+
const useFetch = (endpoint, query) => {
8+
const [data, setData] = useState([])
9+
const [isLoading, setIsLoading] = useState(false);
10+
const [error, setError] = useState(null);
11+
12+
const options = {
13+
method: 'GET',
14+
url: `https://jsearch.p.rapidapi.com/${endpoint}`,
15+
headers: {
16+
'content-type': 'application/octet-stream',
17+
'X-RapidAPI-Key': rapidApiKey,
18+
'X-RapidAPI-Host': 'jsearch.p.rapidapi.com'
19+
},
20+
params: { ...query },
21+
};
22+
23+
const fetchData = async () => {
24+
setIsLoading(true)
25+
try {
26+
const response = await axios.request(options)
27+
setData(response.data.data)
28+
setIsLoading(false)
29+
} catch (error) {
30+
setError(error)
31+
alert('There is an error')
32+
} finally {
33+
setIsLoading(false)
34+
}
35+
}
36+
37+
useEffect(() => {
38+
fetchData()
39+
}, []);
40+
41+
const refetch = () => {
42+
setIsLoading(true)
43+
fetchData()
44+
}
45+
46+
return { data, isLoading, error, refetch };
47+
}
48+
49+
export default useFetch;

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
},
88
"dependencies": {
99
"axios": "^1.3.6",
10+
"dotenv": "^16.0.3",
1011
"expo": "^48.0.7",
1112
"expo-constants": "~14.2.1",
1213
"expo-font": "^11.1.1",

0 commit comments

Comments
 (0)