Files
nutriscan/hooks/use-search-logic.ts
Evandro Fonseca Junior f98c648311 feat(footer, header, landing): enhance UI components and improve navigation
- Updated Footer component with new links and dynamic year display.
- Refactored Header component to improve mobile navigation and theme toggling.
- Enhanced DonationSection and Features components with improved layout and animations.
- Updated HowItWorks and Impact sections for better user engagement and clarity.
- Improved product page layout and error handling in API interactions.
- General UI refinements across various components for a cohesive user experience.
2026-01-12 19:55:50 -03:00

25 lines
756 B
TypeScript

"use client";
import { useState, useEffect } from "react";
import { detectSearchType, isValidBarcode } from "@/lib/openFoodFactsApi";
// Definimos o tipo de união para garantir segurança de índice
export type SearchType = "auto" | "barcode" | "name";
export function useSearchLogic(query: string) {
const [searchType, setSearchType] = useState<SearchType>("auto");
const [loading, setLoading] = useState(false);
useEffect(() => {
if (query.trim()) {
const detected = detectSearchType(query) as SearchType;
setSearchType(detected);
} else {
setSearchType("auto");
}
}, [query]);
const isValid = searchType === "barcode" ? isValidBarcode(query) : true;
return { searchType, isValid, loading, setLoading };
}