chore: run prettier

This commit is contained in:
Adrian Castro
2024-02-04 16:15:21 +01:00
parent e3f74aac09
commit dc6e3f5a7f
4 changed files with 71 additions and 46 deletions

View File

@@ -5,7 +5,11 @@ import { FontAwesome5 } from "@expo/vector-icons";
import Colors from "@movie-web/tailwind-config/colors"; 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 [keyword, setKeyword] = useState("");
const inputRef = useRef<TextInput>(null); const inputRef = useRef<TextInput>(null);

View File

@@ -1,23 +1,26 @@
import React, { useState } from 'react'; import React, { useState } from "react";
import { ScrollView, View } from 'react-native'; import { ScrollView, View } from "react-native";
import Item from '~/components/item/item'; import { getMediaPoster, searchTitle } from "@movie-web/tmdb";
import Item from "~/components/item/item";
import ScreenLayout from "~/components/layout/ScreenLayout";
import { Text } from "~/components/ui/Text"; import { Text } from "~/components/ui/Text";
import ScreenLayout from '~/components/layout/ScreenLayout'; import Searchbar from "./Searchbar";
import Searchbar from './Searchbar';
import { searchTitle, getMediaPoster } from '@movie-web/tmdb';
export default function SearchScreen() { export default function SearchScreen() {
const [searchResults, setSearchResults] = useState<{ title: string; posterUrl: string; year: number; type: "movie" | "tv"; }[]>([]); const [searchResults, setSearchResults] = useState<
{ title: string; posterUrl: string; year: number; type: "movie" | "tv" }[]
>([]);
const handleSearchChange = async (query: string) => { const handleSearchChange = async (query: string) => {
if (query.length > 0) { if (query.length > 0) {
const results = await fetchSearchResults(query); const results = await fetchSearchResults(query);
setSearchResults(results); setSearchResults(results);
} else { } else {
setSearchResults([]); setSearchResults([]);
} }
}; };
return ( return (
<ScrollView> <ScrollView>
@@ -42,20 +45,25 @@ const handleSearchChange = async (query: string) => {
); );
} }
async function fetchSearchResults(query: string): Promise<{ title: string; posterUrl: string; year: number; type: "movie" | "tv"; }[]> { async function fetchSearchResults(
console.log('Fetching results for:', query); query: string,
): Promise<
{ title: string; posterUrl: string; year: number; type: "movie" | "tv" }[]
> {
console.log("Fetching results for:", query);
const results = await searchTitle(query); const results = await searchTitle(query);
return results.map((result) => { return results
.map((result) => {
switch (result.media_type) { switch (result.media_type) {
case 'movie': case "movie":
return { return {
title: result.title, title: result.title,
posterUrl: getMediaPoster(result.poster_path), posterUrl: getMediaPoster(result.poster_path),
year: new Date(result.release_date).getFullYear(), year: new Date(result.release_date).getFullYear(),
type: result.media_type as "movie", type: result.media_type as "movie",
}; };
case 'tv': case "tv":
return { return {
title: result.name, title: result.name,
posterUrl: getMediaPoster(result.poster_path), posterUrl: getMediaPoster(result.poster_path),
@@ -65,7 +73,15 @@ async function fetchSearchResults(query: string): Promise<{ title: string; poste
default: default:
return undefined; return undefined;
} }
}).filter((item): item is { title: string; posterUrl: string; year: number; type: "movie" | "tv"; } => item !== undefined); })
} .filter(
(
item,
): item is {
title: string;
posterUrl: string;
year: number;
type: "movie" | "tv";
} => item !== undefined,
);
}

View File

@@ -1,7 +1,12 @@
import { Image, View } from "react-native"; import { Image, View } from "react-native";
import { Text } from "~/components/ui/Text"; 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; const { title, type, year, posterUrl } = data;
return ( return (