mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-20 14:37:43 +01:00
Add most popular shows
This commit is contained in:
parent
4e855021bf
commit
0150078df5
2 changed files with 56 additions and 4 deletions
|
@ -15,6 +15,7 @@ import {
|
||||||
Movie,
|
Movie,
|
||||||
TVShow,
|
TVShow,
|
||||||
categories,
|
categories,
|
||||||
|
tvCategories,
|
||||||
} from "@/utils/discover";
|
} from "@/utils/discover";
|
||||||
|
|
||||||
import { PageTitle } from "./parts/util/PageTitle";
|
import { PageTitle } from "./parts/util/PageTitle";
|
||||||
|
@ -26,7 +27,7 @@ export function Discover() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [showBg] = useState<boolean>(false);
|
const [showBg] = useState<boolean>(false);
|
||||||
const [genres, setGenres] = useState<Genre[]>([]);
|
const [genres, setGenres] = useState<Genre[]>([]);
|
||||||
const [randomMovie, setRandomMovie] = useState<Movie | null>(null); // Add this line
|
const [randomMovie, setRandomMovie] = useState<Movie | null>(null);
|
||||||
const [genreMovies, setGenreMovies] = useState<{
|
const [genreMovies, setGenreMovies] = useState<{
|
||||||
[genreId: number]: Movie[];
|
[genreId: number]: Movie[];
|
||||||
}>({});
|
}>({});
|
||||||
|
@ -36,6 +37,9 @@ export function Discover() {
|
||||||
const bgColor =
|
const bgColor =
|
||||||
currentTheme?.extend?.colors?.background?.accentA ?? "#7831BF";
|
currentTheme?.extend?.colors?.background?.accentA ?? "#7831BF";
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const [categoryShows, setCategoryShows] = useState<{
|
||||||
|
[categoryName: string]: Movie[];
|
||||||
|
}>({});
|
||||||
const [categoryMovies, setCategoryMovies] = useState<{
|
const [categoryMovies, setCategoryMovies] = useState<{
|
||||||
[categoryName: string]: Movie[];
|
[categoryName: string]: Movie[];
|
||||||
}>({});
|
}>({});
|
||||||
|
@ -71,6 +75,28 @@ export function Discover() {
|
||||||
categories.forEach(fetchMoviesForCategory);
|
categories.forEach(fetchMoviesForCategory);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchShowsForCategory = async (category: Category) => {
|
||||||
|
try {
|
||||||
|
const data = await get<any>(category.endpoint, {
|
||||||
|
api_key: conf().TMDB_READ_API_KEY,
|
||||||
|
language: "en-US",
|
||||||
|
});
|
||||||
|
|
||||||
|
setCategoryShows((prevCategoryShows) => ({
|
||||||
|
...prevCategoryShows,
|
||||||
|
[category.name]: data.results,
|
||||||
|
}));
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
`Error fetching movies for category ${category.name}:`,
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
tvCategories.forEach(fetchShowsForCategory);
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Fetch TV show genres
|
// Fetch TV show genres
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchTVGenres = async () => {
|
const fetchTVGenres = async () => {
|
||||||
|
@ -215,7 +241,7 @@ export function Discover() {
|
||||||
};
|
};
|
||||||
|
|
||||||
function renderMovies(medias: Media[], category: string, isTVShow = false) {
|
function renderMovies(medias: Media[], category: string, isTVShow = false) {
|
||||||
const categorySlug = category.toLowerCase().replace(/ /g, "-"); // Convert the category to a slug
|
const categorySlug = `${category.toLowerCase().replace(/ /g, "-")}${Math.random()}`; // Convert the category to a slug
|
||||||
const displayCategory =
|
const displayCategory =
|
||||||
category === "Now Playing"
|
category === "Now Playing"
|
||||||
? "In Cinemas"
|
? "In Cinemas"
|
||||||
|
@ -342,8 +368,8 @@ export function Discover() {
|
||||||
[data.genres[i], data.genres[j]] = [data.genres[j], data.genres[i]];
|
[data.genres[i], data.genres[j]] = [data.genres[j], data.genres[i]];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch only the first 6 genres
|
// Fetch only the first 5 genres
|
||||||
setGenres(data.genres.slice(0, 6));
|
setGenres(data.genres.slice(0, 5));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching genres:", error);
|
console.error("Error fetching genres:", error);
|
||||||
}
|
}
|
||||||
|
@ -479,6 +505,21 @@ export function Discover() {
|
||||||
<h1 className="text-4xl font-bold text-white mx-auto">Shows</h1>
|
<h1 className="text-4xl font-bold text-white mx-auto">Shows</h1>
|
||||||
<Divider marginClass="ml-5 my-5" />
|
<Divider marginClass="ml-5 my-5" />
|
||||||
</div>
|
</div>
|
||||||
|
{tvCategories.map((category) => (
|
||||||
|
<div
|
||||||
|
key={category.name}
|
||||||
|
id={`carousel-${category.name
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/ /g, "-")}`}
|
||||||
|
className="mt-8"
|
||||||
|
>
|
||||||
|
{renderMovies(
|
||||||
|
categoryShows[category.name] || [],
|
||||||
|
category.name,
|
||||||
|
true,
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
{tvGenres.map((genre) => (
|
{tvGenres.map((genre) => (
|
||||||
<div
|
<div
|
||||||
key={genre.id}
|
key={genre.id}
|
||||||
|
|
|
@ -44,3 +44,14 @@ export const categories: Category[] = [
|
||||||
endpoint: "/movie/popular?language=en-US",
|
endpoint: "/movie/popular?language=en-US",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const tvCategories: Category[] = [
|
||||||
|
{
|
||||||
|
name: "Top Rated",
|
||||||
|
endpoint: "/tv/top_rated?language=en-US",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Most Popular",
|
||||||
|
endpoint: "/tv/popular?language=en-US",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
Loading…
Reference in a new issue