Add ErrorBoundaries to Home
This commit is contained in:
3 files changed
+366
-266
No files matched your search
+5
-1
@@ -173,7 +173,7 @@ function App() {
|
|||||||
|
|
||||||
const usersAvailable = async () => {
|
const usersAvailable = async () => {
|
||||||
const users = await getUserApi(window.api).getPublicUsers();
|
const users = await getUserApi(window.api).getPublicUsers();
|
||||||
if (users.data.length >= 1) {
|
if (users.status == 200 || users.data.length >= 1) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@@ -280,6 +280,10 @@ function App() {
|
|||||||
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.scrollTo(0, 0);
|
||||||
|
}, [location.key]);
|
||||||
|
|
||||||
if (!window.api) {
|
if (!window.api) {
|
||||||
serverAvailable().then((available) => {
|
serverAvailable().then((available) => {
|
||||||
if (available) {
|
if (available) {
|
||||||
|
|||||||
@@ -282,6 +282,16 @@ const CarouselSlide = ({ item }) => {
|
|||||||
size: "large",
|
size: "large",
|
||||||
}}
|
}}
|
||||||
itemUserData={item.UserData}
|
itemUserData={item.UserData}
|
||||||
|
audio={
|
||||||
|
item.Type == BaseItemKind.MusicAlbum ||
|
||||||
|
item.Type == BaseItemKind.Audio ||
|
||||||
|
item.Type == BaseItemKind.AudioBook ||
|
||||||
|
item.Type == BaseItemKind.Playlist
|
||||||
|
}
|
||||||
|
playlistItem={
|
||||||
|
item.Type == BaseItemKind.Playlist
|
||||||
|
}
|
||||||
|
playlistItemId={item.Id}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
+351
-265
@@ -31,6 +31,8 @@ import { useBackdropStore } from "../../utils/store/backdrop";
|
|||||||
|
|
||||||
import CarouselSlide from "../../components/carouselSlide";
|
import CarouselSlide from "../../components/carouselSlide";
|
||||||
import { BaseItemKind, ItemFields } from "@jellyfin/sdk/lib/generated-client";
|
import { BaseItemKind, ItemFields } from "@jellyfin/sdk/lib/generated-client";
|
||||||
|
import ErrorBoundary from "../../components/errorBoundary";
|
||||||
|
import { Typography } from "@mui/material";
|
||||||
|
|
||||||
const Home = () => {
|
const Home = () => {
|
||||||
const authUser = useQuery({
|
const authUser = useQuery({
|
||||||
@@ -63,7 +65,7 @@ const Home = () => {
|
|||||||
const libraries = useQuery({
|
const libraries = useQuery({
|
||||||
queryKey: ["libraries"],
|
queryKey: ["libraries"],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
let libs = await getUserViewsApi(window.api).getUserViews({
|
const libs = await getUserViewsApi(window.api).getUserViews({
|
||||||
userId: user.data.Id,
|
userId: user.data.Id,
|
||||||
});
|
});
|
||||||
return libs.data;
|
return libs.data;
|
||||||
@@ -214,60 +216,180 @@ const Home = () => {
|
|||||||
position: "relative",
|
position: "relative",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{latestMedia.isLoading ? (
|
<ErrorBoundary
|
||||||
<CarouselSkeleton />
|
fallback={
|
||||||
) : (
|
<div className="error">
|
||||||
<Carousel
|
<Typography>Error with Carousel</Typography>
|
||||||
content={latestMedia.data?.map((item, index) => (
|
</div>
|
||||||
<CarouselSlide item={item} key={item.Id} />
|
}
|
||||||
))}
|
>
|
||||||
onChange={(now) => {
|
{latestMedia.isLoading ? (
|
||||||
if (latestMedia.isSuccess) {
|
<CarouselSkeleton />
|
||||||
if (
|
) : (
|
||||||
!!latestMedia.data[now]
|
<Carousel
|
||||||
.ParentBackdropImageTags
|
content={latestMedia.data?.map(
|
||||||
) {
|
(item, index) => (
|
||||||
setAppBackdrop(
|
<CarouselSlide
|
||||||
`${window.api.basePath}/Items/${latestMedia.data[now].ParentBackdropItemId}/Images/Backdrop`,
|
item={item}
|
||||||
latestMedia.data[now].Id,
|
key={item.Id}
|
||||||
);
|
/>
|
||||||
} else {
|
),
|
||||||
setAppBackdrop(
|
)}
|
||||||
`${window.api.basePath}/Items/${latestMedia.data[now].Id}/Images/Backdrop`,
|
onChange={(now) => {
|
||||||
latestMedia.data[now].Id,
|
if (latestMedia.isSuccess) {
|
||||||
);
|
if (
|
||||||
|
!!latestMedia.data[now]
|
||||||
|
.ParentBackdropImageTags
|
||||||
|
) {
|
||||||
|
setAppBackdrop(
|
||||||
|
`${window.api.basePath}/Items/${latestMedia.data[now].ParentBackdropItemId}/Images/Backdrop`,
|
||||||
|
latestMedia.data[now].Id,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setAppBackdrop(
|
||||||
|
`${window.api.basePath}/Items/${latestMedia.data[now].Id}/Images/Backdrop`,
|
||||||
|
latestMedia.data[now].Id,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}}
|
||||||
}}
|
/>
|
||||||
/>
|
)}
|
||||||
)}
|
</ErrorBoundary>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className="padded-container"
|
className="padded-container"
|
||||||
style={{
|
style={{
|
||||||
padding: "1em",
|
padding: "1em",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{libraries.isLoading ? (
|
<ErrorBoundary
|
||||||
<CardsSkeleton />
|
fallback={
|
||||||
) : (
|
<div className="error">
|
||||||
<CardScroller displayCards={4} title="Libraries">
|
<Typography>
|
||||||
{libraries.status == "success" &&
|
Error with Carousel
|
||||||
libraries.data.Items.map(
|
</Typography>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{libraries.isLoading ? (
|
||||||
|
<CardsSkeleton />
|
||||||
|
) : (
|
||||||
|
<CardScroller
|
||||||
|
displayCards={4}
|
||||||
|
title="Libraries"
|
||||||
|
>
|
||||||
|
{libraries.status == "success" &&
|
||||||
|
libraries.data.Items.map(
|
||||||
|
(item, index) => {
|
||||||
|
return (
|
||||||
|
<Card
|
||||||
|
key={item.Id}
|
||||||
|
item={item}
|
||||||
|
cardTitle={
|
||||||
|
item.Name
|
||||||
|
}
|
||||||
|
imageType="Primary"
|
||||||
|
cardType="thumb"
|
||||||
|
disableOverlay
|
||||||
|
onClick={() =>
|
||||||
|
navigate(
|
||||||
|
`/library/${item.Id}`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
imageBlurhash={
|
||||||
|
!!item
|
||||||
|
.ImageBlurHashes
|
||||||
|
?.Primary &&
|
||||||
|
item
|
||||||
|
.ImageBlurHashes
|
||||||
|
?.Primary[
|
||||||
|
Object.keys(
|
||||||
|
item
|
||||||
|
.ImageBlurHashes
|
||||||
|
.Primary,
|
||||||
|
)[0]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
></Card>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
</CardScroller>
|
||||||
|
)}
|
||||||
|
</ErrorBoundary>
|
||||||
|
<ErrorBoundary
|
||||||
|
fallback={
|
||||||
|
<div className="error">
|
||||||
|
<Typography>
|
||||||
|
Error with Libraries
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{upNextItems.isLoading ? (
|
||||||
|
<CardsSkeleton />
|
||||||
|
) : upNextItems.isSuccess &&
|
||||||
|
upNextItems.data.Items.length == 0 ? (
|
||||||
|
<></>
|
||||||
|
) : (
|
||||||
|
<CardScroller
|
||||||
|
displayCards={4}
|
||||||
|
title="Up Next"
|
||||||
|
>
|
||||||
|
{upNextItems.data.Items.map(
|
||||||
(item, index) => {
|
(item, index) => {
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
key={item.Id}
|
key={item.Id}
|
||||||
item={item}
|
item={item}
|
||||||
cardTitle={
|
cardTitle={
|
||||||
item.Name
|
item.Type ==
|
||||||
|
BaseItemKind.Episode
|
||||||
|
? item.SeriesName
|
||||||
|
: item.Name
|
||||||
|
}
|
||||||
|
imageType={
|
||||||
|
item.Type ==
|
||||||
|
BaseItemKind.Episode
|
||||||
|
? "Primary"
|
||||||
|
: Object.keys(
|
||||||
|
item.ImageTags,
|
||||||
|
).includes(
|
||||||
|
"Thumb",
|
||||||
|
)
|
||||||
|
? "Thumb"
|
||||||
|
: "Backdrop"
|
||||||
|
}
|
||||||
|
cardCaption={
|
||||||
|
item.Type ==
|
||||||
|
BaseItemKind.Episode
|
||||||
|
? `S${item.ParentIndexNumber}:E${item.IndexNumber} - ${item.Name}`
|
||||||
|
: item.Type ==
|
||||||
|
BaseItemKind.Series
|
||||||
|
? `${
|
||||||
|
item.ProductionYear
|
||||||
|
} - ${
|
||||||
|
!!item.EndDate
|
||||||
|
? new Date(
|
||||||
|
item.EndDate,
|
||||||
|
).toLocaleString(
|
||||||
|
[],
|
||||||
|
{
|
||||||
|
year: "numeric",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: "Present"
|
||||||
|
}`
|
||||||
|
: item.ProductionYear
|
||||||
}
|
}
|
||||||
imageType="Primary"
|
|
||||||
cardType="thumb"
|
cardType="thumb"
|
||||||
disableOverlay
|
queryKey={[
|
||||||
onClick={() =>
|
"home",
|
||||||
navigate(
|
"upNext",
|
||||||
`/library/${item.Id}`,
|
]}
|
||||||
)
|
userId={
|
||||||
|
user.data.Id
|
||||||
}
|
}
|
||||||
imageBlurhash={
|
imageBlurhash={
|
||||||
!!item
|
!!item
|
||||||
@@ -287,231 +409,195 @@ const Home = () => {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
</CardScroller>
|
</CardScroller>
|
||||||
)}
|
)}
|
||||||
{upNextItems.isLoading ? (
|
</ErrorBoundary>
|
||||||
<CardsSkeleton />
|
<ErrorBoundary
|
||||||
) : upNextItems.isSuccess &&
|
fallback={
|
||||||
upNextItems.data.Items.length == 0 ? (
|
<div className="error">
|
||||||
<></>
|
<Typography>
|
||||||
) : (
|
Error with resumeItemsVideo
|
||||||
<CardScroller displayCards={4} title="Up Next">
|
</Typography>
|
||||||
{upNextItems.data.Items.map(
|
</div>
|
||||||
(item, index) => {
|
}
|
||||||
return (
|
>
|
||||||
<Card
|
{resumeItemsVideo.isLoading ? (
|
||||||
key={item.Id}
|
<CardsSkeleton />
|
||||||
item={item}
|
) : resumeItemsVideo.isSuccess &&
|
||||||
cardTitle={
|
resumeItemsVideo.data.Items.length == 0 ? (
|
||||||
item.Type ==
|
<></>
|
||||||
BaseItemKind.Episode
|
) : (
|
||||||
? item.SeriesName
|
<CardScroller
|
||||||
: item.Name
|
displayCards={4}
|
||||||
}
|
title="Continue Watching"
|
||||||
imageType={
|
>
|
||||||
item.Type ==
|
{resumeItemsVideo.data.Items.map(
|
||||||
BaseItemKind.Episode
|
(item, index) => {
|
||||||
? "Primary"
|
return (
|
||||||
: Object.keys(
|
<Card
|
||||||
item.ImageTags,
|
key={item.Id}
|
||||||
).includes(
|
item={item}
|
||||||
"Thumb",
|
cardTitle={
|
||||||
)
|
item.Type ==
|
||||||
? "Thumb"
|
BaseItemKind.Episode
|
||||||
: "Backdrop"
|
? item.SeriesName
|
||||||
}
|
: item.Name
|
||||||
cardCaption={
|
}
|
||||||
item.Type ==
|
imageType={
|
||||||
BaseItemKind.Episode
|
item.Type ==
|
||||||
? `S${item.ParentIndexNumber}:E${item.IndexNumber} - ${item.Name}`
|
BaseItemKind.Episode
|
||||||
: item.Type ==
|
? "Primary"
|
||||||
BaseItemKind.Series
|
: Object.keys(
|
||||||
? `${
|
item.ImageTags,
|
||||||
item.ProductionYear
|
).includes(
|
||||||
} - ${
|
"Thumb",
|
||||||
!!item.EndDate
|
)
|
||||||
? new Date(
|
? "Thumb"
|
||||||
item.EndDate,
|
: "Backdrop"
|
||||||
).toLocaleString(
|
}
|
||||||
[],
|
cardCaption={
|
||||||
{
|
item.Type ==
|
||||||
year: "numeric",
|
BaseItemKind.Episode
|
||||||
},
|
? `S${item.ParentIndexNumber}:E${item.IndexNumber} - ${item.Name}`
|
||||||
)
|
: item.Type ==
|
||||||
: "Present"
|
BaseItemKind.Series
|
||||||
}`
|
? `${
|
||||||
: item.ProductionYear
|
item.ProductionYear
|
||||||
}
|
} - ${
|
||||||
cardType="thumb"
|
!!item.EndDate
|
||||||
queryKey={[
|
? new Date(
|
||||||
"home",
|
item.EndDate,
|
||||||
"upNext",
|
).toLocaleString(
|
||||||
]}
|
[],
|
||||||
userId={user.data.Id}
|
{
|
||||||
imageBlurhash={
|
year: "numeric",
|
||||||
!!item
|
},
|
||||||
.ImageBlurHashes
|
)
|
||||||
?.Primary &&
|
: "Present"
|
||||||
item.ImageBlurHashes
|
}`
|
||||||
?.Primary[
|
: item.ProductionYear
|
||||||
Object.keys(
|
}
|
||||||
item
|
cardType="thumb"
|
||||||
.ImageBlurHashes
|
queryKey={[
|
||||||
.Primary,
|
"home",
|
||||||
)[0]
|
"resume",
|
||||||
]
|
"video",
|
||||||
}
|
]}
|
||||||
></Card>
|
userId={
|
||||||
);
|
user.data.Id
|
||||||
},
|
}
|
||||||
)}
|
imageBlurhash={
|
||||||
</CardScroller>
|
!!item
|
||||||
)}
|
.ImageBlurHashes
|
||||||
{resumeItemsVideo.isLoading ? (
|
?.Primary &&
|
||||||
<CardsSkeleton />
|
item
|
||||||
) : resumeItemsVideo.data.Items.length == 0 ? (
|
.ImageBlurHashes
|
||||||
<></>
|
?.Primary[
|
||||||
) : (
|
Object.keys(
|
||||||
<CardScroller
|
item
|
||||||
displayCards={4}
|
.ImageBlurHashes
|
||||||
title="Continue Watching"
|
.Primary,
|
||||||
>
|
)[0]
|
||||||
{resumeItemsVideo.data.Items.map(
|
]
|
||||||
(item, index) => {
|
}
|
||||||
return (
|
></Card>
|
||||||
<Card
|
);
|
||||||
key={item.Id}
|
},
|
||||||
item={item}
|
)}
|
||||||
cardTitle={
|
</CardScroller>
|
||||||
item.Type ==
|
)}
|
||||||
BaseItemKind.Episode
|
</ErrorBoundary>
|
||||||
? item.SeriesName
|
<ErrorBoundary
|
||||||
: item.Name
|
fallback={
|
||||||
}
|
<div className="error">
|
||||||
imageType={
|
<Typography>
|
||||||
item.Type ==
|
Error with resumeItemsAudio
|
||||||
BaseItemKind.Episode
|
</Typography>
|
||||||
? "Primary"
|
</div>
|
||||||
: Object.keys(
|
}
|
||||||
item.ImageTags,
|
>
|
||||||
).includes(
|
{resumeItemsAudio.isLoading ? (
|
||||||
"Thumb",
|
<CardsSkeleton />
|
||||||
)
|
) : resumeItemsAudio.isSuccess &&
|
||||||
? "Thumb"
|
resumeItemsAudio.data.Items.length == 0 ? (
|
||||||
: "Backdrop"
|
<></>
|
||||||
}
|
) : (
|
||||||
cardCaption={
|
<CardScroller
|
||||||
item.Type ==
|
displayCards={4}
|
||||||
BaseItemKind.Episode
|
title="Continue Listening"
|
||||||
? `S${item.ParentIndexNumber}:E${item.IndexNumber} - ${item.Name}`
|
>
|
||||||
: item.Type ==
|
{resumeItemsAudio.data.Items.map(
|
||||||
BaseItemKind.Series
|
(item, index) => {
|
||||||
? `${
|
return (
|
||||||
item.ProductionYear
|
<Card
|
||||||
} - ${
|
key={item.Id}
|
||||||
!!item.EndDate
|
item={item}
|
||||||
? new Date(
|
cardTitle={
|
||||||
item.EndDate,
|
item.Name
|
||||||
).toLocaleString(
|
}
|
||||||
[],
|
imageType={
|
||||||
{
|
item.Type ==
|
||||||
year: "numeric",
|
BaseItemKind.Episode
|
||||||
},
|
? "Primary"
|
||||||
)
|
: Object.keys(
|
||||||
: "Present"
|
item.ImageTags,
|
||||||
}`
|
).includes(
|
||||||
: item.ProductionYear
|
"Thumb",
|
||||||
}
|
)
|
||||||
cardType="thumb"
|
? "Thumb"
|
||||||
queryKey={[
|
: "Backdrop"
|
||||||
"home",
|
}
|
||||||
"resume",
|
cardCaption={
|
||||||
"video",
|
item.ProductionYear
|
||||||
]}
|
}
|
||||||
userId={user.data.Id}
|
cardType="thumb"
|
||||||
imageBlurhash={
|
queryKey={[
|
||||||
!!item
|
"home",
|
||||||
.ImageBlurHashes
|
"resume",
|
||||||
?.Primary &&
|
"audio",
|
||||||
item.ImageBlurHashes
|
]}
|
||||||
?.Primary[
|
userId={
|
||||||
Object.keys(
|
user.data.Id
|
||||||
item
|
}
|
||||||
.ImageBlurHashes
|
imageBlurhash={
|
||||||
.Primary,
|
item
|
||||||
)[0]
|
.ImageBlurHashes
|
||||||
]
|
?.Primary &&
|
||||||
}
|
item
|
||||||
></Card>
|
.ImageBlurHashes
|
||||||
);
|
?.Primary[
|
||||||
},
|
Object.keys(
|
||||||
)}
|
item
|
||||||
</CardScroller>
|
.ImageBlurHashes
|
||||||
)}
|
.Primary,
|
||||||
{resumeItemsAudio.isLoading ? (
|
)[0]
|
||||||
<CardsSkeleton />
|
]
|
||||||
) : resumeItemsAudio.data.Items.length == 0 ? (
|
}
|
||||||
<></>
|
></Card>
|
||||||
) : (
|
);
|
||||||
<CardScroller
|
},
|
||||||
displayCards={4}
|
)}
|
||||||
title="Continue Listening"
|
</CardScroller>
|
||||||
>
|
)}
|
||||||
{resumeItemsAudio.data.Items.map(
|
</ErrorBoundary>
|
||||||
(item, index) => {
|
<ErrorBoundary
|
||||||
return (
|
fallback={
|
||||||
<Card
|
<div className="error">
|
||||||
key={item.Id}
|
<Typography>
|
||||||
item={item}
|
Error with LatestMediaSections
|
||||||
cardTitle={item.Name}
|
</Typography>
|
||||||
imageType={
|
</div>
|
||||||
item.Type ==
|
}
|
||||||
BaseItemKind.Episode
|
>
|
||||||
? "Primary"
|
{latestMediaLibs.map((lib, index) => {
|
||||||
: Object.keys(
|
return (
|
||||||
item.ImageTags,
|
<LatestMediaSection
|
||||||
).includes(
|
key={lib[0]}
|
||||||
"Thumb",
|
latestMediaLib={lib}
|
||||||
)
|
/>
|
||||||
? "Thumb"
|
);
|
||||||
: "Backdrop"
|
})}
|
||||||
}
|
</ErrorBoundary>
|
||||||
cardCaption={
|
|
||||||
item.ProductionYear
|
|
||||||
}
|
|
||||||
cardType="thumb"
|
|
||||||
queryKey={[
|
|
||||||
"home",
|
|
||||||
"resume",
|
|
||||||
"audio",
|
|
||||||
]}
|
|
||||||
userId={user.data.Id}
|
|
||||||
imageBlurhash={
|
|
||||||
item.ImageBlurHashes
|
|
||||||
?.Primary &&
|
|
||||||
item.ImageBlurHashes
|
|
||||||
?.Primary[
|
|
||||||
Object.keys(
|
|
||||||
item
|
|
||||||
.ImageBlurHashes
|
|
||||||
.Primary,
|
|
||||||
)[0]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
></Card>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
)}
|
|
||||||
</CardScroller>
|
|
||||||
)}
|
|
||||||
{latestMediaLibs.map((lib, index) => {
|
|
||||||
return (
|
|
||||||
<LatestMediaSection
|
|
||||||
key={lib[0]}
|
|
||||||
latestMediaLib={lib}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in new issue
Block a user