Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #4

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions app/api/anime-episodes/route.ts

This file was deleted.

4 changes: 2 additions & 2 deletions app/api/anime-infov1/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export async function GET(request: NextRequest) {
const { data } = await AnimeServiceV1.getAnimeInfoV1Gogo(query);
return NextResponse.json(data);
} catch (error) {
console.error("Error searching anime:", error);
console.error("Error to give animev1 info:", error);
return NextResponse.json(
{ error: "Failed to search anime" },
{ error: "Failed to give animev1 info" },
{ status: 500 }
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/api/anime-infov2/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export async function GET(request: NextRequest) {
const { data } = await AnimeServiceV2.getAnimeInfoV2(query);
return NextResponse.json(data);
} catch (error) {
console.error("Error searching anime:", error);
console.error("Failed to give animev2 info", error);
return NextResponse.json(
{ error: "Failed to search anime" },
{ error: "Failed to give animev2 info" },
{ status: 500 }
);
}
Expand Down
24 changes: 15 additions & 9 deletions app/api/anime-search/route.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { NextRequest, NextResponse } from 'next/server'
import { AnimeServiceV2 } from '@/services'
import { NextRequest, NextResponse } from "next/server";
import { AnimeServiceV2 } from "@/services";

export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams
const query = searchParams.get('query')
const searchParams = request.nextUrl.searchParams;
const query = searchParams.get("query");

if (!query) {
return NextResponse.json({ error: 'Query parameter is required' }, { status: 400 })
return NextResponse.json(
{ error: "Query parameter is required" },
{ status: 400 }
);
}

try {
const { data } = await AnimeServiceV2.searchAnimeV2(query)
return NextResponse.json(data)
const { data } = await AnimeServiceV2.searchAnimeV2(query);
return NextResponse.json(data);
} catch (error) {
console.error('Error searching anime:', error)
return NextResponse.json({ error: 'Failed to search anime' }, { status: 500 })
console.error("Error searching animev2:", error);
return NextResponse.json(
{ error: "Failed to search animev2" },
{ status: 500 }
);
}
}
5 changes: 2 additions & 3 deletions app/api/animestream/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ export async function GET(request: NextRequest) {
const { data } = await AnimeServiceV1.getAnimeStreamGogo(query);
return NextResponse.json(data);
} catch (error) {
console.error("Error searching anime:", error);
console.error("Failed to give animev1 stream", error);
return NextResponse.json(
{ error: "Failed to search anime" },
{ error: "Failed to give animev1 stream" },
{ status: 500 }
);
}
}

25 changes: 15 additions & 10 deletions app/api/movie-search/route.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { NextRequest, NextResponse } from 'next/server'
import { MovieService } from '@/services'
import { NextRequest, NextResponse } from "next/server";
import { MovieService } from "@/services";

export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams
const query = searchParams.get('query')
const searchParams = request.nextUrl.searchParams;
const query = searchParams.get("query");

if (!query) {
return NextResponse.json({ error: 'Query parameter is required' }, { status: 400 })
return NextResponse.json(
{ error: "Query parameter is required" },
{ status: 400 }
);
}

try {
const { data } = await MovieService.searchMovie(query)
return NextResponse.json(data)
const { data } = await MovieService.searchMovie(query);
return NextResponse.json(data);
} catch (error) {
console.error('Error searching anime:', error)
return NextResponse.json({ error: 'Failed to search anime' }, { status: 500 })
console.error("Failed to search movie", error);
return NextResponse.json(
{ error: "Failed to search movie" },
{ status: 500 }
);
}
}

2 changes: 1 addition & 1 deletion app/components/card/animecard/AnimeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const AnimeCard = ({ anime }: AnimeCardProps) => {

{isPopularAnime(anime) && (
<SmallInfo
year={String(anime?.seasonYear)}
year={String(anime?.seasonYear || anime.format)}
genre={anime?.genres?.[0]}
rating={String(anime?.averageScore / 10)}
/>
Expand Down
14 changes: 12 additions & 2 deletions app/components/detail/cardbanner/CardBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import { useState, useMemo } from "react";
import { useState, useMemo, useEffect } from "react";
import Image from "next/image";
import { AnimeInfo } from "@/types/anime.type";
import { MovieInfo, TVInfo } from "@/types/movies.type";
Expand All @@ -13,6 +13,14 @@ function CardBanner({ item }: CardBannerProps) {
const pathName = usePathname();
const fallbackCard = "/fallback-card.webp";
const [isImageLoading, setImageLoading] = useState(true);
const [isMobile, setIsMobile] = useState(false);

useEffect(() => {
const handleResize = () => setIsMobile(window.innerWidth < 640); // Tailwind's mobile breakpoint (sm: 640px)
handleResize();
window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
}, []);

const isAnime = useMemo(() => pathName.split("/")[1] === "anime", [pathName]);

Expand Down Expand Up @@ -69,6 +77,8 @@ function CardBanner({ item }: CardBannerProps) {
return [];
}, [item]);

const genreSlice = isMobile ? genres.slice(0, 2) : genres.slice(0, 3);

return (
<div
className={`${
Expand Down Expand Up @@ -99,7 +109,7 @@ function CardBanner({ item }: CardBannerProps) {
{title}
</p>
<div className="flex flex-wrap gap-1 text-xs text-white sm:gap-2 sm:text-base">
{genres.slice(0, 3).map((genre: string, i: number) => (
{genreSlice.map((genre: string, i: number) => (
<div
key={i}
className="flex items-center truncate rounded bg-gray-400 p-1 text-center font-semibold text-black sm:max-w-full"
Expand Down
1 change: 1 addition & 0 deletions app/types/anime.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export type Anime = {
coverImage?: CoverImage;
episodes: number | null;
meanScore?: number;
format?: string;
duration: number;
season: string;
seasonYear?: number;
Expand Down
Loading