Compare commits
No commits in common. "e0d423f80636fa36109cec750ae768042f734b22" and "439f7d219e72417c966d96b753d2573d2ee9853d" have entirely different histories.
e0d423f806
...
439f7d219e
@ -7,9 +7,10 @@ import { isApiError } from "../../types/api/error";
|
|||||||
import type { Recipe } from "../../types/recipe";
|
import type { Recipe } from "../../types/recipe";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { FilterContext } from "../../context/FilterContext";
|
import { FilterContext } from "../../context/FilterContext";
|
||||||
import ROUTE_CONSTANTS from "../../types/routes";
|
|
||||||
|
|
||||||
interface RecipeSearchBarProps {
|
interface RecipeSearchBarProps {
|
||||||
|
// filters: SearchFilters;
|
||||||
|
// setFilters: React.Dispatch<React.SetStateAction<SearchFilters>>;
|
||||||
redirect: boolean;
|
redirect: boolean;
|
||||||
searchOnLoad: boolean;
|
searchOnLoad: boolean;
|
||||||
favorites: boolean;
|
favorites: boolean;
|
||||||
@ -29,7 +30,7 @@ export default function RecipeSearchBar({ redirect, searchOnLoad, favorites, set
|
|||||||
// SERVER FUNCTIONS
|
// SERVER FUNCTIONS
|
||||||
const fetchSearchResults = async () => {
|
const fetchSearchResults = async () => {
|
||||||
if (redirect) {
|
if (redirect) {
|
||||||
await navigate(ROUTE_CONSTANTS.Search);
|
await navigate("/v2/web/search");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ export default function RecipeSearchBar({ redirect, searchOnLoad, favorites, set
|
|||||||
if (setLoading) setLoading(true);
|
if (setLoading) setLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await SearchRecipes({ ...filters, Favorites: favorites });
|
const result = await SearchRecipes(filters);
|
||||||
if (isApiError(result)) {
|
if (isApiError(result)) {
|
||||||
console.error(result.message);
|
console.error(result.message);
|
||||||
return;
|
return;
|
||||||
@ -75,6 +76,14 @@ export default function RecipeSearchBar({ redirect, searchOnLoad, favorites, set
|
|||||||
void fetchSearchResults();
|
void fetchSearchResults();
|
||||||
}, [searchOnLoad]);
|
}, [searchOnLoad]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setFilters({
|
||||||
|
...filters,
|
||||||
|
Favorites: favorites
|
||||||
|
});
|
||||||
|
}, [favorites]);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className="w-full px-4 my-8" onSubmit={(e) => void searchHandler(e)}>
|
<form className="w-full px-4 my-8" onSubmit={(e) => void searchHandler(e)}>
|
||||||
<div className="flex w-full gap-x-2">
|
<div className="flex w-full gap-x-2">
|
||||||
|
|||||||
@ -88,12 +88,7 @@ export default function Home() {
|
|||||||
<div className="w-full md:w-3/4">
|
<div className="w-full md:w-3/4">
|
||||||
<RecipeSearchBar redirect={true} favorites={false} searchOnLoad={false} setRecipes={null} />
|
<RecipeSearchBar redirect={true} favorites={false} searchOnLoad={false} setRecipes={null} />
|
||||||
</div>
|
</div>
|
||||||
<p className="leading-relaxed text-gray-800">
|
<div className="hidden" id="result-list"></div>
|
||||||
Not sure what you want? {" "}
|
|
||||||
<a href={ROUTE_CONSTANTS.Search} className="text-blue-500 underline hover:text-blue-700 duration-300">
|
|
||||||
View all recipes here
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
{/* Highlight Section */}
|
{/* Highlight Section */}
|
||||||
|
|||||||
4
web/src/types/filters.ts
Normal file
4
web/src/types/filters.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export interface SearchFilters {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
0
web/src/types/index.ts
Normal file
0
web/src/types/index.ts
Normal file
@ -8,7 +8,6 @@ const ROUTE_CONSTANTS: {
|
|||||||
ShoppingList: string;
|
ShoppingList: string;
|
||||||
Login: string;
|
Login: string;
|
||||||
History: string;
|
History: string;
|
||||||
Search: string;
|
|
||||||
Recipe: (id: number) => string;
|
Recipe: (id: number) => string;
|
||||||
} = {
|
} = {
|
||||||
Home: `${VERSION_FLAG}/web/home`,
|
Home: `${VERSION_FLAG}/web/home`,
|
||||||
@ -18,7 +17,6 @@ const ROUTE_CONSTANTS: {
|
|||||||
ShoppingList: `${VERSION_FLAG}/web/list`,
|
ShoppingList: `${VERSION_FLAG}/web/list`,
|
||||||
Login: `${VERSION_FLAG}/web/login`,
|
Login: `${VERSION_FLAG}/web/login`,
|
||||||
History: `${VERSION_FLAG}/web/history`,
|
History: `${VERSION_FLAG}/web/history`,
|
||||||
Search: `${VERSION_FLAG}/web/search`,
|
|
||||||
Recipe: (id: number) => `${VERSION_FLAG}/web/recipe/${id}`,
|
Recipe: (id: number) => `${VERSION_FLAG}/web/recipe/${id}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user