Skip to content

Commit

Permalink
skip empty pages
Browse files Browse the repository at this point in the history
  • Loading branch information
John Corser committed Jan 5, 2025
1 parent b1be7c7 commit a68bb9d
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 18 deletions.
10 changes: 8 additions & 2 deletions src/components/pages/AudioReviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { styled } from "@stitches/react";
import { useNavigate } from "react-router-dom";
import { useErrorBoundary } from "react-error-boundary";

const NEXT_PAGE = '/music-videos'

export default function AudioReviewPage() {
const { showBoundary } = useErrorBoundary();
const navigate = useNavigate();
Expand All @@ -18,7 +20,11 @@ export default function AudioReviewPage() {
const setup = async (): Promise<void> => {
setIsLoading(true);
try {
setAudios(await listAudio());
const fetched = await listAudio();
if (!fetched.length) {
void navigate(NEXT_PAGE);
}
setAudios(fetched);
} catch (e) {
showBoundary(e);
} finally {
Expand Down Expand Up @@ -85,7 +91,7 @@ export default function AudioReviewPage() {
size={"4"}
style={{ width: "100%" }}
onClick={() => {
void navigate("/music-videos");
void navigate(NEXT_PAGE);
}}
>
Review Music Videos
Expand Down
10 changes: 7 additions & 3 deletions src/components/pages/FavoriteActorsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { generateGuid } from "@/lib/utils";
import { BaseItemPerson } from "@jellyfin/sdk/lib/generated-client";
import { ActorCard } from "./MoviesReviewPage/ActorCard";
import { useErrorBoundary } from "react-error-boundary";

const NEXT_PAGE = '/genres';
export default function FavoriteActorsPage() {
const { showBoundary } = useErrorBoundary();
const navigate = useNavigate();
Expand All @@ -30,7 +30,11 @@ export default function FavoriteActorsPage() {
const setup = async () => {
setIsLoading(true);
try {
setFavoriteActors(await listFavoriteActors());
const fetched = await listFavoriteActors();
if (!fetched.length) {
void navigate(NEXT_PAGE);
}
setFavoriteActors(fetched);
} catch (e) {
showBoundary(e);
} finally {
Expand Down Expand Up @@ -87,7 +91,7 @@ export default function FavoriteActorsPage() {
size={"4"}
style={{ width: "100%" }}
onClick={() => {
void navigate("/genres");
void navigate(NEXT_PAGE);
}}
>
Review Top Genres
Expand Down
6 changes: 5 additions & 1 deletion src/components/pages/GenreReviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { generateGuid } from "@/lib/utils";
import { useErrorBoundary } from "react-error-boundary";
import { getCachedHiddenIds, setCachedHiddenId } from "@/lib/cache";

const NEXT_PAGE = '/holidays';
export default function GenreReviewPage() {
const { showBoundary } = useErrorBoundary();
const navigate = useNavigate();
Expand All @@ -35,6 +36,9 @@ export default function GenreReviewPage() {
.map((show) => show.item)
.filter((show) => !hiddenIds.includes(show.id ?? "")),
);
if (!movies.length && !shows.length) {
void navigate(NEXT_PAGE);
}
} catch (error) {
showBoundary(error);
} finally {
Expand Down Expand Up @@ -121,7 +125,7 @@ export default function GenreReviewPage() {
size={"4"}
style={{ width: "100%" }}
onClick={() => {
void navigate("/holidays");
void navigate(NEXT_PAGE);
}}
>
Review Holidays
Expand Down
7 changes: 6 additions & 1 deletion src/components/pages/HolidayReviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
getValentinesDay,
} from "date-fns-holiday-us";
import { isAfter, isSameDay, subDays } from "date-fns";

const NEXT_PAGE = '/tv';
export default function HolidayReviewPage() {
const { showBoundary } = useErrorBoundary();
const navigate = useNavigate();
Expand Down Expand Up @@ -87,6 +89,9 @@ export default function HolidayReviewPage() {
setValentinesItems(
valentinesItems.filter((item) => !hiddenIds.includes(item.id ?? "")),
);
if (christmasItems.length === 0 && christmasEveItems.length === 0 && halloweenItems.length === 0 && valentinesItems.length === 0) {
void navigate(NEXT_PAGE);
}
} catch (error) {
showBoundary(error);
} finally {
Expand Down Expand Up @@ -200,7 +205,7 @@ export default function HolidayReviewPage() {
size={"4"}
style={{ width: "100%" }}
onClick={() => {
void navigate("/tv");
void navigate(NEXT_PAGE);
}}
>
Review Live TV
Expand Down
6 changes: 5 additions & 1 deletion src/components/pages/LiveTvReviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface ChannelCardProps {
duration: number;
}

const NEXT_PAGE = '/audio';
export function ChannelCard({ channelName, duration }: ChannelCardProps) {
return (
<motion.div
Expand Down Expand Up @@ -48,6 +49,9 @@ export default function LiveTvReviewPage() {
const channelData = await listLiveTvChannels();
// Sort channels by duration in descending order
channelData.sort((a, b) => b.duration - a.duration);
if (!channelData.length) {
void navigate(NEXT_PAGE);
}
setChannels(channelData);
} catch (e) {
showBoundary(e);
Expand Down Expand Up @@ -108,7 +112,7 @@ export default function LiveTvReviewPage() {
size={"4"}
style={{ width: "100%" }}
onClick={() => {
void navigate("/audio");
void navigate(NEXT_PAGE);
}}
>
Review Audio
Expand Down
6 changes: 5 additions & 1 deletion src/components/pages/MoviesReviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { generateGuid } from "@/lib/utils";
import { useErrorBoundary } from "react-error-boundary";
import { getCachedHiddenIds, setCachedHiddenId } from "@/lib/cache";

const NEXT_PAGE = '/oldest-movie'
export default function MoviesReviewPage() {
const { showBoundary } = useErrorBoundary();
const navigate = useNavigate();
Expand All @@ -24,6 +25,9 @@ export default function MoviesReviewPage() {
setMovies(
movies.filter((movie) => !hiddenIds.includes(movie.id ?? "")),
);
if (!movies.length) {
void navigate(NEXT_PAGE);
}
} catch (error) {
showBoundary(error);
} finally {
Expand Down Expand Up @@ -79,7 +83,7 @@ export default function MoviesReviewPage() {
size={"4"}
style={{ width: "100%" }}
onClick={() => {
void navigate("/oldest-movie");
void navigate(NEXT_PAGE);
}}
>
Review Oldest Movie
Expand Down
9 changes: 7 additions & 2 deletions src/components/pages/MusicVideoPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { styled } from "@stitches/react";
import { useNavigate } from "react-router-dom";
import { useErrorBoundary } from "react-error-boundary";

const NEXT_PAGE = "/";
export default function MusicVideoPage() {
const { showBoundary } = useErrorBoundary();
const navigate = useNavigate();
Expand All @@ -21,7 +22,11 @@ export default function MusicVideoPage() {
const setup = async () => {
setIsLoading(true);
try {
setMusicVideos(await listMusicVideos());
const fetched = await listMusicVideos();
if (!fetched.length) {
void navigate(NEXT_PAGE);
}
setMusicVideos(fetched);
} catch (error) {
showBoundary(error);
} finally {
Expand Down Expand Up @@ -88,7 +93,7 @@ export default function MusicVideoPage() {
size={"4"}
style={{ width: "100%" }}
onClick={() => {
void navigate("/");
void navigate(NEXT_PAGE);
}}
>
Home
Expand Down
8 changes: 6 additions & 2 deletions src/components/pages/OldestMoviePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useNavigate } from "react-router-dom";
import { Subtitle } from "../ui/styled";
import { useErrorBoundary } from "react-error-boundary";

const NEXT_PAGE = "/shows";
export default function OldestMoviePage() {
const { showBoundary } = useErrorBoundary();

Expand All @@ -26,6 +27,9 @@ export default function OldestMoviePage() {
return aDate.getTime() - bDate.getTime();
});
const m = movies.find((s) => s);
if (!m) {
void navigate(NEXT_PAGE);
}
setMovie(m);
} catch (e) {
showBoundary(e);
Expand Down Expand Up @@ -79,7 +83,7 @@ export default function OldestMoviePage() {
size={"4"}
style={{ width: "100%" }}
onClick={() => {
void navigate("/shows");
void navigate(NEXT_PAGE);
}}
>
Review Shows
Expand Down Expand Up @@ -121,7 +125,7 @@ export default function OldestMoviePage() {
size={"4"}
style={{ width: "100%" }}
onClick={() => {
void navigate("/shows");
void navigate(NEXT_PAGE);
}}
>
Review Shows
Expand Down
8 changes: 6 additions & 2 deletions src/components/pages/OldestShowPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useNavigate } from "react-router-dom";
import { Subtitle } from "../ui/styled";
import { useErrorBoundary } from "react-error-boundary";

const NEXT_PAGE = "/actors";
export default function OldestShowPage() {
const { showBoundary } = useErrorBoundary();
const navigate = useNavigate();
Expand All @@ -30,6 +31,9 @@ export default function OldestShowPage() {
return aDate.getTime() - bDate.getTime();
});
const s = shows.find((s) => s);
if (!s) {
void navigate(NEXT_PAGE);
}
setShow(s);
} catch (e) {
showBoundary(e);
Expand Down Expand Up @@ -82,7 +86,7 @@ export default function OldestShowPage() {
size={"4"}
style={{ width: "100%" }}
onClick={() => {
void navigate("/actors");
void navigate(NEXT_PAGE);
}}
>
Review Favorite Actors
Expand Down Expand Up @@ -130,7 +134,7 @@ export default function OldestShowPage() {
size={"4"}
style={{ width: "100%" }}
onClick={() => {
void navigate("/actors");
void navigate(NEXT_PAGE);
}}
>
Review Favorite Actors
Expand Down
11 changes: 10 additions & 1 deletion src/components/pages/ServerConfigurationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import {
setCacheValue,
} from "@/lib/cache";
import { useErrorBoundary } from "react-error-boundary";
import { listAudio, listLiveTvChannels, listMovies, listShows } from "@/lib/playback-reporting-queries";

const NEXT_PAGE = '/movies'
type WindowOverride = typeof Window & {
ENV:
| {
Expand Down Expand Up @@ -81,7 +84,13 @@ const ServerConfigurationPage = () => {
await authenticateByUserName(serverUrl, username, password);
}

void navigate("/movies");
// Warm caches
void listMovies();
void listShows();
void listAudio();
void listLiveTvChannels();

void navigate(NEXT_PAGE);
} catch (e) {
showBoundary(e);
} finally {
Expand Down
6 changes: 5 additions & 1 deletion src/components/pages/ShowReviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useNavigate } from "react-router-dom";
import { useErrorBoundary } from "react-error-boundary";
import { getCachedHiddenIds, setCachedHiddenId } from "@/lib/cache";

const NEXT_PAGE = "/oldest-show";
export default function ShowReviewPage() {
const { showBoundary } = useErrorBoundary();
const navigate = useNavigate();
Expand All @@ -31,6 +32,9 @@ export default function ShowReviewPage() {
(show) => !hiddenIds.includes(show.item.id ?? ""),
);
setShows(filteredShows);
if (!filteredShows.length) {
void navigate(NEXT_PAGE);
}
} catch (e) {
showBoundary(e);
} finally {
Expand Down Expand Up @@ -110,7 +114,7 @@ export default function ShowReviewPage() {
size={"4"}
style={{ width: "100%" }}
onClick={() => {
void navigate("/oldest-show");
void navigate(NEXT_PAGE);
}}
>
Review Oldest Show
Expand Down
3 changes: 2 additions & 1 deletion src/components/pages/SplashPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Title,
} from "../ui/styled";

const NEXT_PAGE = "/configure";
const SplashPage = () => {
const navigate = useNavigate();

Expand Down Expand Up @@ -101,7 +102,7 @@ const SplashPage = () => {
>
<StyledButton
onClick={() => {
void navigate("/configure");
void navigate(NEXT_PAGE);
}}
>
Connect Your Jellyfin Server
Expand Down

0 comments on commit a68bb9d

Please sign in to comment.