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";
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<TextInput>(null);

View File

@@ -1,14 +1,17 @@
import React, { useState } from 'react';
import { ScrollView, View } from 'react-native';
import React, { useState } from "react";
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 ScreenLayout from '~/components/layout/ScreenLayout';
import Searchbar from './Searchbar';
import { searchTitle, getMediaPoster } from '@movie-web/tmdb';
import Searchbar from "./Searchbar";
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) => {
if (query.length > 0) {
@@ -42,20 +45,25 @@ 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);
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) => {
return results
.map((result) => {
switch (result.media_type) {
case 'movie':
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':
case "tv":
return {
title: result.name,
posterUrl: getMediaPoster(result.poster_path),
@@ -65,7 +73,15 @@ async function fetchSearchResults(query: string): Promise<{ title: string; poste
default:
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 { 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 (