-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search by entire search term input. Case insensitive.
- Loading branch information
1 parent
2537a23
commit 1637c7f
Showing
9 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Form from "react-bootstrap/Form"; | ||
|
||
interface Props { | ||
searchTerm: string; | ||
update: (s: string) => void; | ||
} | ||
|
||
export const SearchTermInput = (props: Props) => ( | ||
<Form> | ||
<Form.Control | ||
type="text" | ||
placeholder="Type to search" | ||
value={props.searchTerm} | ||
onChange={e => props.update(e.target.value)} | ||
/> | ||
</Form> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { connect } from "react-redux"; | ||
import { savedMealStateSelector } from "../../app/selectors"; | ||
import { AppDispatch, RootState } from "../../app/store"; | ||
import { SearchTermInput } from "../../components/saved-meal/SearchTermInput"; | ||
import { updateSearchTerm } from "./savedMealStateSlice"; | ||
|
||
const mapStateToProps = (state: RootState) => ({ | ||
searchTerm: savedMealStateSelector(state).searchTerm, | ||
}) | ||
|
||
const mapDispatchToProps = (dispatch: AppDispatch) => ({ | ||
update: (newTerm: string) => dispatch(updateSearchTerm(newTerm)), | ||
}) | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(SearchTermInput); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; | ||
import { addSavedMeal } from "../day-page/mealStatesSlice"; | ||
import { hide } from "../day-page/showSavedMealsSlice"; | ||
|
||
interface SavedMealState { | ||
searchTerm: string; | ||
} | ||
|
||
const savedMealStateSlice = createSlice({ | ||
name: "searchTerm", | ||
initialState: { searchTerm: "" } as SavedMealState, | ||
reducers: { | ||
updateSearchTerm(state, action: PayloadAction<string>) { | ||
state.searchTerm = action.payload; | ||
}, | ||
}, | ||
extraReducers: (builder) => { | ||
builder.addCase(addSavedMeal, (state) => { | ||
state.searchTerm = ""; | ||
}).addCase(hide, (state) => { | ||
state.searchTerm = ""; | ||
}); | ||
} | ||
}); | ||
|
||
export const { updateSearchTerm } = savedMealStateSlice.actions; | ||
export default savedMealStateSlice.reducer; |