Skip to content

Commit b754e53

Browse files
committed
Implemented SearchBar component
1 parent 4b41bba commit b754e53

File tree

4 files changed

+43
-21
lines changed

4 files changed

+43
-21
lines changed

src/App.js

+29-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
1-
import React, { Component } from 'react';
1+
import React, { useState } from 'react';
22
import './App.css';
3+
import { useFetch } from './hooks/useFetch';
34

5+
import { SearchBar } from './components/SearchBar/SearchBar.component';
46
import { JobCardList } from './components/JobCardList/JobCardList.component';
57

6-
// using class system (no hooks) for practice
7-
class App extends Component {
8-
render() {
8+
const App = () => {
9+
const [search, setSearch] = useState("");
10+
11+
const res = useFetch("http://localhost:8080/beta/jobs", {});
12+
13+
if (res.isLoading || !res.response) {
14+
return <div>Loading...</div>
15+
}
16+
17+
const jobList = res.response;
18+
919
return (
10-
<div className='App'>
11-
<div className='container'>
12-
<h1>Mobius Final Fantasy Job Cards</h1>
13-
<JobCardList/>
20+
<div className='App'>
21+
<div className='container'>
22+
<h1>Mobius Final Fantasy Job Cards</h1>
23+
<SearchBar
24+
placeholder='search jobs'
25+
handleChange={e => setSearch(e.target.value)}
26+
/>
27+
28+
<JobCardList
29+
jobList={
30+
jobList.filter(jobs => jobs.jobName.toLowerCase()
31+
.includes(search.toLocaleLowerCase()))
32+
}
33+
/>
34+
</div>
1435
</div>
15-
</div>
1636
);
17-
}
1837
}
1938

2039
export default App;

src/components/JobCard/JobCard.component.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
32
import { Card } from 'react-bootstrap';
43

54
export const JobCard = (props) => {

src/components/JobCardList/JobCardList.component.jsx

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
import React from 'react';
2-
import { useFetch } from '../../hooks/useFetch';
3-
42
import { JobCard } from '../JobCard/JobCard.component';
53

64
export const JobCardList = (props) => {
7-
const res = useFetch("http://localhost:8080/beta/jobs", {});
8-
9-
if (res.isLoading || !res.response) {
10-
return <div>Loading...</div>
11-
}
12-
13-
const jobList = res.response;
5+
const jobList = props.jobList;
146

157
return (
168
<div className='row'> {
179
jobList.map(job => (
18-
<JobCard jobs={job} />
10+
<JobCard key={job.jobQueryString} jobs={job} />
1911
))
2012
} </div>
2113
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react'
2+
3+
export const SearchBar = ({ placeholder, handleChange }) => {
4+
return (
5+
<input
6+
className='form-control'
7+
type='search'
8+
placeholder={placeholder}
9+
onChange={handleChange}
10+
/>
11+
);
12+
}

0 commit comments

Comments
 (0)