refactor: unmount card image if not inView
This commit is contained in:
8 files changed
+155
-121
No files matched your search
@@ -60,6 +60,7 @@
|
||||
"react-dnd-html5-backend": "^16.0.1",
|
||||
"react-dom": "18.3.1",
|
||||
"react-error-boundary": "^4.1.2",
|
||||
"react-intersection-observer": "^9.13.1",
|
||||
"react-markdown": "^9.0.1",
|
||||
"react-multi-carousel": "^2.8.5",
|
||||
"react-player": "^2.16.0",
|
||||
|
||||
Generated
+18
@@ -149,6 +149,9 @@ importers:
|
||||
react-error-boundary:
|
||||
specifier: ^4.1.2
|
||||
version: 4.1.2(react@18.3.1)
|
||||
react-intersection-observer:
|
||||
specifier: ^9.13.1
|
||||
version: 9.13.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||
react-markdown:
|
||||
specifier: ^9.0.1
|
||||
version: 9.0.1(@types/react@18.3.12)(react@18.3.1)
|
||||
@@ -2729,6 +2732,15 @@ packages:
|
||||
react-fast-compare@3.2.2:
|
||||
resolution: {integrity: sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ==}
|
||||
|
||||
react-intersection-observer@9.13.1:
|
||||
resolution: {integrity: sha512-tSzDaTy0qwNPLJHg8XZhlyHTgGW6drFKTtvjdL+p6um12rcnp8Z5XstE+QNBJ7c64n5o0Lj4ilUleA41bmDoMw==}
|
||||
peerDependencies:
|
||||
react: ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||
react-dom: ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||
peerDependenciesMeta:
|
||||
react-dom:
|
||||
optional: true
|
||||
|
||||
react-is@16.13.1:
|
||||
resolution: {integrity: sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==}
|
||||
|
||||
@@ -5733,6 +5745,12 @@ snapshots:
|
||||
|
||||
react-fast-compare@3.2.2: {}
|
||||
|
||||
react-intersection-observer@9.13.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1):
|
||||
dependencies:
|
||||
react: 18.3.1
|
||||
optionalDependencies:
|
||||
react-dom: 18.3.1(react@18.3.1)
|
||||
|
||||
react-is@16.13.1: {}
|
||||
|
||||
react-is@18.3.1: {}
|
||||
|
||||
@@ -20,6 +20,8 @@ import "./card.scss";
|
||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
|
||||
import { useInView } from "react-intersection-observer";
|
||||
|
||||
const CardComponent = ({
|
||||
item,
|
||||
cardTitle,
|
||||
@@ -80,8 +82,16 @@ const CardComponent = ({
|
||||
}
|
||||
};
|
||||
|
||||
const { ref, inView } = useInView({
|
||||
threshold: 0,
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="card" onClick={onClick ? onClick : defaultOnClick}>
|
||||
<div
|
||||
className="card"
|
||||
ref={ref}
|
||||
onClick={onClick ? onClick : defaultOnClick}
|
||||
>
|
||||
<div className={`card-image-container ${cardType}`}>
|
||||
<ErrorBoundary fallback>
|
||||
<div
|
||||
@@ -112,73 +122,74 @@ const CardComponent = ({
|
||||
? getTypeIcon(overrideIcon)
|
||||
: getTypeIcon(item.Type ?? "universal")}
|
||||
</div>
|
||||
<img
|
||||
alt={item.Name ?? "blink"}
|
||||
src={
|
||||
api
|
||||
? overrideIcon === "User"
|
||||
? `${api?.basePath}/Users/${item.Id}/Images/Primary`
|
||||
: getImageUrlsApi(api).getItemImageUrlById(
|
||||
(seriesId ? item.SeriesId : (item.AlbumId ?? item.Id)) ??
|
||||
"",
|
||||
imageType,
|
||||
{
|
||||
quality: 90,
|
||||
fillWidth: cardType === "thumb" ? 560 : 280,
|
||||
},
|
||||
)
|
||||
: ""
|
||||
}
|
||||
style={{
|
||||
height: "100%",
|
||||
width: "100%",
|
||||
opacity: 0,
|
||||
}}
|
||||
loading="lazy"
|
||||
onLoad={(e) => {
|
||||
e.currentTarget.style.setProperty("opacity", "1");
|
||||
}}
|
||||
onLoadStart={(e) => console.log(e)}
|
||||
className="card-image"
|
||||
/>
|
||||
<div className="card-overlay">
|
||||
{!disableOverlay && (
|
||||
<>
|
||||
<PlayButton
|
||||
item={item}
|
||||
userId={userId}
|
||||
itemType={item.Type ?? "Movie"}
|
||||
currentAudioTrack={0}
|
||||
currentSubTrack="nosub"
|
||||
currentVideoTrack={0}
|
||||
className="card-play-button"
|
||||
iconOnly
|
||||
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}
|
||||
/>
|
||||
<LikeButton
|
||||
itemId={item.Id}
|
||||
itemName={item.Name ?? ""}
|
||||
isFavorite={item.UserData?.IsFavorite}
|
||||
queryKey={queryKey}
|
||||
userId={userId}
|
||||
/>
|
||||
<MarkPlayedButton
|
||||
itemId={item.Id}
|
||||
itemName={item.Name ?? ""}
|
||||
isPlayed={item.UserData?.Played}
|
||||
queryKey={queryKey}
|
||||
userId={userId}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{inView && (
|
||||
<img
|
||||
alt={item.Name ?? "blink"}
|
||||
src={
|
||||
api
|
||||
? overrideIcon === "User"
|
||||
? `${api?.basePath}/Users/${item.Id}/Images/Primary`
|
||||
: getImageUrlsApi(api).getItemImageUrlById(
|
||||
(seriesId ? item.SeriesId : (item.AlbumId ?? item.Id)) ??
|
||||
"",
|
||||
imageType,
|
||||
{
|
||||
quality: 90,
|
||||
fillWidth: cardType === "thumb" ? 560 : 280,
|
||||
},
|
||||
)
|
||||
: ""
|
||||
}
|
||||
style={{
|
||||
height: "100%",
|
||||
width: "100%",
|
||||
opacity: 0,
|
||||
}}
|
||||
loading="lazy"
|
||||
onLoad={(e) => {
|
||||
e.currentTarget.style.setProperty("opacity", "1");
|
||||
}}
|
||||
onLoadStart={(e) => console.log(e)}
|
||||
className="card-image"
|
||||
/>
|
||||
)}
|
||||
|
||||
{inView && !disableOverlay && (
|
||||
<div className="card-overlay">
|
||||
<PlayButton
|
||||
item={item}
|
||||
userId={userId}
|
||||
itemType={item.Type ?? "Movie"}
|
||||
currentAudioTrack={0}
|
||||
currentSubTrack="nosub"
|
||||
currentVideoTrack={0}
|
||||
className="card-play-button"
|
||||
iconOnly
|
||||
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}
|
||||
/>
|
||||
<LikeButton
|
||||
itemId={item.Id}
|
||||
itemName={item.Name ?? ""}
|
||||
isFavorite={item.UserData?.IsFavorite}
|
||||
queryKey={queryKey}
|
||||
userId={userId}
|
||||
/>
|
||||
<MarkPlayedButton
|
||||
itemId={item.Id}
|
||||
itemName={item.Name ?? ""}
|
||||
isPlayed={item.UserData?.Played}
|
||||
queryKey={queryKey}
|
||||
userId={userId}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{(item.UserData?.PlaybackPositionTicks ?? -1) > 0 && (
|
||||
<div className="card-progress-container">
|
||||
<div
|
||||
|
||||
@@ -151,7 +151,9 @@ function ItemDetail() {
|
||||
}
|
||||
return false;
|
||||
});
|
||||
setSelectedVideoTrack(result?.find((track) => track.IsDefault)?.Index ?? 0);
|
||||
setSelectedVideoTrack(
|
||||
result?.find((track) => track.IsDefault)?.Index ?? result?.[0].Index ?? 0,
|
||||
);
|
||||
return result ?? [];
|
||||
}, [item.data?.Id]);
|
||||
const audioTracks = useMemo(() => {
|
||||
@@ -161,7 +163,9 @@ function ItemDetail() {
|
||||
}
|
||||
return false;
|
||||
});
|
||||
setSelectedAudioTrack(result?.find((track) => track.IsDefault)?.Index ?? 0);
|
||||
setSelectedAudioTrack(
|
||||
result?.find((track) => track.IsDefault)?.Index ?? result?.[0].Index ?? 0,
|
||||
);
|
||||
return result ?? [];
|
||||
}, [item.data?.Id]);
|
||||
const subtitleTracks = useMemo(() => {
|
||||
@@ -171,9 +175,7 @@ function ItemDetail() {
|
||||
}
|
||||
return false;
|
||||
});
|
||||
setSelectedSubtitleTrack(
|
||||
result?.find((track) => track.IsDefault)?.Index ?? -1,
|
||||
);
|
||||
setSelectedSubtitleTrack(result?.find((track) => track.IsDefault)?.Index ?? -1);
|
||||
return result ?? [];
|
||||
}, [item.data?.Id]);
|
||||
|
||||
|
||||
@@ -168,7 +168,6 @@ function PersonTitlePage() {
|
||||
fields: ["SeasonUserData", "Overview"],
|
||||
sortBy: ["PremiereDate", "ProductionYear", "SortName"],
|
||||
excludeLocationTypes: [LocationType.Virtual],
|
||||
limit: 24,
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
@@ -476,17 +475,6 @@ function PersonTitlePage() {
|
||||
);
|
||||
})}
|
||||
</motion.div>
|
||||
{tab.data.isSuccess &&
|
||||
(tab.data.data?.TotalRecordCount ?? 0) > 24 && (
|
||||
<Typography
|
||||
variant="h6"
|
||||
style={{
|
||||
opacity: 0.8,
|
||||
}}
|
||||
>
|
||||
And more...
|
||||
</Typography>
|
||||
)}
|
||||
</TabPanel>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -53,8 +53,9 @@ import useQueue, { clearQueue } from "@/utils/store/queue";
|
||||
import { createFileRoute, useRouter } from "@tanstack/react-router";
|
||||
import { toNumber } from "lodash";
|
||||
import type { OnProgressProps } from "react-player/base";
|
||||
import type { TrackProps } from "react-player/file";
|
||||
|
||||
import type subtitlePlaybackInfo from "@/utils/types/subtitlePlaybackInfo";
|
||||
//@ts-ignore
|
||||
import font from "./Noto-Sans-Indosphere.ttf?url";
|
||||
|
||||
const ticksDisplay = (ticks: number) => {
|
||||
@@ -85,7 +86,7 @@ const VOLUME_SCROLL_INTERVAL = 0.02;
|
||||
*/
|
||||
function addSubtitleTrackToReactPlayer(
|
||||
videoElem: HTMLMediaElement,
|
||||
subtitleTracks,
|
||||
subtitleTracks: subtitlePlaybackInfo,
|
||||
baseUrl: string,
|
||||
) {
|
||||
if (subtitleTracks.url && subtitleTracks.allTracks) {
|
||||
@@ -191,7 +192,7 @@ function VideoPlayer() {
|
||||
const [clickTimeout, setClickTimeout] = useState<NodeJS.Timeout>(null!);
|
||||
|
||||
const handleReady = async () => {
|
||||
if (!isReady) {
|
||||
if (api && !isReady) {
|
||||
player.current?.seekTo(ticksToSec(startPosition), "seconds");
|
||||
setIsReady(true);
|
||||
// Report Jellyfin server: Playback has begin
|
||||
@@ -216,6 +217,7 @@ function VideoPlayer() {
|
||||
|
||||
const handleProgress = async (event: OnProgressProps) => {
|
||||
setProgress(secToTicks(event.playedSeconds));
|
||||
if (!api) return null;
|
||||
// Report Jellyfin server: Playback progress
|
||||
getPlaystateApi(api).reportPlaybackProgress({
|
||||
playbackProgressInfo: {
|
||||
@@ -239,6 +241,7 @@ function VideoPlayer() {
|
||||
appWindow.getCurrent().setFullscreen(false);
|
||||
|
||||
history.back();
|
||||
if (!api) return null;
|
||||
// Report Jellyfin server: Playback has ended/stopped
|
||||
getPlaystateApi(api).reportPlaybackStopped({
|
||||
playbackStopInfo: {
|
||||
@@ -314,6 +317,7 @@ function VideoPlayer() {
|
||||
};
|
||||
}, [handleKeyPress]);
|
||||
|
||||
const playerOSDRef = useRef<HTMLDivElement>(null);
|
||||
// Volume control with mouse wheel
|
||||
useEffect(() => {
|
||||
const handleMouseWheel = (event: WheelEvent) => {
|
||||
@@ -327,11 +331,11 @@ function VideoPlayer() {
|
||||
};
|
||||
|
||||
// attach the event listener
|
||||
document.addEventListener("wheel", handleMouseWheel);
|
||||
playerOSDRef.current?.addEventListener("wheel", handleMouseWheel);
|
||||
|
||||
// remove the event listener
|
||||
return () => {
|
||||
document.removeEventListener("wheel", handleMouseWheel);
|
||||
playerOSDRef.current?.removeEventListener("wheel", handleMouseWheel);
|
||||
};
|
||||
}, []);
|
||||
|
||||
@@ -355,7 +359,7 @@ function VideoPlayer() {
|
||||
video: player.current?.getInternalPlayer(),
|
||||
workerUrl,
|
||||
wasmUrl,
|
||||
subUrl: `${api.basePath}${mediaSource.subtitle.url}`,
|
||||
subUrl: `${api?.basePath}${mediaSource.subtitle.url}`,
|
||||
availableFonts: { "noto sans": font },
|
||||
fallbackFont: "noto sans",
|
||||
});
|
||||
@@ -369,7 +373,7 @@ function VideoPlayer() {
|
||||
addSubtitleTrackToReactPlayer(
|
||||
player.current.getInternalPlayer() as HTMLMediaElement,
|
||||
mediaSource.subtitle,
|
||||
api.basePath,
|
||||
api?.basePath ?? "",
|
||||
);
|
||||
console.log(videoElem.textTracks);
|
||||
}
|
||||
@@ -429,7 +433,8 @@ function VideoPlayer() {
|
||||
|
||||
const handleSkipIntro = useCallback(() => {
|
||||
player.current?.seekTo(
|
||||
ticksToSec(introInfo?.EndTicks) ?? player.current?.getCurrentTime(),
|
||||
ticksToSec(Number(introInfo?.EndTicks)) ??
|
||||
player.current?.getCurrentTime(),
|
||||
);
|
||||
}, [item?.Id]);
|
||||
|
||||
@@ -518,7 +523,7 @@ function VideoPlayer() {
|
||||
const backgroundOffsetY = -(imageOffsetY * trickplayResolution?.Height);
|
||||
|
||||
const imgUrlParamsObject: Record<string, string> = {
|
||||
api_key: api.accessToken,
|
||||
api_key: String(api?.accessToken),
|
||||
MediaSourceId: mediaSource.id ?? "",
|
||||
};
|
||||
const imgUrlParams = new URLSearchParams(imgUrlParamsObject).toString();
|
||||
@@ -529,7 +534,7 @@ function VideoPlayer() {
|
||||
<div
|
||||
className="video-osd-trickplayBubble"
|
||||
style={{
|
||||
background: `url(${api.basePath}/Videos/${item?.Id}/Trickplay/${trickplayResolution.Width}/${index}.jpg?${imgUrlParams})`,
|
||||
background: `url(${api?.basePath}/Videos/${item?.Id}/Trickplay/${trickplayResolution.Width}/${index}.jpg?${imgUrlParams})`,
|
||||
backgroundPositionX: `${backgroundOffsetX}px`,
|
||||
backgroundPositionY: `${backgroundOffsetY}px`,
|
||||
width: `${trickplayResolution.Width}px`,
|
||||
@@ -550,7 +555,7 @@ function VideoPlayer() {
|
||||
<div
|
||||
className="video-osd-trickplayBubble"
|
||||
style={{
|
||||
background: `url(${api.basePath}/Videos/${item?.Id}/Trickplay/${trickplayResolution.Width}/${index}.jpg?${imgUrlParams})`,
|
||||
background: `url(${api?.basePath}/Videos/${item?.Id}/Trickplay/${trickplayResolution.Width}/${index}.jpg?${imgUrlParams})`,
|
||||
backgroundPositionX: `${backgroundOffsetX}px`,
|
||||
backgroundPositionY: `${backgroundOffsetY}px`,
|
||||
width: `${trickplayResolution.Width}px`,
|
||||
@@ -595,7 +600,7 @@ function VideoPlayer() {
|
||||
}, [volume]);
|
||||
|
||||
const handlePlaybackEnded = () => {
|
||||
if (queue[currentQueueItemIndex + 1].Id) {
|
||||
if (queue?.[currentQueueItemIndex + 1].Id) {
|
||||
playItemFromQueue("next", user?.Id, api);
|
||||
} else {
|
||||
handleExitPlayer(); // Exit player if playback has finished and the queue is empty
|
||||
@@ -603,17 +608,23 @@ function VideoPlayer() {
|
||||
};
|
||||
|
||||
const [subtitleIsChanging, startSubtitleChange] = useTransition();
|
||||
const handleSubtitleChange = (
|
||||
e: ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>,
|
||||
) => {
|
||||
startSubtitleChange(() => {
|
||||
if (mediaSource.subtitle.allTracks) {
|
||||
changeSubtitleTrack(toNumber(e.target.value), mediaSource.subtitle.allTracks);
|
||||
console.log(mediaSource.subtitle);
|
||||
setSettingsMenu(null);
|
||||
}
|
||||
});
|
||||
};
|
||||
const handleSubtitleChange: ChangeEventHandler<
|
||||
HTMLInputElement | HTMLTextAreaElement
|
||||
> = useCallback(
|
||||
(e) => {
|
||||
startSubtitleChange(() => {
|
||||
if (mediaSource.subtitle.allTracks) {
|
||||
changeSubtitleTrack(
|
||||
toNumber(e.target.value),
|
||||
mediaSource.subtitle.allTracks,
|
||||
);
|
||||
console.log(mediaSource.subtitle);
|
||||
setSettingsMenu(null);
|
||||
}
|
||||
});
|
||||
},
|
||||
[mediaSource.subtitle.allTracks],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="video-player">
|
||||
@@ -687,6 +698,7 @@ function VideoPlayer() {
|
||||
: "video-player-osd"
|
||||
}
|
||||
onMouseMove={handleShowOsd}
|
||||
ref={playerOSDRef}
|
||||
initial={{
|
||||
opacity: 0,
|
||||
}}
|
||||
@@ -767,10 +779,10 @@ function VideoPlayer() {
|
||||
{(forceShowCredits || !showUpNextCard) && (
|
||||
<div className="video-player-osd-info">
|
||||
<Typography variant="h4" fontWeight={500} mb={2}>
|
||||
{itemName}
|
||||
{String(itemName)}
|
||||
{episodeTitle && (
|
||||
<Typography variant="h6" fontWeight={300} mt={1}>
|
||||
{episodeTitle}
|
||||
{String(episodeTitle)}
|
||||
</Typography>
|
||||
)}
|
||||
</Typography>
|
||||
|
||||
@@ -12,8 +12,6 @@ import { save } from "@tauri-apps/plugin-dialog";
|
||||
import "./photos.scss";
|
||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||
import {
|
||||
Button,
|
||||
CircularProgress,
|
||||
IconButton,
|
||||
ListItemIcon,
|
||||
ListItemText,
|
||||
@@ -48,12 +46,16 @@ function PhotosPlayer() {
|
||||
>
|
||||
<img
|
||||
src={
|
||||
item.Id
|
||||
? getImageUrlsApi(api).getItemImageUrlById(item.Id, "Primary", {
|
||||
// width: 250,
|
||||
fillWidth: 250,
|
||||
quality: 70,
|
||||
})
|
||||
api
|
||||
? getImageUrlsApi(api).getItemImageUrlById(
|
||||
item.Id ?? "",
|
||||
"Primary",
|
||||
{
|
||||
// width: 250,
|
||||
fillWidth: 250,
|
||||
quality: 70,
|
||||
},
|
||||
)
|
||||
: brokenImage
|
||||
}
|
||||
style={{
|
||||
@@ -103,7 +105,7 @@ function PhotosPlayer() {
|
||||
|
||||
if (pathToSave) {
|
||||
download(
|
||||
`${api.basePath}/Items/${currentPhoto?.Id}/Download?api_key=${api.accessToken}`,
|
||||
`${api?.basePath}/Items/${currentPhoto?.Id}/Download?api_key=${api?.accessToken}`,
|
||||
pathToSave,
|
||||
);
|
||||
enqueueSnackbar("Image download queued.", { variant: "info" });
|
||||
@@ -120,7 +122,7 @@ function PhotosPlayer() {
|
||||
key={currentPhoto?.Id ?? "noPhoto"}
|
||||
src={
|
||||
currentPhoto
|
||||
? `${api.basePath}/Items/${currentPhoto.Id}/Download?api_key=${api.accessToken}`
|
||||
? `${api?.basePath}/Items/${currentPhoto.Id}/Download?api_key=${api?.accessToken}`
|
||||
: brokenImage
|
||||
}
|
||||
alt="Item"
|
||||
|
||||
@@ -126,7 +126,7 @@ function SeriesTitlePage() {
|
||||
|
||||
const [currentSeason, setCurrentSeason] = useState(() => {
|
||||
const result = sessionStorage.getItem(`season-${item.data?.Id}`);
|
||||
return result ?? 0;
|
||||
return result ?? seasons.data?.Items?.[0].IndexNumber ?? 0;
|
||||
});
|
||||
|
||||
const currentSeasonItem = useQuery({
|
||||
|
||||
Reference in new issue
Block a user