Fix view more pages

more content, now shows correct media when trakt fails and also scrolls to the top
This commit is contained in:
Pas 2025-11-23 15:27:06 -07:00
parent 6a3d81a048
commit 1025ea087d
4 changed files with 14 additions and 3 deletions

View file

@ -97,6 +97,11 @@ export function MoreContent({ onShowDetails }: MoreContentProps) {
setIsContentVisible(false);
}, [isLoading, mediaItems, currentPage]);
// Scroll to top when entering the page
useEffect(() => {
window.scrollTo(0, 0);
}, [contentType, mediaType, id]);
const handleBack = () => {
if (lastView) {
navigate(lastView.url);

View file

@ -198,7 +198,7 @@ export function MediaCarousel({
]);
// Fetch media using our hook - only when carousel has been visible
const { media, sectionTitle } = useDiscoverMedia({
const { media, sectionTitle, actualContentType } = useDiscoverMedia({
contentType,
mediaType,
id: selectedProviderId || selectedGenreId || selectedRecommendationId,
@ -298,7 +298,7 @@ export function MediaCarousel({
if (showRecommendations && selectedRecommendationId) {
return `${baseLink}/recommendations/${selectedRecommendationId}/${mediaType}`;
}
return `${baseLink}/${content.type}/${mediaType}`;
return `${baseLink}/${actualContentType}/${mediaType}`;
}, [
moreLink,
showProviders,
@ -308,7 +308,7 @@ export function MediaCarousel({
showRecommendations,
selectedRecommendationId,
mediaType,
content.type,
actualContentType,
]);
// Loading state

View file

@ -121,6 +121,8 @@ export function useDiscoverMedia({
const [sectionTitle, setSectionTitle] = useState<string>("");
const [currentContentType, setCurrentContentType] =
useState<string>(contentType);
const [actualContentType, setActualContentType] =
useState<DiscoverContentType>(contentType);
const { t } = useTranslation();
const userLanguage = useLanguageStore((s) => s.language);
@ -131,6 +133,7 @@ export function useDiscoverMedia({
if (contentType !== currentContentType) {
setMedia([]);
setCurrentContentType(contentType);
setActualContentType(contentType); // Reset actual content type to original
}
}, [contentType, currentContentType]);
@ -475,6 +478,7 @@ export function useDiscoverMedia({
console.info(`Falling back from ${contentType} to ${fallbackType}`);
try {
const fallbackData = await attemptFetch(fallbackType);
setActualContentType(fallbackType); // Set actual content type to fallback
setMedia((prevMedia) => {
// If page is 1, replace the media array, otherwise append
return page === 1
@ -526,5 +530,6 @@ export function useDiscoverMedia({
hasMore,
refetch: fetchMedia,
sectionTitle,
actualContentType,
};
}

View file

@ -47,6 +47,7 @@ export interface UseDiscoverMediaReturn {
hasMore: boolean;
refetch: () => Promise<void>;
sectionTitle: string;
actualContentType: DiscoverContentType;
}
export interface Provider {