Commit 743fd99f by Madhankumar

code changes

parent 81415f4e
...@@ -2,14 +2,15 @@ ...@@ -2,14 +2,15 @@
import Header from "@components/base/header"; import Header from "@components/base/header";
import { useThemeContext } from "app/theme-context"; import { useThemeContext } from "app/theme-context";
import { useRouter } from "next/navigation"; import { useRouter, useSearchParams } from "next/navigation";
export default function PageHeader({ searchParams }) { export default function PageHeader() {
const { theme, toggleTheme } = useThemeContext(); const { theme, toggleTheme } = useThemeContext();
const router = useRouter(); const router = useRouter();
const currentPage = 1; // Assuming currentPage is constant for now const currentPage = 1; // Assuming currentPage is constant for now
const search = searchParams.search; const searchParams = useSearchParams();
const search = searchParams.get("search") || "";
const handleSearch = (value) => { const handleSearch = (value) => {
const query = value const query = value
...@@ -29,7 +30,7 @@ export default function PageHeader({ searchParams }) { ...@@ -29,7 +30,7 @@ export default function PageHeader({ searchParams }) {
onThemeChange={toggleTheme} onThemeChange={toggleTheme}
onSearch={handleSearch} onSearch={handleSearch}
onClear={handleClear} onClear={handleClear}
value={search} searchValue={search}
/> />
); );
} }
...@@ -10,7 +10,7 @@ function Header({ ...@@ -10,7 +10,7 @@ function Header({
onSearch, onSearch,
onClear, onClear,
onThemeChange, onThemeChange,
value, searchValue,
}) { }) {
const handleTheme = () => { const handleTheme = () => {
onThemeChange(currentTheme); onThemeChange(currentTheme);
...@@ -35,7 +35,7 @@ function Header({ ...@@ -35,7 +35,7 @@ function Header({
<Search <Search
onSearch={handleSearch} onSearch={handleSearch}
onClear={handleClear} onClear={handleClear}
value={value} defaultValue={searchValue}
/> />
</div> </div>
......
...@@ -3,12 +3,13 @@ import PropTypes from "prop-types"; ...@@ -3,12 +3,13 @@ import PropTypes from "prop-types";
import Icons from "@components/base/icons"; import Icons from "@components/base/icons";
import styles from "./styles.module.css"; import styles from "./styles.module.css";
const Search = ({ onSearch, onClear, value }) => { const Search = ({ onSearch, onClear, defaultValue }) => {
const [inputValue, setInputValue] = useState(value); const [inputValue, setInputValue] = useState(defaultValue);
useEffect(() => { useEffect(() => {
setInputValue(value); setInputValue(defaultValue);
}, [value]); }, [defaultValue]);
const handleCustomClear = () => { const handleCustomClear = () => {
onClear(""); onClear("");
setInputValue(""); // Reset the input value setInputValue(""); // Reset the input value
...@@ -32,8 +33,7 @@ const Search = ({ onSearch, onClear, value }) => { ...@@ -32,8 +33,7 @@ const Search = ({ onSearch, onClear, value }) => {
<input <input
className={styles["search-input"]} className={styles["search-input"]}
type="text" type="text"
autoFocus={true} value={inputValue || ""} // Ensure value is not null
value={inputValue}
onChange={handleChange} onChange={handleChange}
onKeyUp={handleKeyPress} onKeyUp={handleKeyPress}
placeholder="Discover news, articles and more" placeholder="Discover news, articles and more"
......
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