diff --git a/apps/expo/package.json b/apps/expo/package.json index c763762..8742f70 100644 --- a/apps/expo/package.json +++ b/apps/expo/package.json @@ -19,7 +19,7 @@ }, "dependencies": { "@expo/metro-config": "^0.17.3", - "@movie-web/tmdb": "*", + "@movie-web/tmdb": "*", "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", "expo": "~50.0.5", diff --git a/apps/expo/src/app/(tabs)/search/Searchbar.tsx b/apps/expo/src/app/(tabs)/search/Searchbar.tsx index 20229a0..5de78f4 100644 --- a/apps/expo/src/app/(tabs)/search/Searchbar.tsx +++ b/apps/expo/src/app/(tabs)/search/Searchbar.tsx @@ -5,7 +5,11 @@ import { FontAwesome5 } from "@expo/vector-icons"; import Colors from "@movie-web/tailwind-config/colors"; -export default function Searchbar({ onSearchChange }: { onSearchChange: (text: string) => void }) { +export default function Searchbar({ + onSearchChange, +}: { + onSearchChange: (text: string) => void; +}) { const [keyword, setKeyword] = useState(""); const inputRef = useRef(null); @@ -34,7 +38,7 @@ export default function Searchbar({ onSearchChange }: { onSearchChange: (text: s ([]); + const [searchResults, setSearchResults] = useState< + { title: string; posterUrl: string; year: number; type: "movie" | "tv" }[] + >([]); -const handleSearchChange = async (query: string) => { - if (query.length > 0) { - const results = await fetchSearchResults(query); - setSearchResults(results); - } else { - setSearchResults([]); - } -}; + const handleSearchChange = async (query: string) => { + if (query.length > 0) { + const results = await fetchSearchResults(query); + setSearchResults(results); + } else { + setSearchResults([]); + } + }; return ( @@ -42,30 +45,43 @@ const handleSearchChange = async (query: string) => { ); } -async function fetchSearchResults(query: string): Promise<{ title: string; posterUrl: string; year: number; type: "movie" | "tv"; }[]> { - console.log('Fetching results for:', query); - const results = await searchTitle(query); - - return results.map((result) => { - switch (result.media_type) { - case 'movie': - return { - title: result.title, - posterUrl: getMediaPoster(result.poster_path), - year: new Date(result.release_date).getFullYear(), - type: result.media_type as "movie", - }; - case 'tv': - return { - title: result.name, - posterUrl: getMediaPoster(result.poster_path), - year: new Date(result.first_air_date).getFullYear(), - type: result.media_type as "tv", - }; - default: - return undefined; - } - }).filter((item): item is { title: string; posterUrl: string; year: number; type: "movie" | "tv"; } => item !== undefined); - } - - \ No newline at end of file +async function fetchSearchResults( + query: string, +): Promise< + { title: string; posterUrl: string; year: number; type: "movie" | "tv" }[] +> { + console.log("Fetching results for:", query); + const results = await searchTitle(query); + + return results + .map((result) => { + switch (result.media_type) { + case "movie": + return { + title: result.title, + posterUrl: getMediaPoster(result.poster_path), + year: new Date(result.release_date).getFullYear(), + type: result.media_type as "movie", + }; + case "tv": + return { + title: result.name, + posterUrl: getMediaPoster(result.poster_path), + year: new Date(result.first_air_date).getFullYear(), + type: result.media_type as "tv", + }; + default: + return undefined; + } + }) + .filter( + ( + item, + ): item is { + title: string; + posterUrl: string; + year: number; + type: "movie" | "tv"; + } => item !== undefined, + ); +} diff --git a/apps/expo/src/app/components/item/item.tsx b/apps/expo/src/app/components/item/item.tsx index f251cc2..5710d01 100644 --- a/apps/expo/src/app/components/item/item.tsx +++ b/apps/expo/src/app/components/item/item.tsx @@ -1,7 +1,12 @@ import { Image, View } from "react-native"; + import { Text } from "~/components/ui/Text"; -export default function Item({ data }: { data: { title: string, type: string, year: number, posterUrl: string } }) { +export default function Item({ + data, +}: { + data: { title: string; type: string; year: number; posterUrl: string }; +}) { const { title, type, year, posterUrl } = data; return (