Skip to content

Commit

Permalink
Add Search Query
Browse files Browse the repository at this point in the history
  • Loading branch information
kaamil-ahamadh committed Nov 18, 2022
1 parent f6ef4ec commit fec0982
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { useEffect, useState } from "react";
import React, { useEffect, useState } from "react";
import "./App.css";
import { Route, Routes } from "react-router-dom";

import GlobalContext from "./context/GlobalContext";
import { HomeScreen, VideoDetailsScreen, ErrorScreen } from "../src/screens";
import { Header, Footer, Loading } from "../src/components";
import { Header, Footer, Loading, SearchQuery } from "../src/components";

function App() {
/* States */

//Loading
const [loading, setLoading] = useState(true);

// Global States
const [userSearch, setUserSearch] = useState("");

useEffect(() => {
setTimeout(() => {
setLoading(false);
Expand All @@ -24,7 +27,10 @@ function App() {

return (
<div className="app-container">
<Header />
<div>
<Header />
<SearchQuery userSearch={userSearch} setUserSearch={setUserSearch} />
</div>
<div className="screen-container">
<GlobalContext.Provider value={{}}>
<Routes>
Expand Down
35 changes: 35 additions & 0 deletions src/components/SearchQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from "react";
import { FaSearch } from "react-icons/fa";

const SearchQuery = ({ userSearch, setUserSearch }) => {
const handleChange = (event) => {
setUserSearch(event.target.value);
};

const handleClickEnter = (event) => {
if (event.key === "Enter") {
console.log(userSearch);
}
};

return (
<div>
<div className="input-container">
<div className="input">
<input
type="text"
placeholder="Search Videos..."
value={userSearch}
onChange={(e) => handleChange(e)}
className="input-search"
onKeyDown={(e) => handleClickEnter(e)}
/>

<FaSearch color="aqua" />
</div>
</div>
</div>
);
};

export default SearchQuery;
1 change: 1 addition & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as Header } from "./Header";
export { default as Footer } from "./Footer";
export { default as Loading } from "./Loading";
export { default as SearchQuery } from "./SearchQuery";

0 comments on commit fec0982

Please sign in to comment.