diff --git a/src/App.css b/src/App.css index 8a55933..85fce7f 100644 --- a/src/App.css +++ b/src/App.css @@ -34,7 +34,31 @@ body: { padding: 10px; } +.App-search { + padding: 10px 15px; + display: flex; + flex-direction: column; + justify-content: center; +} + +.App-search > h3 > div:first-child { + margin: 5px 15px 0 0; +} + @keyframes App-logo-spin { - from { transform: rotate(0deg); } - to { transform: rotate(360deg); } + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} + +@media screen and (min-width: 500px) { + .App-search { + flex-direction: row; + } + .App-search-input { + width: 300px; + } } diff --git a/src/App.js b/src/App.js index a4742e6..a161663 100644 --- a/src/App.js +++ b/src/App.js @@ -1,13 +1,17 @@ -import React, { useState, useEffect } from 'react'; -import { usePage } from './hooks/use-page'; -import { Container, Card, Header, Icon, Pagination } from 'semantic-ui-react'; -import 'semantic-ui-css/semantic.min.css'; -import parse from 'parse-link-header'; -import './App.css'; -import { PetCard } from './components/PetCard'; -import fetchPets from './services/pets'; -import { cacheRequest } from './_sessionStorage'; -import { PETS } from './constants'; +import React, { useState, useEffect } from "react"; +import { + Container, + Card, + Header, + Icon, + Pagination, + Input +} from "semantic-ui-react"; +import "semantic-ui-css/semantic.min.css"; +import parse from "parse-link-header"; +import "./App.css"; +import { PetCard } from "./components/PetCard"; +import fetchPets from "./services/pets"; function App() { const LIMIT = 9; @@ -15,6 +19,7 @@ function App() { const [pets, setPets] = useState([]); const [page, setPage] = usePage(); const [totalPages, setTotalPages] = useState(1); + const [searchText, setSearchText] = useState(""); useEffect(() => { async function fetchData() { @@ -33,6 +38,18 @@ function App() { setPage(data.activePage); }; + const findPetBy = (pet, _search) => + pet.toLowerCase().includes(_search.toLowerCase()); + + const searchPets = + pets && + pets.filter( + pet => + findPetBy(pet.name, searchText) || + findPetBy(pet.owner, searchText) || + findPetBy(pet.type, searchText) + ); + return (