diff --git a/App.tsx b/App.tsx index d1dbd61..621350d 100644 --- a/App.tsx +++ b/App.tsx @@ -1,20 +1,29 @@ -import { GluestackUIProvider, Text, Box, Center, Image } from "@gluestack-ui/themed" +import { GluestackUIProvider, Text, Box, Center, Image, VStack, ScrollView } from "@gluestack-ui/themed" import { config } from "@gluestack-ui/config" import Swiper from "react-native-swiper"; import { Dimensions } from "react-native"; //폰의 넓이만큼 import { QueryClient, QueryClientProvider, useQuery } from "@tanstack/react-query"; import MySwiper from "./components/MySwiper"; +import React from "react"; +import CardList from "./CardList"; const queryClient = new QueryClient(); export default function App() { return ( - -
- -
-
-
+ + + +
+ +
+ + + +
+
+ + ); } diff --git a/CardList.tsx b/CardList.tsx new file mode 100644 index 0000000..88e0829 --- /dev/null +++ b/CardList.tsx @@ -0,0 +1,31 @@ +import { useQuery } from "@tanstack/react-query"; +import { VStack } from "@gluestack-ui/themed" +import MediumCard from "./components/Card/MediumCard"; +import { Webtoon } from "./types"; +import React from "react"; + +interface WebtoonResponse{ + webtoons: Webtoon[]; +} + +const fetchWebtoons = async () => { + const res = await fetch('https://korea-webtoon-api.herokuapp.com'); //await 확장자: 함수를 기다려서 api를 호출해서 완료될때까지 기다리겠다. + return res.json(); +}; + +export default function CardList() { + const { data } = useQuery({ + queryKey: ['korea-webtoon-api.herokuapp.com'], + queryFn: fetchWebtoons, + }); + + return ( + + {data + ? data.webtoons.map((webtoon) => + + ) + : []} + + ); +} \ No newline at end of file diff --git a/components/Card/LargeView.tsx b/components/Card/LargeView.tsx new file mode 100644 index 0000000..ad0ce5e --- /dev/null +++ b/components/Card/LargeView.tsx @@ -0,0 +1,48 @@ +import { GluestackUIProvider, Text, Box, Center, Image, VStack } from "@gluestack-ui/themed" +import { config } from "@gluestack-ui/config" +import Swiper from "react-native-swiper"; +import { Dimensions } from "react-native"; //폰의 넓이 +import { Webtoon } from "../../types"; +import React from "react"; + +interface LargeViewProp { + webtoon: Webtoon; +} + +export default function LargeView({ webtoon }: LargeViewProp) { + + return ( + + + + + + webtoon + + + + {webtoon.title} + {webtoon.author} + + + + + ); +} diff --git a/components/Card/MediumCard.tsx b/components/Card/MediumCard.tsx new file mode 100644 index 0000000..ce8edbc --- /dev/null +++ b/components/Card/MediumCard.tsx @@ -0,0 +1,44 @@ +import { GluestackUIProvider, Text, Box, Center, Image, VStack, HStack, Icon, StarIcon } from "@gluestack-ui/themed" +import { config } from "@gluestack-ui/config" +import Swiper from "react-native-swiper"; +import { Dimensions } from "react-native"; //폰의 넓이 +import { Webtoon } from "../../types"; +import React from "react"; + + +interface MediumCardProp { + webtoon: Webtoon; +} + +export default function MediumCard({ webtoon }: MediumCardProp) { + + return ( + + webtoon + + + + {webtoon.title} + + + {webtoon.author} + + + + + {webtoon.fanCount} + + + + + + + ); +} diff --git a/components/MySwiper.tsx b/components/MySwiper.tsx index 8713c41..c37e197 100644 --- a/components/MySwiper.tsx +++ b/components/MySwiper.tsx @@ -1,8 +1,12 @@ -import { GluestackUIProvider, Text, Box, Center, Image } from "@gluestack-ui/themed" -import { config } from "@gluestack-ui/config" import Swiper from "react-native-swiper"; -import { Dimensions } from "react-native"; //폰의 넓이 import { useQuery } from "@tanstack/react-query"; +import { Webtoon } from "../types"; +import React from "react"; +import LargeView from "./Card/LargeView"; + +interface WebtoonResponse{ + webtoons: Webtoon[]; +} const fetchWebtoons = async () => { const res = await fetch('https://korea-webtoon-api.herokuapp.com'); //await 확장자: 함수를 기다려서 api를 호출해서 완료될때까지 기다리겠다. @@ -10,38 +14,18 @@ const fetchWebtoons = async () => { }; export default function MySwiper() { - const { data } = useQuery({ + + const { data } = useQuery({ queryKey: ['korea-webtoon-api.herokuapp.com'], queryFn: fetchWebtoons, }); return ( - + {data - ? data.webtoons.map((item: any) => ( -
- webtoon - - {item.title} - - - - {item.author} - - - -
- )) + ? data.webtoons.map((webtoon) => + + ) : []}
); diff --git a/types.ts b/types.ts new file mode 100644 index 0000000..26d71f3 --- /dev/null +++ b/types.ts @@ -0,0 +1,7 @@ +export interface Webtoon{ + webtoonId: number; + title: string; + author: string; + img: string; + fanCount : number; +} \ No newline at end of file