File tree 4 files changed +43
-21
lines changed
4 files changed +43
-21
lines changed Original file line number Diff line number Diff line change 1
- import React , { Component } from 'react' ;
1
+ import React , { useState } from 'react' ;
2
2
import './App.css' ;
3
+ import { useFetch } from './hooks/useFetch' ;
3
4
5
+ import { SearchBar } from './components/SearchBar/SearchBar.component' ;
4
6
import { JobCardList } from './components/JobCardList/JobCardList.component' ;
5
7
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
+
9
19
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 >
14
35
</ div >
15
- </ div >
16
36
) ;
17
- }
18
37
}
19
38
20
39
export default App ;
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
-
3
2
import { Card } from 'react-bootstrap' ;
4
3
5
4
export const JobCard = ( props ) => {
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
- import { useFetch } from '../../hooks/useFetch' ;
3
-
4
2
import { JobCard } from '../JobCard/JobCard.component' ;
5
3
6
4
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 ;
14
6
15
7
return (
16
8
< div className = 'row' > {
17
9
jobList . map ( job => (
18
- < JobCard jobs = { job } />
10
+ < JobCard key = { job . jobQueryString } jobs = { job } />
19
11
) )
20
12
} </ div >
21
13
) ;
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments