Skip to content

Commit

Permalink
fix: merge various sliders and remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
AlkenD committed Aug 21, 2024
1 parent 87bd0df commit 5445144
Show file tree
Hide file tree
Showing 16 changed files with 386 additions and 450 deletions.
10 changes: 8 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ const App = () => {
path: "/",
element: <HomePage />,
loader: async () => {
const res = await axios.get(APP_API_PATHS.home);
return res.data;
// const res = await axios.get(APP_API_PATHS.home);
return {
carouselSlider: [],
genreSlider: [],
collectionSlider: [],
movieSlider: [],
tvSlider: [],
};
},
},
{
Expand Down
12 changes: 8 additions & 4 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export interface AppConfig {
stream_path: string;
image_path: string;
optimization: boolean;
genreSlider: any;
collectionSlider: any;
movieSlider: any;
tvSlider: any;
}

const APP_CONFIG: AppConfig = {
Expand All @@ -19,10 +23,10 @@ const APP_CONFIG: AppConfig = {
};

const APP_API_PATHS = {
home: APP_CONFIG.server_path + "/" + APP_CONFIG.home_path,
movie: APP_CONFIG.server_path + "/" + APP_CONFIG.movie_path,
tv: APP_CONFIG.server_path + "/" + APP_CONFIG.tv_path,
image: APP_CONFIG.server_path + "/" + APP_CONFIG.image_path + "/original",
home: APP_CONFIG.server_path + "/api/" + APP_CONFIG.home_path,
movie: APP_CONFIG.server_path + "/api/" + APP_CONFIG.movie_path,
tv: APP_CONFIG.server_path + "/api/" + APP_CONFIG.tv_path,
image: APP_CONFIG.server_path + "/api/" + APP_CONFIG.image_path + "/original",
};

export { APP_CONFIG, APP_API_PATHS };
88 changes: 86 additions & 2 deletions src/config/default.config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,95 @@
{
"server_path": "http://localhost:8000",
"server_path": "http://localhost:8803",
"home_path": "home",
"movie_path": "movie",
"tv_path": "tv",
"season_path": "season",
"episode_path": "episode",
"stream_path": "stream",
"image_path": "image",
"optimization": false
"optimization": false,
"genreSlider": {
"title": "Genres",
"placeholderCount": 6,
"breakpoints": {
"300": {
"slidesPerView": 2,
"spaceBetween": 20
},
"920": {
"slidesPerView": 4,
"spaceBetween": 20
},
"1080": {
"slidesPerView": 6,
"spaceBetween": 20
}
}
},
"collectionSlider": {
"title": "Collections",
"placeholderCount": 4,
"breakpoints": {
"320": {
"slidesPerView": 2,
"spaceBetween": 20
},
"580": {
"slidesPerView": 3,
"spaceBetween": 20
},
"920": {
"slidesPerView": 3,
"spaceBetween": 20
},
"1080": {
"slidesPerView": 4,
"spaceBetween": 20
}
}
},
"movieSlider": {
"title": "Movies",
"placeholderCount": 4,
"breakpoints": {
"320": {
"slidesPerView": 2,
"spaceBetween": 20
},
"580": {
"slidesPerView": 3,
"spaceBetween": 20
},
"920": {
"slidesPerView": 3,
"spaceBetween": 20
},
"1080": {
"slidesPerView": 4,
"spaceBetween": 20
}
}
},
"tvSlider": {
"title": "TV Shows",
"placeholderCount": 4,
"breakpoints": {
"320": {
"slidesPerView": 2,
"spaceBetween": 20
},
"580": {
"slidesPerView": 3,
"spaceBetween": 20
},
"920": {
"slidesPerView": 3,
"spaceBetween": 20
},
"1080": {
"slidesPerView": 4,
"spaceBetween": 20
}
}
}
}
71 changes: 71 additions & 0 deletions src/lib/components/logic/ContentSlider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Swiper, SwiperSlide } from "swiper/react";
import { Navigation } from "swiper/modules";
import generateRandomString from "../../utils/generateRandomString";
import React from "react";
import IconButton from "../actions/IconButton";

interface SliderControls {
sliderUid: string;
}

const SliderControls = ({ sliderUid }: SliderControls) => {
return (
<div className="w-fit space-x-2 flex justify-between items-center">
<IconButton
rounded
className={`customSwiperPrevious${sliderUid}`}
icon="ChevronLeftIcon"
variant="secondary"
iconType="outline"
/>
<IconButton
rounded
className={`customSwiperNext${sliderUid}`}
icon="ChevronRightIcon"
variant="secondary"
iconType="outline"
/>
</div>
);
};

const ContentSlider = ({ sliderConfig, data, children }: any) => {
const sliderUid = generateRandomString();

return (
<section className="w-full z-0 relative">
<div className="flex justify-between px-6">
<div className="text-white/60 font-bold text-4xl/normal">
{sliderConfig.title}
</div>
<SliderControls sliderUid={sliderUid} />
</div>
<Swiper
className="!py-2 w-full"
breakpoints={sliderConfig.breakpoints}
modules={[Navigation]}
navigation={{
nextEl: `.customSwiperNext${sliderUid}`,
prevEl: `.customSwiperPrevious${sliderUid}`,
}}
>
{data && data.length > 0
? data.map((item: any, index: number) => (
<SwiperSlide key={item.id || index}>
{React.cloneElement(children as React.ReactElement, { item })}
</SwiperSlide>
))
: Array(sliderConfig.placeholderCount)
.fill(null)
.map((_, index) => index + 1)
.map((_, index) => (
<SwiperSlide key={index}>
{React.cloneElement(children, { placeholder: true })}
</SwiperSlide>
))}
</Swiper>
</section>
);
};

export default ContentSlider;
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import "swiper/css/effect-fade";
import "swiper/css";
import "swiper/css/navigation";

import useAppStore from "../../../stores/app.store";
import Button from "../../actions/Button";
import IconButton from "../../actions/IconButton";
import LazyImage from "../LazyImage";
import useImageColors from "../../../hooks/useImageColors";
import generateRandomString from "../../../utils/generateRandomString";
import { APP_API_PATHS } from "../../../../config/config";
import useAppStore from "../../stores/app.store";
import Button from "../actions/Button";
import IconButton from "../actions/IconButton";
import LazyImage from "./LazyImage";
import useImageColors from "../../hooks/useImageColors";

Check failure on line 14 in src/lib/components/logic/MainSlider.tsx

View workflow job for this annotation

GitHub Actions / publish-tauri (macos-latest, --target aarch64-apple-darwin)

'useImageColors' is declared but its value is never read.

Check failure on line 14 in src/lib/components/logic/MainSlider.tsx

View workflow job for this annotation

GitHub Actions / publish-tauri (macos-latest, --target x86_64-apple-darwin)

'useImageColors' is declared but its value is never read.

Check failure on line 14 in src/lib/components/logic/MainSlider.tsx

View workflow job for this annotation

GitHub Actions / publish-tauri (ubuntu-22.04)

'useImageColors' is declared but its value is never read.

Check failure on line 14 in src/lib/components/logic/MainSlider.tsx

View workflow job for this annotation

GitHub Actions / publish-tauri (windows-latest)

'useImageColors' is declared but its value is never read.
import generateRandomString from "../../utils/generateRandomString";
import { APP_API_PATHS } from "../../../config/config";

const SlideContent = ({ item, index }: any) => {
// const colors = useImageColors(`${APP_API_PATHS.image}${item.backdrop_path}`);
Expand Down Expand Up @@ -88,54 +88,60 @@ const MainSlider = ({ data }: any) => {

return (
<div className="w-full h-fit relative">
<div className="w-full h-fit">
<Swiper
className="aspect-video xl:aspect-[21/9]"
spaceBetween={50}
slidesPerView={1}
modules={[EffectFade, Navigation, Autoplay, Pagination]}
effect={"fade"}
pagination={{ clickable: true }}
fadeEffect={{
crossFade: true,
}}
loop={true}
onSwiper={(swiper) => {
swiperRef.current = swiper;
}}
onSlideChange={(swiper) => {
useAppStore.setState({ homeSliderIndex: swiper.realIndex });
}}
autoplay={{
delay: 5000,
}}
>
{data.map((item: any, index: number) => (
<SwiperSlide className="relative" key={index}>
<SlideContent item={item} index={index} sliderId={sliderId} />
</SwiperSlide>
))}
<div
className="absolute bottom-[20px] right-0 z-50 px-[4.5rem]"
slot="container-end"
{data.length === 0 ? (
<div className="aspect-video xl:aspect-[21/9] flex justify-center items-center text-4xl font-bold bg-white/5">
Content Unavailable
</div>
) : (
<div className="w-full h-fit">
<Swiper
className="aspect-video xl:aspect-[21/9]"
spaceBetween={50}
slidesPerView={1}
modules={[EffectFade, Navigation, Autoplay, Pagination]}
effect={"fade"}
pagination={{ clickable: true }}
fadeEffect={{
crossFade: true,
}}
loop={true}
onSwiper={(swiper) => {
swiperRef.current = swiper;
}}
onSlideChange={(swiper) => {
useAppStore.setState({ homeSliderIndex: swiper.realIndex });
}}
autoplay={{
delay: 5000,
}}
>
<div className="flex space-x-2 items-center justify-center">
<IconButton
rounded
variant="secondary"
icon="ChevronLeftIcon"
onClick={() => swiperRef.current.slidePrev()}
></IconButton>
<IconButton
rounded
variant="secondary"
icon="ChevronRightIcon"
onClick={() => swiperRef.current.slideNext()}
></IconButton>
{data.map((item: any, index: number) => (
<SwiperSlide className="relative" key={index}>
<SlideContent item={item} index={index} sliderId={sliderId} />
</SwiperSlide>
))}
<div
className="absolute bottom-[20px] right-0 z-50 px-[4.5rem]"
slot="container-end"
>
<div className="flex space-x-2 items-center justify-center">
<IconButton
rounded
variant="secondary"
icon="ChevronLeftIcon"
onClick={() => swiperRef.current.slidePrev()}
></IconButton>
<IconButton
rounded
variant="secondary"
icon="ChevronRightIcon"
onClick={() => swiperRef.current.slideNext()}
></IconButton>
</div>
</div>
</div>
</Swiper>
</div>
</Swiper>
</div>
)}
</div>
);
};
Expand Down
Loading

0 comments on commit 5445144

Please sign in to comment.