Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SearchBar #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
font-family: Roboto;
}

.center {
display: flex;
justify-content: center;
align-items: center;
height:100vh;
}

.App-header {
background-color: #282c34;
min-height: 100vh;
Expand Down
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { Outlet } from 'react-router-dom';

import Navbar from './components/Navbar';
import theme from './themes/theme';
import SearchBar from './components/SearchBar';

const App = () => {
return (
<ThemeProvider theme={theme}>
<div className="App">
<Navbar />
<SearchBar />
<Outlet/>
</div>
</ThemeProvider>
Expand Down
22 changes: 21 additions & 1 deletion src/components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,30 @@ const navItems = [
{ text: 'About', link: '/about' }
];

const Navbar = () => {


const Navbar = (movies, setSearchResult) => {
// const handleSubmit = (e) => e.preventDefault()
// const handleSearchChange = (e) => {
// if (!e.target.value) return setSearchResult(movies)

// const resultArray = movies.filter(movie =>
// movie.title.includes(e.target.value) || movie.body.includes(e.target.value))
// setSearchResult(resultArray)}
return (
<Box sx={{ display: 'flex' }}>
<AppBar>
{/* <form className='search' onSubmit={handleSubmit}>
<input className='searchInput'
type= "search"
id = "search"
onChange={handleSearchChange}
></input>
<button className='searchButton'
color='black'>
Search
</button>
</form> */}
<Toolbar>
<MovieFilter sx={{ display: 'flex', mr: 1 }} />
<Typography
Expand Down
33 changes: 33 additions & 0 deletions src/components/SearchBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react'
import AppBar from '@mui/material/AppBar';


const SearchBar = (movies, setSearchResult) => {
const handleSubmit = (e) => e.preventDefault()
const handleSearchChange = (e) => {
if (!e.target.value) return setSearchResult(movies)

const resultArray = movies.filter(movie =>
movie.title.includes(e.target.value) || movie.body.includes(e.target.value))

setSearchResult(resultArray)
}
return (
<AppBar>
<form className='search' onSubmit={handleSubmit}>
<input className='searchInput'
type= "search"
id = "search"
onChange={handleSearchChange}>

</input>
<button className='searchButton'
color='black'>
Search
</button>
</form>
</AppBar>
)
}

export default SearchBar
9 changes: 9 additions & 0 deletions src/containers/MovieList.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ const MovieList = () => {
queryParams.set("page", page);
setQueryParams(queryParams);
}
const SearchMovie = ({searchResult}) => {
const result = searchResult.map(movie => <MovieCard key = {movie.title} movie = {movie} />)

const content = result?.lenght ? result : <article><p>NMo MAtching Posts</p></article>

return (
<main>{content}</main>
)
}

return (
<Box sx={{
Expand Down