mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 10:03:26 +00:00
chore: run prettier
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@expo/metro-config": "^0.17.3",
|
"@expo/metro-config": "^0.17.3",
|
||||||
"@movie-web/tmdb": "*",
|
"@movie-web/tmdb": "*",
|
||||||
"class-variance-authority": "^0.7.0",
|
"class-variance-authority": "^0.7.0",
|
||||||
"clsx": "^2.1.0",
|
"clsx": "^2.1.0",
|
||||||
"expo": "~50.0.5",
|
"expo": "~50.0.5",
|
||||||
|
@@ -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);
|
||||||
|
|
||||||
@@ -34,7 +38,7 @@ export default function Searchbar({ onSearchChange }: { onSearchChange: (text: s
|
|||||||
</View>
|
</View>
|
||||||
<TextInput
|
<TextInput
|
||||||
value={keyword}
|
value={keyword}
|
||||||
onChangeText={handleChange}
|
onChangeText={handleChange}
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
placeholder="What are you looking for?"
|
placeholder="What are you looking for?"
|
||||||
placeholderTextColor={Colors.secondary[200]}
|
placeholderTextColor={Colors.secondary[200]}
|
||||||
|
@@ -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,30 +45,43 @@ 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,
|
||||||
const results = await searchTitle(query);
|
): Promise<
|
||||||
|
{ title: string; posterUrl: string; year: number; type: "movie" | "tv" }[]
|
||||||
return results.map((result) => {
|
> {
|
||||||
switch (result.media_type) {
|
console.log("Fetching results for:", query);
|
||||||
case 'movie':
|
const results = await searchTitle(query);
|
||||||
return {
|
|
||||||
title: result.title,
|
return results
|
||||||
posterUrl: getMediaPoster(result.poster_path),
|
.map((result) => {
|
||||||
year: new Date(result.release_date).getFullYear(),
|
switch (result.media_type) {
|
||||||
type: result.media_type as "movie",
|
case "movie":
|
||||||
};
|
return {
|
||||||
case 'tv':
|
title: result.title,
|
||||||
return {
|
posterUrl: getMediaPoster(result.poster_path),
|
||||||
title: result.name,
|
year: new Date(result.release_date).getFullYear(),
|
||||||
posterUrl: getMediaPoster(result.poster_path),
|
type: result.media_type as "movie",
|
||||||
year: new Date(result.first_air_date).getFullYear(),
|
};
|
||||||
type: result.media_type as "tv",
|
case "tv":
|
||||||
};
|
return {
|
||||||
default:
|
title: result.name,
|
||||||
return undefined;
|
posterUrl: getMediaPoster(result.poster_path),
|
||||||
}
|
year: new Date(result.first_air_date).getFullYear(),
|
||||||
}).filter((item): item is { title: string; posterUrl: string; year: number; type: "movie" | "tv"; } => item !== undefined);
|
type: result.media_type as "tv",
|
||||||
}
|
};
|
||||||
|
default:
|
||||||
|
return 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