Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
sonicname committed Sep 28, 2022
1 parent 21e20ca commit 1e2887e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 47 deletions.
19 changes: 0 additions & 19 deletions src/apis/apis.jsx

This file was deleted.

8 changes: 2 additions & 6 deletions src/components/anime/AnimeList.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { memo } from 'react';
import { toast } from 'react-toastify';
import { useNavigate } from 'react-router-dom';
import { useQuery } from '@tanstack/react-query';
import { Swiper, SwiperSlide } from 'swiper/react';

import { getListAnime } from '../../apis/apis';

import AnimeItem from './AnimeItem';
import AnimeItemSkeleton from './AnimeItemSkeleton';
import useGetAnimeList from '../../hooks/useGetAnimeList';

const AnimeList = ({ type }) => {
const navigate = useNavigate();
const { data, isError, isLoading } = useQuery(['list-anime', { type }], () =>
getListAnime(type),
);
const { data, isError, isLoading } = useGetAnimeList(type);

if (isError) {
toast.error('Something went wrong! Please try again!');
Expand Down
19 changes: 0 additions & 19 deletions src/hooks/useBindEnter.jsx

This file was deleted.

10 changes: 10 additions & 0 deletions src/hooks/useGetAnimeList.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useQuery } from '@tanstack/react-query';

const useGetAnimeList = (type) => {
return useQuery(
['list-anime', { type }],
async () => await (await fetch(`https://api.jikan.moe/v4/${type}`)).json(),
);
};

export default useGetAnimeList;
4 changes: 1 addition & 3 deletions src/hooks/useSearchAnime.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { useInfiniteQuery } from '@tanstack/react-query';

import { search } from '../apis/apis';

const useSearchAnime = (type, query, url) => {
return useInfiniteQuery(
['search', { type, query }],
({ pageParam = url }) => search(pageParam),
async ({ pageParam = url }) => (await fetch(pageParam)).json(),
{
getNextPageParam: (lastPage, _) =>
lastPage.pagination.has_next_page
Expand Down

1 comment on commit 1e2887e

@vercel
Copy link

@vercel vercel bot commented on 1e2887e Sep 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.