Skip to content

Commit

Permalink
Remove duplicate anime
Browse files Browse the repository at this point in the history
  • Loading branch information
huy232 committed Feb 17, 2024
1 parent 312e853 commit 92a7a0f
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Components/Content/MangaBrowseENG/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function MangaBrowseENG({ subUrl, title }) {
const mangaPayload = data.data.data
const mangaObject = Object.values(mangaPayload)[0]
setMangaData((prev) => {
return [...new Set([...prev, ...mangaObject.media])]
return [new Set([...prev, ...mangaObject.media])]
})
setPage(mangaObject.pageInfo.currentPage)
setHasNextPage(mangaObject.pageInfo.hasNextPage)
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/AnimeBrowseCategoryENG/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ function AnimeBrowseCategoryENG() {
if (response.data.success) {
if (response.data.data.results.length === 0) {
setAnimeList((prev) => {
return [...new Set([...prev])]
return [new Set([...prev])]
})
setNextPage(false)
} else {
setNextPage(true)
setAnimeList((prev) => {
return [...new Set([...prev, ...response.data.data.results])]
return [new Set([...prev, ...response.data.data.results])]
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/Pages/AnimeBrowseENG/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function AnimeBrowseENG() {
.then((response) => {
if (response.data.success) {
setAllAnime((prev) => {
return [...new Set([...prev, ...response.data.data.results])]
return [new Set([...prev, ...response.data.data.results])]
})
setHasNextPage(response.data.data.hasNextPage)
setLoading(false)
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/AnimeBrowseMoreENG/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function AnimeBrowseMoreENG({ urlString, urlTitle }) {
.then((response) => {
if (response.data.success) {
setAllAnime((prev) => {
return [...new Set([...prev, ...response.data.data.results])]
return [new Set([...prev, ...response.data.data.results])]
})
setHasNextPage(response.data.data.hasNextPage)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/AnimeCollection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function AnimeCollection({ instance }) {
}))
setTranslateGenreAnime(response.data.data.title || "")
setAnimeList((prev) => {
return [...new Set([...prev, ...newList])]
return [new Set([...prev, ...newList])]
})
setLoading(false)
})
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/AnimeGenre/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function AnimeGenre({ instance }) {
}))
setTotalPage(response.data.pagination.totalPage)
setAnimeList((prev) => {
return [...new Set([...prev, ...newList])]
return [new Set([...prev, ...newList])]
})
setLoading(false)
}
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/AnimeList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function AnimeList({ instance }) {
}))
setTotalPage(response.data.pagination.totalPage)
setAnimeList((prev) => {
return [...new Set([...prev, ...newList])]
return [new Set([...prev, ...newList])]
})
setLoading(false)
}
Expand Down
20 changes: 16 additions & 4 deletions src/Pages/AnimeSearchENG/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const PAGE_NUMBER = 1
function AnimeSearchENG() {
const [loading, setLoading] = useState(true)
const [searchResult, setSearchResult] = useState([])
let [page, setPage] = useState(PAGE_NUMBER)
const [hasNextPage, setHasNextPage] = useState(true)
let [page, setPage] = useState(PAGE_NUMBER)
const { query } = useParams()
const prevQuery = useRef({ query, page: 1 })

Expand All @@ -31,20 +31,28 @@ function AnimeSearchENG() {
cancelToken: source.token,
})
.then((response) => {
if (response.data.success) {
if (response.data.success && response.data?.data) {
if (prevQuery.current.query !== query) {
prevQuery.current.query = query
setSearchResult(response.data.data.results)
} else {
setSearchResult((prev) => {
return [...new Set([...prev, ...response.data.data.results])]
return [new Set([...prev, ...response.data.data.results])]
})
}
setHasNextPage(response.data.data.hasNextPage)
setLoading(false)
} else {
if (response.data?.data) {
setSearchResult((prev) => {
return [new Set([...prev, ...response.data.data.results])]
})
}
setLoading(false)
}
})
.catch((thrown) => {
setLoading(false)
if (axios.isCancel(thrown)) return
})
}
Expand All @@ -64,11 +72,15 @@ function AnimeSearchENG() {

return (
<div>
<h1 className="font-black">SEARCH</h1>
<h1 className="font-black font-bebas-neue text-[#d3d9] text-center">
SEARCH
</h1>
{loading ? (
<div className="block w-full mt-[50px] text-center">
<LoadingSpin primaryColor="red" />
</div>
) : searchResult.length === 0 ? (
<p>There are no anime you're are looking for...</p>
) : (
<InfiniteScroll
initialScrollY={0}
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/MangaInfoENG/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function MangaInfoENG() {
language.push(current, next)
}
}
setMangaLanguageOption([...new Set(language)])
setMangaLanguageOption([new Set(language)])
} else {
setMangaLanguageOption([])
}
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/MangaSearchENG/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function MangaSearchENG() {
setSearchResult(response.data.data.results)
} else {
setSearchResult((prev) => {
return [...new Set([...prev, ...response.data.data.results])]
return [new Set([...prev, ...response.data.data.results])]
})
}
setHasNextPage(response.data.data.hasNextPage)
Expand Down

0 comments on commit 92a7a0f

Please sign in to comment.