diff --git a/features/home/actions/Hero/addHeroBannerMediaToSaved.ts b/features/home/actions/Hero/addHeroBannerMediaToSaved.ts new file mode 100644 index 0000000..8a1c3a1 --- /dev/null +++ b/features/home/actions/Hero/addHeroBannerMediaToSaved.ts @@ -0,0 +1,18 @@ +"use server"; + +import { backendFetch } from "@/shared/helpers/backendFetch"; + +export const addHeroBannerMediaToSaved = async (mediaId: string) => { + try { + return await backendFetch("collections/sys", { + method: "POST", + body: JSON.stringify({ + name: "Saved", + itemId: mediaId, + }), + }); + } catch (error) { + console.error("Error adding media to saved list:", error); + return { success: false, message: "Failed to add media to saved list." }; + } +}; diff --git a/features/home/actions/getRecommenationAnime.ts b/features/home/actions/Hero/getRecommenationAnime.ts similarity index 100% rename from features/home/actions/getRecommenationAnime.ts rename to features/home/actions/Hero/getRecommenationAnime.ts diff --git a/features/home/actions/Hero/removeHeroBannerMediaFromSaved.ts b/features/home/actions/Hero/removeHeroBannerMediaFromSaved.ts new file mode 100644 index 0000000..0c2c873 --- /dev/null +++ b/features/home/actions/Hero/removeHeroBannerMediaFromSaved.ts @@ -0,0 +1,21 @@ +"use server"; + +import { backendFetch } from "@/shared/helpers/backendFetch"; + +export const removeHeroBannerMediaFromSaved = async (mediaId: string) => { + try { + return await backendFetch("collections/sys", { + method: "DELETE", + body: JSON.stringify({ + name: "Saved", + itemId: mediaId, + }), + }); + } catch (error) { + console.error("Error removing media from saved list:", error); + return { + success: false, + message: "Failed to remove media from saved list.", + }; + } +}; diff --git a/features/home/sections/Hero/components/AddToList.tsx b/features/home/sections/Hero/components/AddToList.tsx new file mode 100644 index 0000000..255a7c4 --- /dev/null +++ b/features/home/sections/Hero/components/AddToList.tsx @@ -0,0 +1,65 @@ +"use client"; +import { addHeroBannerMediaToSaved } from "@/features/home/actions/Hero/addHeroBannerMediaToSaved"; +import { removeHeroBannerMediaFromSaved } from "@/features/home/actions/Hero/removeHeroBannerMediaFromSaved"; +import { useAuth } from "@/shared/contexts/AuthContext"; +import { BackendResponse } from "@/shared/helpers/backendFetch"; +import { Button } from "@/shared/libs/shadcn/ui/button"; +import { Icon } from "@iconify/react"; +import React from "react"; + +const AddToList = ({ + mediaId, + isInCollection, +}: { + mediaId: string; + isInCollection: boolean; +}) => { + const { session } = useAuth(); + const [isSaved, setIsSaved] = React.useState(isInCollection); + + const handleAddToList = async () => { + setIsSaved(!isSaved); + const result = (await addHeroBannerMediaToSaved(mediaId).catch( + (_) => void _, + )) as BackendResponse; + if (!result || !result.success) { + setIsSaved((prev) => !prev); + } + }; + const handleRemoveFromList = async () => { + setIsSaved(!isSaved); + const result = (await removeHeroBannerMediaFromSaved(mediaId).catch( + (_) => void _, + )) as BackendResponse; + if (!result || !result.success) { + setIsSaved((prev) => !prev); + } + }; + + return ( +
+ {session?.user && + (isSaved ? ( + + ) : ( + + ))} +
+ ); +}; + +export default AddToList; diff --git a/features/home/sections/Hero/components/Swiper.tsx b/features/home/sections/Hero/components/Swiper.tsx index 82239d8..40322f5 100644 --- a/features/home/sections/Hero/components/Swiper.tsx +++ b/features/home/sections/Hero/components/Swiper.tsx @@ -2,114 +2,94 @@ import "swiper/css"; import { Badge } from "@/shared/libs/shadcn/ui/badge"; import { Button } from "@/shared/libs/shadcn/ui/button"; -import { useRouter } from "next/navigation"; import { Autoplay, Navigation, Pagination } from "swiper/modules"; import { Swiper, SwiperSlide } from "swiper/react"; +import { Icon } from "@iconify/react"; +import Link from "next/link"; +import AddToList from "./AddToList"; export interface HeroSwiperProps { data: { id: string; - isClickable: boolean; title: string; - tags: string[]; - description: string; - buttonContent: string; - buttonLink: string; + slug: string; imageUrl: string; - startDate: string; - endDate: string; + synopsis: string; + genres: { + slug: string; + name: string; + }[]; + isInCollection: boolean; }[]; } const HeroSwiper = (props: HeroSwiperProps) => { - const router = useRouter(); return (
console.log("slide change")} - onSwiper={(swiper) => console.log(swiper)} className="h-full" autoplay={{ delay: 5000, disableOnInteraction: false }} modules={[Autoplay, Pagination, Navigation]} > - {props.data.map((slide) => - slide.imageUrl ? ( - // Slide with image background - - {slide.title} - {slide.title && slide.description && ( -
-

- {slide.title} -

-
- {slide.tags.map((tag) => ( - - {tag} - - ))} -
-

- {slide.description} -

- {slide.isClickable && ( - - )} -
- )} -
- ) : ( - // Fallback for slides without image - ( + + {slide.title} +

{slide.title}

-
- {slide.tags.map((tag) => ( - - {tag} - +
+ {slide.genres.map((genre) => ( + + + {genre.name} + + ))}
-

- {slide.description} +

+ {slide.synopsis}

- {slide.isClickable && ( - - )} - - ), - )} + + + +
+
+
+ ))}
); diff --git a/features/home/sections/Recommendation/components/Card.tsx b/features/home/sections/Recommendation/components/Card.tsx index d4662c4..d93df64 100644 --- a/features/home/sections/Recommendation/components/Card.tsx +++ b/features/home/sections/Recommendation/components/Card.tsx @@ -1,4 +1,4 @@ -import { RecommendationAnime } from "@/features/home/actions/getRecommenationAnime"; +import { RecommendationAnime } from "@/features/home/actions/Hero/getRecommenationAnime"; import { Icon } from "@iconify/react"; const AnimeRecommendationCard = ({ data }: { data: RecommendationAnime }) => { diff --git a/features/home/sections/Recommendation/main.client.tsx b/features/home/sections/Recommendation/main.client.tsx index 3fae04f..d4871d3 100644 --- a/features/home/sections/Recommendation/main.client.tsx +++ b/features/home/sections/Recommendation/main.client.tsx @@ -1,7 +1,7 @@ "use client"; import { useRef } from "react"; -import { RecommendationAnime } from "../../actions/getRecommenationAnime"; +import { RecommendationAnime } from "../../actions/Hero/getRecommenationAnime"; import AnimeRecommendationCard from "./components/Card"; import ScrollingButton from "./components/ScrollingButton"; diff --git a/features/home/sections/Recommendation/main.tsx b/features/home/sections/Recommendation/main.tsx index e4d3229..83d7850 100644 --- a/features/home/sections/Recommendation/main.tsx +++ b/features/home/sections/Recommendation/main.tsx @@ -1,4 +1,4 @@ -import { getRecommendationAnimeAction } from "../../actions/getRecommenationAnime"; +import { getRecommendationAnimeAction } from "../../actions/Hero/getRecommenationAnime"; import RecommendationClient from "./main.client"; const RecommendationMain = async () => {