Skip to content

Commit

Permalink
add layout
Browse files Browse the repository at this point in the history
  • Loading branch information
mominrazashahid committed Aug 17, 2024
1 parent 4509078 commit 9d725a6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
25 changes: 25 additions & 0 deletions src/layouts/headerWithNavbar/headerHomeLayout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { useState } from 'react';
import { Navbar } from 'react-bootstrap';
import Home from '../../pages/home/Home';
import Header from '../../components/header/Header';

function HeaderHomeLayout ({ children }) {
//This State will keep Track of what is entered in the searchField
const [searchField, setSearchField] = useState('');

//updating the State from Header Component which further updating itself from HeaderSearchBar.js
let inputHandler = (event) => {
setSearchField(event.target.value);
};

return (
<div>
<Header inputHandler={inputHandler} />
<Navbar />
<Home text={searchField} />
<main>{children}</main>
</div>
);
};

export default HeaderHomeLayout;
21 changes: 12 additions & 9 deletions src/layouts/headerWithNavbar/headerWithNavbar.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Header } from 'antd/lib/layout/layout';
import React from 'react';
import React, { useState } from 'react';
import { Navbar } from 'react-bootstrap';
import Header from '../../components/header/Header';

const HeaderWithNavbar = ({ children }) => (
<div>
<Header />
<Navbar />
<main>{children}</main>
</div>
);
function HeaderWithNavbar ({ children }) {

return (
<div>
<Header />
<Navbar />
<main>{children}</main>
</div>
);
};

export default HeaderWithNavbar;
17 changes: 3 additions & 14 deletions src/routes/routes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect } from 'react';

import { BrowserRouter, Routes, Route } from 'react-router-dom';

Expand All @@ -12,15 +12,14 @@ import Payment from '../components/payment/Payment';
import Login from '../pages/login/Login';
import Signup from '../pages/signup/Signup';
import Checkout from '../components/checkOut/Checkout';
import Navbar from '../components/navbar/Navbar';
import BookToys from '../Categories/BooksToys/BookToys';
import HeaderWithNavbar from '../layouts/headerWithNavbar/headerWithNavbar';
import FashionBeauty from '../Categories/FashionBeauty/FashionBeauty';
import Electronics from '../Categories/Electronics/Electronics';
import { Home } from '@material-ui/icons';
import { useStateValue } from '../context/StateProvider';
import { auth } from '../firebase';
import { Footer } from 'antd/lib/layout/layout';
import HeaderHomeLayout from '../layouts/headerWithNavbar/headerHomeLayout';

const stripePromise = loadStripe(
'pk_test_51JdCsbSDjgMnau9ncKpDOaddNIWtdhVTTV92V4ShkTzLec033vWcRQjqEUByb1s4D6vmPmH6oMK0bkBJyBlRsStp00wQV1pNuX'
Expand All @@ -30,13 +29,7 @@ function AppRoutes() {

//to keep a check who is signed in/making a listner
const [{}, dispatch] = useStateValue();
//This State will keep Track of what is entered in the searchField
const [searchField, setSearchField] = useState('');

//updating the State from Header Component which further updating itself from HeaderSearchBar.js
let inputHandler = (event) => {
setSearchField(event.target.value);
};
useEffect(() => {
//will run only once when the app component loads
auth.onAuthStateChanged((authUser) => {
Expand Down Expand Up @@ -102,7 +95,6 @@ useEffect(() => {
element={
<>
<HeaderWithNavbar> <BookToys /></HeaderWithNavbar>

</>
}
/>
Expand All @@ -124,10 +116,7 @@ useEffect(() => {
path="/"
element={
<>
<Header inputHandler={inputHandler} />
<Navbar />
<Home text={searchField} />
<AllCategories />
<HeaderHomeLayout> <AllCategories /></HeaderHomeLayout>
</>
}
/>
Expand Down

0 comments on commit 9d725a6

Please sign in to comment.