feat(i18n): enhance SearchBar to support language context in search queries
- Update SearchBar component to utilize LanguageContext for current language management. - Modify search request to include language and translation request parameters, improving internationalization support. - Ensure state management reflects changes in language context for more accurate search functionality.
This commit is contained in:
@@ -12,12 +12,14 @@ import SearchIcon from "@mui/icons-material/Search";
|
||||
import KeyboardReturnIcon from "@mui/icons-material/KeyboardReturn";
|
||||
import { useNavigate, useLocation } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { LanguageContext } from "../../i18n/withTranslation.js";
|
||||
|
||||
const SearchBar = () => {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const searchParams = new URLSearchParams(location.search);
|
||||
const { t } = useTranslation();
|
||||
const { t, i18n } = useTranslation();
|
||||
const languageContext = React.useContext(LanguageContext);
|
||||
|
||||
// State management
|
||||
const [searchQuery, setSearchQuery] = React.useState(
|
||||
@@ -64,11 +66,15 @@ const SearchBar = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentLanguage = languageContext?.currentLanguage || i18n?.language || 'de';
|
||||
|
||||
window.socketManager.emit(
|
||||
"getSearchProducts",
|
||||
{
|
||||
query: query.trim(),
|
||||
limit: 8,
|
||||
language: currentLanguage,
|
||||
requestTranslation: currentLanguage === 'de' ? false : true,
|
||||
},
|
||||
(response) => {
|
||||
if (response && response.products) {
|
||||
@@ -85,7 +91,7 @@ const SearchBar = () => {
|
||||
}
|
||||
);
|
||||
},
|
||||
[]
|
||||
[languageContext, i18n]
|
||||
);
|
||||
|
||||
const handleSearchChange = (e) => {
|
||||
|
||||
Reference in New Issue
Block a user