mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 14:43:25 +00:00
chore: run prettier
This commit is contained in:
@@ -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);
|
||||||
|
|
||||||
|
@@ -1,14 +1,17 @@
|
|||||||
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) {
|
||||||
@@ -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,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@@ -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 (
|
||||||
|
Reference in New Issue
Block a user