Commit 542188c7 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

fix search on navbar

parent 74b7f294
...@@ -76,11 +76,16 @@ function Navbar(props) { ...@@ -76,11 +76,16 @@ function Navbar(props) {
const isMenuOpen = Boolean(anchorEl); const isMenuOpen = Boolean(anchorEl);
const isMobileMenuOpen = Boolean(mobileMoreAnchorEl); const isMobileMenuOpen = Boolean(mobileMoreAnchorEl);
function onUpdateSearch(value) {
router.push({
pathname: location.pathname,
query: { ...router.query, q: value },
});
}
React.useEffect(() => { React.useEffect(() => {
if (search.length) setSearch(router.query?.q ?? "");
router.push({ pathname: router.pathname, query: { q: search } }); }, [router]);
else router.push({ pathname: router.pathname });
}, [search]);
const handleMobileMenuClose = () => { const handleMobileMenuClose = () => {
setMobileMoreAnchorEl(null); setMobileMoreAnchorEl(null);
...@@ -174,7 +179,7 @@ function Navbar(props) { ...@@ -174,7 +179,7 @@ function Navbar(props) {
color="inherit" color="inherit"
> >
<Badge color="error"> <Badge color="error">
<ShoppingBag /> <ShoppingBag />
</Badge> </Badge>
</IconButton> </IconButton>
), ),
...@@ -295,7 +300,9 @@ function Navbar(props) { ...@@ -295,7 +300,9 @@ function Navbar(props) {
<StyledInputBase <StyledInputBase
placeholder="Search…" placeholder="Search…"
inputProps={{ "aria-label": "search" }} inputProps={{ "aria-label": "search" }}
onChange={(e) => setSearch(e.target.value)} onChange={(e) => {
return onUpdateSearch(e.target.value);
}}
/> />
</Search> </Search>
<Box sx={{ flexGrow: 1 }} /> <Box sx={{ flexGrow: 1 }} />
......
import React from 'react'
export default function OrderDetailPage() {
return (
<div>OrderDetailPage</div>
)
}
\ No newline at end of file
...@@ -61,7 +61,7 @@ export default function App({ Component, pageProps }) { ...@@ -61,7 +61,7 @@ export default function App({ Component, pageProps }) {
value={{ value: cart, set: setCart, fetch: fetchCart }} value={{ value: cart, set: setCart, fetch: fetchCart }}
> >
<WishlistContext.Provider value={{ value: wishlist, set: setWishlist }}> <WishlistContext.Provider value={{ value: wishlist, set: setWishlist }}>
{pathname.split("/")[1] === "admin" ? ( {String(pathname).split("/")[1] === "admin" ? (
<> <>
{user.rank ? ( {user.rank ? (
<AdminLayout> <AdminLayout>
......
...@@ -9,21 +9,17 @@ import { ...@@ -9,21 +9,17 @@ import {
TableRow, TableRow,
} from "@mui/material"; } from "@mui/material";
import React, { useContext, useEffect, useState } from "react"; import React, { useContext, useEffect, useState } from "react";
import { CartContext, UserContext, WishlistContext } from "./_app"; import { CartContext, UserContext } from "./_app";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import axios from "axios"; import axios from "axios";
import PopupAlert from "@/components/PopupAlert"; import PopupAlert from "@/components/PopupAlert";
import Head from "next/head"; import Head from "next/head";
import { ShoppingBag } from "@mui/icons-material";
import ConfirmOrder from "@/components/order/ConfirmOrder";
export default function Order() { export default function Order() {
const user = useContext(UserContext); const user = useContext(UserContext);
const cart = useContext(CartContext); const cart = useContext(CartContext);
const [products, setProducts] = useState([]); const [products, setProducts] = useState([]);
const [message, setMessage] = useState({ error: false, message: "" }); const [message, setMessage] = useState({ error: false, message: "" });
const [orderState, setOrderState] = useState(false);
const router = useRouter();
const [orderList, setOrderList] = useState([]); const [orderList, setOrderList] = useState([]);
const [CartProduct, setCartProduct] = useState([]); const [CartProduct, setCartProduct] = useState([]);
......
import { useRouter } from "next/router";
import React from "react";
export default function OrderDetail() {
const router = useRouter();
console.log(router.query);
return <div>OrderDetail</div>;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment