Skip to content

Commit

Permalink
feat(SearchResult): Add query info on dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoliron committed Aug 16, 2023
1 parent 1abe69b commit 9654107
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/components/SearchResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TransitionProps } from "@mui/material/transitions";
import { Close } from "@mui/icons-material";

type Props = {
currentSearch: string;
searchResults: FoodList;
ifSearched: boolean;
closeModal: () => void;
Expand All @@ -28,7 +29,7 @@ const Transition = forwardRef(function Transition(
});

function SearchResult(props: Props) {
const { searchResults, ifSearched, closeModal } = props;
const { currentSearch, searchResults, ifSearched, closeModal } = props;

const foodItems = searchResults.map((item, key) => {
return <Item key={key} {...item} />;
Expand All @@ -44,9 +45,10 @@ function SearchResult(props: Props) {
aria-describedby="the results of your search are shown here"
TransitionComponent={Transition}
>
<Stack direction="row">
<Stack direction="row" alignItems="center" p={2}>
<Typography variant="h5" component="div">Search: {currentSearch}</Typography>
<IconButton
sx={{ m: 2, ml: "auto" }}
sx={{ml: "auto" }}
edge="start"
color="inherit"
onClick={closeModal}
Expand Down
3 changes: 3 additions & 0 deletions src/routes/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ const theme = createTheme({

function Layout({ food }: { food: FoodList }) {
//search bar code
const [currentSearch, setCurrentSearch] = useState('');
const [ifSearched, setIfSearched] = useState(false);
const [searchResults, setSearchResults] = useState([] as FoodList);
const closeModal = () => setIfSearched(false);

const onSearch = (query: string, food: FoodList) => {
if (query != "") {
setCurrentSearch(query)
setIfSearched(true);
setSearchResults(food);
}
Expand Down Expand Up @@ -87,6 +89,7 @@ function Layout({ food }: { food: FoodList }) {
/>
{ifSearched ? (
<SearchResult
currentSearch={currentSearch}
searchResults={searchResults}
ifSearched={ifSearched}
closeModal={closeModal}
Expand Down

0 comments on commit 9654107

Please sign in to comment.