From 634d7baa4ea878dc519ff3dbaf92a28e2ad953f9 Mon Sep 17 00:00:00 2001 From: Soham Saha <83546205+Sypher0Dronzer@users.noreply.github.com> Date: Sat, 8 Jun 2024 22:04:34 +0530 Subject: [PATCH 1/2] AnimeFinder has been added --- App.js | 8 +- src/screens/AnimeFinder/AnimeFinder.js | 152 +++++++++++++++++++++++++ src/screens/Home/home.js | 9 ++ 3 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 src/screens/AnimeFinder/AnimeFinder.js diff --git a/App.js b/App.js index f8eda9ce..21ada3e9 100644 --- a/App.js +++ b/App.js @@ -28,6 +28,7 @@ import QRCodeGenerator from "./src/screens/QRGenerator/QRGenerator"; import RecipeFinder from "./src/screens/RecipeFinder/RecipeFinder"; import TicTacToe from "./src/screens/TicTacToe/TicTacToe"; import Icons from "./src/screens/TicTacToe/components/Icons"; +import AnimeFinder from "./src/screens/AnimeFinder/AnimeFinder"; export default function App() { @@ -72,7 +73,7 @@ export default function App() { options={{ headerShown: true, animation: "slide_from_right" }} /> - + ); diff --git a/src/screens/AnimeFinder/AnimeFinder.js b/src/screens/AnimeFinder/AnimeFinder.js new file mode 100644 index 00000000..4e2bcb42 --- /dev/null +++ b/src/screens/AnimeFinder/AnimeFinder.js @@ -0,0 +1,152 @@ +import React, { useState } from 'react'; +import { View, Text, TextInput, Button, StyleSheet, ScrollView, Image } from 'react-native'; + +const AnimeFinder = () => { + const [searchInput, setSearchInput] = useState(''); + const [animeResults, setAnimeResults] = useState([]); + const [noResultsMessage, setNoResultsMessage] = useState(''); + + const searchAnime = async () => { + const query = ` + query ($title: String) { + Page { + media (search: $title, type: ANIME) { + id + title { + romaji + english + native + } + description + averageScore + coverImage { + large + medium + } + } + } + } + `; + + try { + const response = await fetch('https://graphql.anilist.co', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + query, + variables: { title: searchInput }, + }), + }); + + const responseData = await response.json(); + const animeList = responseData.data.Page.media; + + if (animeList.length === 0) { + setNoResultsMessage('No anime found with this name'); + } else { + setNoResultsMessage(''); + } + + setAnimeResults(animeList); + } catch (error) { + console.error('Error:', error); + setNoResultsMessage('An error occurred while fetching data.'); + } + }; + + return ( + + Anime Search + +