Skip to content

Commit

Permalink
input working along the house filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jeannettearias committed Aug 20, 2024
1 parent b7f90df commit ca13e91
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 35 deletions.
27 changes: 18 additions & 9 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import '../styles/App.scss';
import '../styles/layout/_header.scss';
import Header from './layout/Header';
import Landing from './Landing';
import CharacterDetail from './pages/CharacterDetail';
import Footer from './layout/Footer';
import PropTypes from 'prop-types'

import { useState, useEffect } from 'react';
import { Route, Routes } from 'react-router-dom';
import Landing from './Landing';


function App() {

//global variables
const [characters, setCharacters] = useState([]);
const [houseFilter, setHouseFilter] = useState('All');
const [searchInput, setSearchInput] = useState('');

const imageNotFound = 'https://via.placeholder.com/210x295/ffffff/666666/?text=HarryPotter'

//Code if there is no imagen
Expand All @@ -30,7 +32,7 @@ function App() {
});
}, []);

//events and functions
//events and functions - House filter
const handleChangeHouse = (house) => {
setHouseFilter(house);
let path = 'characters/house/' + house;
Expand All @@ -47,6 +49,12 @@ function App() {

}

//events and functions - Character filter
const handleChangeCharacterFilter = (searchInput) => {
setSearchInput(searchInput);
}

//events and functions - Character Detail
const findCharacter = (id) => {

const characterToShow = characters.find(
Expand All @@ -55,8 +63,10 @@ function App() {
);
return characterToShow;
};
console.log(houseFilter);

const filteredCharacters = characters.filter(character =>
character.name.toLowerCase().includes(searchInput.toLowerCase())
);
//HTML code
return (
<>
Expand All @@ -68,6 +78,10 @@ function App() {
<Routes>
<Route path='/' element={<Landing
characters={characters}
searchInput={searchInput}
filteredCharacters={filteredCharacters}
handleChangeCharacterFilter={handleChangeCharacterFilter}

houseFilter={houseFilter}
handleChangeHouse={handleChangeHouse} />} />
<Route path='/detail/:id'
Expand All @@ -84,9 +98,4 @@ function App() {
)
}

App.propType = {
characters: PropTypes.array.isRequired,
houseFilter: PropTypes.string.isRequired,
handleChangeHouse: PropTypes.func.isRequired,
};
export default App;
23 changes: 14 additions & 9 deletions src/components/Landing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@ import HouseFilter from './filters/HouseFilter';
import CharacterFilter from './filters/CharacterFilter';
import CharacterList from './pages/CharacterList';

function Landing({ characters, houseFilter, handleChangeHouse }) {
function Landing({ filteredCharacters, houseFilter, handleChangeHouse, searchInput, handleChangeCharacterFilter }) {


return (
<>
<section>
<CharacterFilter />
<HouseFilter houseFilter={houseFilter}
<CharacterFilter
searchInput={searchInput}
handleChangeCharacterFilter={handleChangeCharacterFilter} />
<HouseFilter
houseFilter={houseFilter}
handleChangeHouse={handleChangeHouse} />
</section>
<section className='characters'>
<CharacterList characters={characters} />
<CharacterList characters={filteredCharacters}
/>
</section>
</>
)
}
Landing.propTypes = {
characters: PropTypes.array.isRequired,
searchInput: PropTypes.string.isRequired,
houseFilter: PropTypes.string.isRequired,
handleChangeHouse: PropTypes.func.isRequired
}

export default Landing;

filteredCharacters: PropTypes.array.isRequired,
handleChangeHouse: PropTypes.func.isRequired,
handleChangeCharacterFilter: PropTypes.func.isRequired
};

export default Landing;
29 changes: 17 additions & 12 deletions src/components/filters/CharacterFilter.jsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
import '../../styles/layout/_cardsSearch.scss';
import PropTypes from 'prop-types';

function CharacterFilter() {
function CharacterFilter({ searchInput, handleChangeCharacterFilter }) {

//global variables



//code when the page load


//Search events and functions
//handle the input change
const handleInputChange = (ev) => {
const newValue = ev.target.value;

//trigger the search whenever the input changes
handleChangeCharacterFilter(newValue);

};

//HTML code
return (
<>
<section className="search__section">
<form className='form'>
<div>
<label className='form__label'
>Busca por personaje: </label>
<label className='form__label'>Busca por personaje: </label>
<input className='form__input'
type="text" name="search" id="search" />
type="text"
name="search" id="search"
value={searchInput}
onChange={handleInputChange} />
</div>
</form>
</section>
</>

);
}
CharacterFilter.propTypes = {
handleChangeCharacterFilter: PropTypes.func.isRequired,
searchInput: PropTypes.string.isRequired,
};

export default CharacterFilter;
2 changes: 1 addition & 1 deletion src/components/filters/HouseFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function HouseFilter({ houseFilter, handleChangeHouse }) {
);
}
HouseFilter.propType = {
houseFilter: PropTypes.string.isRequired,
houseFilter: PropTypes.func.isRequired,
handleChangeHouse: PropTypes.func.isRequired,
};
export default HouseFilter;
5 changes: 1 addition & 4 deletions src/components/pages/CharacterDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ function CharacterDetail({ findCharacter }) {
}

CharacterDetail.propTypes = {
findCharacter: PropTypes.func,
translateGender: PropTypes.string,
translateSpecie: PropTypes.string,
translateStatus: PropTypes.string,
findCharacter: PropTypes.func.isRequired,
}
export default CharacterDetail;

0 comments on commit ca13e91

Please sign in to comment.