Migrate react-query to v5
This commit is contained in:
21 files changed
+66
-86
No files matched your search
+9
-29
@@ -15,8 +15,6 @@ import {
|
||||
} from "react-router-dom";
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
|
||||
import { EventEmitter as event } from "./eventEmitter.js";
|
||||
|
||||
import { relaunch } from "@tauri-apps/api/process";
|
||||
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
@@ -96,13 +94,8 @@ import ArtistTitlePage from "./routes/artist/index.jsx";
|
||||
import EpisodeTitlePage from "./routes/episode/index.jsx";
|
||||
import PlaylistTitlePage from "./routes/playlist/index.jsx";
|
||||
|
||||
// Initial custom axios client to use tauri's http module
|
||||
import axios from "axios";
|
||||
import axiosTauriApiAdapter from "axios-tauri-api-adapter";
|
||||
import { createApi, useApi } from "./utils/store/api.js";
|
||||
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api.js";
|
||||
import { Navigate } from "react-router-dom";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { CircularProgress } from "@mui/material";
|
||||
|
||||
const anim = {
|
||||
@@ -149,9 +142,9 @@ const LogicalRoute = () => {
|
||||
return res;
|
||||
};
|
||||
if (
|
||||
!defaultServer.isLoading &&
|
||||
!server.isLoading &&
|
||||
!userSaved.isLoading
|
||||
!defaultServer.isPending &&
|
||||
!server.isPending &&
|
||||
!userSaved.isPending
|
||||
) {
|
||||
if (defaultServer.data) {
|
||||
if (userSaved.data) {
|
||||
@@ -237,21 +230,15 @@ const AnimationWrapper = () => {
|
||||
};
|
||||
|
||||
function App() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
/**
|
||||
* @type {[import("@jellyfin/sdk").Api, import("@jellyfin/sdk").Jellyfin]}
|
||||
* @type {[import("@jellyfin/sdk").Api]}
|
||||
*/
|
||||
const [api, jellyfin] = useApi((state) => [
|
||||
state.api,
|
||||
state.createApi,
|
||||
state.jellyfin,
|
||||
]);
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
|
||||
const [serverReachable, setServerReachable] = useState(true);
|
||||
const [serverReachable] = useState(true);
|
||||
|
||||
const [playbackDataLoading] = usePlaybackDataLoadStore((state) => [
|
||||
state.isLoading,
|
||||
state.isPending,
|
||||
]);
|
||||
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
@@ -265,11 +252,6 @@ function App() {
|
||||
}
|
||||
};
|
||||
|
||||
const LoginLogicalRoutes = () => {
|
||||
// usersAvailable();
|
||||
return <h1>/Login</h1>;
|
||||
};
|
||||
|
||||
const handleRelaunch = async (event, reason) => {
|
||||
if (reason && reason == "backdropClick") {
|
||||
return;
|
||||
@@ -307,9 +289,7 @@ function App() {
|
||||
console.log(location);
|
||||
}, [location.key]);
|
||||
|
||||
const [audioPlayerVisible, currentAudioIndex] = useAudioPlayback(
|
||||
(state) => [state.display, state.currentTrack],
|
||||
);
|
||||
const [audioPlayerVisible] = useAudioPlayback((state) => [state.display]);
|
||||
|
||||
const [backdropUrl, backdropId] = useBackdropStore((state) => [
|
||||
state.backdropUrl,
|
||||
|
||||
@@ -72,13 +72,13 @@ const LikeButton = ({
|
||||
>
|
||||
<CircularProgress
|
||||
style={{
|
||||
opacity: mutation.isLoading ? 1 : 0,
|
||||
opacity: mutation.isPending ? 1 : 0,
|
||||
transition: "opacity 200ms",
|
||||
}}
|
||||
/>
|
||||
<IconButton
|
||||
onClick={(e) => {
|
||||
if (!mutation.isLoading) {
|
||||
if (!mutation.isPending) {
|
||||
e.stopPropagation();
|
||||
mutation.mutate();
|
||||
}
|
||||
@@ -92,7 +92,7 @@ const LikeButton = ({
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
opacity: mutation.isLoading ? 0.5 : 1,
|
||||
opacity: mutation.isPending ? 0.5 : 1,
|
||||
}}
|
||||
>
|
||||
{isFavorite ? (
|
||||
|
||||
@@ -64,13 +64,13 @@ const MarkPlayedButton = ({ itemId, isPlayed, queryKey, userId, itemName }) => {
|
||||
>
|
||||
<CircularProgress
|
||||
style={{
|
||||
opacity: mutation.isLoading ? 1 : 0,
|
||||
opacity: mutation.isPending ? 1 : 0,
|
||||
transition: "opacity 200ms",
|
||||
}}
|
||||
/>
|
||||
<IconButton
|
||||
onClick={(e) => {
|
||||
if (!mutation.isLoading) {
|
||||
if (!mutation.isPending) {
|
||||
e.stopPropagation();
|
||||
mutation.mutate();
|
||||
}
|
||||
@@ -84,7 +84,7 @@ const MarkPlayedButton = ({ itemId, isPlayed, queryKey, userId, itemName }) => {
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
opacity: mutation.isLoading ? 0.5 : 1,
|
||||
opacity: mutation.isPending ? 0.5 : 1,
|
||||
}}
|
||||
>
|
||||
<MdiCheck
|
||||
|
||||
@@ -94,7 +94,7 @@ const PlayButton = ({
|
||||
state.setPlaylistItemId,
|
||||
]);
|
||||
const setPlaybackDataLoading = usePlaybackDataLoadStore(
|
||||
(state) => state.setIsLoading,
|
||||
(state) => state.setisPending,
|
||||
);
|
||||
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
@@ -38,7 +38,7 @@ export const LatestMediaSection = ({ latestMediaLib }) => {
|
||||
enabled: !!user.data,
|
||||
networkMode: "always",
|
||||
});
|
||||
if (data.isLoading) {
|
||||
if (data.isPending) {
|
||||
return <CardsSkeleton />;
|
||||
}
|
||||
if (data.isSuccess && data.data.length >= 1) {
|
||||
|
||||
@@ -140,7 +140,7 @@ export const SideMenu = () => {
|
||||
}}
|
||||
></DrawerHeader>
|
||||
<div className="sidemenu-item-container">
|
||||
{libraries.isLoading ? (
|
||||
{libraries.isPending ? (
|
||||
<></>
|
||||
) : (
|
||||
<>
|
||||
@@ -238,7 +238,7 @@ export const SideMenu = () => {
|
||||
</IconButton>
|
||||
</DrawerHeader>
|
||||
<Divider />
|
||||
{libraries.isLoading ? (
|
||||
{libraries.isPending ? (
|
||||
<>
|
||||
<Skeleton
|
||||
height="100%"
|
||||
|
||||
@@ -162,7 +162,7 @@ const MusicAlbumTitlePage = () => {
|
||||
}
|
||||
}, [item.isSuccess]);
|
||||
|
||||
if (item.isLoading || similarItems.isLoading) {
|
||||
if (item.isPending || similarItems.isPending) {
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
@@ -198,7 +198,7 @@ const MusicAlbumTitlePage = () => {
|
||||
audioPlayButton
|
||||
cardType="square"
|
||||
/>
|
||||
{musicTracks.isLoading ? (
|
||||
{musicTracks.isPending ? (
|
||||
<></>
|
||||
) : (
|
||||
musicTracks.data.TotalRecordCount > 0 && (
|
||||
|
||||
@@ -159,9 +159,9 @@ const ArtistTitlePage = () => {
|
||||
}
|
||||
}
|
||||
}, [
|
||||
artistDiscography.isLoading,
|
||||
artistSongs.isLoading,
|
||||
artistAppearances.isLoading,
|
||||
artistDiscography.isPending,
|
||||
artistSongs.isPending,
|
||||
artistAppearances.isPending,
|
||||
]);
|
||||
|
||||
const [animationDirection, setAnimationDirection] = useState("forward");
|
||||
@@ -180,7 +180,7 @@ const ArtistTitlePage = () => {
|
||||
}
|
||||
}, [item.isSuccess]);
|
||||
|
||||
if (item.isLoading) {
|
||||
if (item.isPending) {
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
|
||||
@@ -132,7 +132,7 @@ const BoxSetTitlePage = () => {
|
||||
}
|
||||
}, [item.isSuccess]);
|
||||
|
||||
if (item.isLoading || similarItems.isLoading) {
|
||||
if (item.isPending || similarItems.isPending) {
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
|
||||
@@ -158,7 +158,7 @@ const EpisodeTitlePage = () => {
|
||||
}
|
||||
}, [item.isSuccess]);
|
||||
|
||||
if (item.isLoading) {
|
||||
if (item.isPending) {
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
|
||||
@@ -177,7 +177,7 @@ const Home = () => {
|
||||
}}
|
||||
>
|
||||
<ErrorBoundary fallback={<CarouselSlideError />}>
|
||||
{latestMedia.isLoading ? (
|
||||
{latestMedia.isPending ? (
|
||||
<CarouselSkeleton />
|
||||
) : (
|
||||
<Carousel
|
||||
@@ -224,7 +224,7 @@ const Home = () => {
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{libraries.isLoading ? (
|
||||
{libraries.isPending ? (
|
||||
<CardsSkeleton />
|
||||
) : (
|
||||
<CardScroller
|
||||
@@ -279,7 +279,7 @@ const Home = () => {
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{upNextItems.isLoading ? (
|
||||
{upNextItems.isPending ? (
|
||||
<CardsSkeleton />
|
||||
) : upNextItems.isSuccess &&
|
||||
upNextItems.data.Items.length == 0 ? (
|
||||
@@ -373,7 +373,7 @@ const Home = () => {
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{resumeItemsVideo.isLoading ? (
|
||||
{resumeItemsVideo.isPending ? (
|
||||
<CardsSkeleton />
|
||||
) : resumeItemsVideo.isSuccess &&
|
||||
resumeItemsVideo.data.Items.length == 0 ? (
|
||||
@@ -468,7 +468,7 @@ const Home = () => {
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{resumeItemsAudio.isLoading ? (
|
||||
{resumeItemsAudio.isPending ? (
|
||||
<CardsSkeleton />
|
||||
) : resumeItemsAudio.isSuccess &&
|
||||
resumeItemsAudio.data.Items.length == 0 ? (
|
||||
|
||||
@@ -185,7 +185,7 @@ const ItemDetail = () => {
|
||||
}
|
||||
}, [item.isSuccess]);
|
||||
|
||||
if (item.isLoading || similarItems.isLoading) {
|
||||
if (item.isPending || similarItems.isPending) {
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
|
||||
@@ -375,7 +375,7 @@ const LibraryView = () => {
|
||||
sx={{ mr: 2, flexShrink: 0 }}
|
||||
noWrap
|
||||
>
|
||||
{currentLib.isLoading ? (
|
||||
{currentLib.isPending ? (
|
||||
<CircularProgress sx={{ p: 1 }} />
|
||||
) : (
|
||||
currentLib.data.Items[0].Name
|
||||
@@ -383,7 +383,7 @@ const LibraryView = () => {
|
||||
</Typography>
|
||||
<Chip
|
||||
label={
|
||||
items.isLoading ? (
|
||||
items.isPending ? (
|
||||
<CircularProgress sx={{ p: 1.5 }} />
|
||||
) : (
|
||||
items.data.TotalRecordCount
|
||||
@@ -1247,7 +1247,7 @@ const LibraryView = () => {
|
||||
</Popper>
|
||||
</div>
|
||||
</div>
|
||||
{items.isLoading ? (
|
||||
{items.isPending ? (
|
||||
<Box
|
||||
sx={{
|
||||
position: "absolute",
|
||||
|
||||
@@ -239,7 +239,7 @@ export const UserLogin = () => {
|
||||
enabled: Boolean(api),
|
||||
});
|
||||
|
||||
if (users.isLoading) {
|
||||
if (users.isPending) {
|
||||
return <LinearProgress />;
|
||||
}
|
||||
if (users.isSuccess) {
|
||||
@@ -407,7 +407,7 @@ export const UserLoginManual = () => {
|
||||
|
||||
return (
|
||||
<>
|
||||
{server.isLoading && <LinearProgress />}
|
||||
{server.isPending && <LinearProgress />}
|
||||
<AppBarBackOnly />
|
||||
<Container
|
||||
maxWidth="xs"
|
||||
@@ -425,7 +425,7 @@ export const UserLoginManual = () => {
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
sx={{
|
||||
opacity: server.isLoading ? 0 : 1,
|
||||
opacity: server.isPending ? 0 : 1,
|
||||
transition: "opacity 200ms",
|
||||
width: "100%",
|
||||
}}
|
||||
|
||||
@@ -228,11 +228,11 @@ const PersonTitlePage = () => {
|
||||
}
|
||||
}
|
||||
}, [
|
||||
personMovies.isLoading,
|
||||
personShows.isLoading,
|
||||
personBooks.isLoading,
|
||||
personPhotos.isLoading,
|
||||
personEpisodes.isLoading,
|
||||
personMovies.isPending,
|
||||
personShows.isPending,
|
||||
personBooks.isPending,
|
||||
personPhotos.isPending,
|
||||
personEpisodes.isPending,
|
||||
]);
|
||||
const [setAppBackdrop] = useBackdropStore((state) => [state.setBackdrop]);
|
||||
|
||||
@@ -250,7 +250,7 @@ const PersonTitlePage = () => {
|
||||
}
|
||||
}, [item.isSuccess]);
|
||||
|
||||
if (item.isLoading) {
|
||||
if (item.isPending) {
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
|
||||
@@ -734,7 +734,7 @@ export const VideoPlayer = () => {
|
||||
onClick={handlePlayPrevEpisode}
|
||||
disabled={
|
||||
seriesId
|
||||
? episodes.isLoading ||
|
||||
? episodes.isPending ||
|
||||
currentEpisodeIndex == 0
|
||||
: true
|
||||
}
|
||||
@@ -770,7 +770,7 @@ export const VideoPlayer = () => {
|
||||
onClick={handlePlayNextEpisode}
|
||||
disabled={
|
||||
seriesId
|
||||
? episodes.isLoading ||
|
||||
? episodes.isPending ||
|
||||
episodes.data
|
||||
?.TotalRecordCount ==
|
||||
currentEpisodeIndex +
|
||||
|
||||
@@ -125,7 +125,7 @@ const PlaylistTitlePage = () => {
|
||||
}
|
||||
}, [item.isSuccess]);
|
||||
|
||||
if (item.isLoading || similarItems.isLoading) {
|
||||
if (item.isPending || similarItems.isPending) {
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
@@ -160,7 +160,7 @@ const PlaylistTitlePage = () => {
|
||||
audioPlayButton
|
||||
cardType="square"
|
||||
/>
|
||||
{musicTracks.isLoading ? (
|
||||
{musicTracks.isPending ? (
|
||||
<></>
|
||||
) : (
|
||||
musicTracks.data.TotalRecordCount > 0 &&
|
||||
|
||||
@@ -198,13 +198,13 @@ const SearchPage = () => {
|
||||
Boolean(
|
||||
searchTerm,
|
||||
) &&
|
||||
(movies.isLoading ||
|
||||
series.isLoading ||
|
||||
audio.isLoading ||
|
||||
musicAlbum.isLoading ||
|
||||
musicArtists.isLoading ||
|
||||
person.isLoading ||
|
||||
book.isLoading)
|
||||
(movies.isPending ||
|
||||
series.isPending ||
|
||||
audio.isPending ||
|
||||
musicAlbum.isPending ||
|
||||
musicArtists.isPending ||
|
||||
person.isPending ||
|
||||
book.isPending)
|
||||
? 1
|
||||
: 0,
|
||||
}}
|
||||
|
||||
@@ -211,7 +211,7 @@ const SeriesTitlePage = () => {
|
||||
}
|
||||
}, [item.isSuccess]);
|
||||
|
||||
if (item.isLoading || similarItems.isLoading) {
|
||||
if (item.isPending || similarItems.isPending) {
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
@@ -285,7 +285,7 @@ const SeriesTitlePage = () => {
|
||||
</CardScroller>
|
||||
)}
|
||||
|
||||
{seasons.isLoading ? (
|
||||
{seasons.isPending ? (
|
||||
<SeasonSelectorSkeleton />
|
||||
) : (
|
||||
<div className="item-series-seasons-container">
|
||||
@@ -313,7 +313,7 @@ const SeriesTitlePage = () => {
|
||||
</Typography>
|
||||
<Chip
|
||||
label={
|
||||
episodes.isLoading ? (
|
||||
episodes.isPending ? (
|
||||
<CircularProgress
|
||||
size={20}
|
||||
style={{
|
||||
@@ -417,7 +417,7 @@ const SeriesTitlePage = () => {
|
||||
</div>
|
||||
<Divider />
|
||||
<div className="item-detail-episodes-container">
|
||||
{episodes.isLoading ? (
|
||||
{episodes.isPending ? (
|
||||
<EpisodeCardsSkeleton />
|
||||
) : (
|
||||
episodes.data.Items.map((episode) => {
|
||||
|
||||
@@ -88,7 +88,7 @@ export const ServerSetup = () => {
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
opacity: checkServer.isLoading ? 1 : 0,
|
||||
opacity: checkServer.isPending ? 1 : 0,
|
||||
transition: "opacity 350ms",
|
||||
}}
|
||||
/>
|
||||
@@ -96,7 +96,7 @@ export const ServerSetup = () => {
|
||||
maxWidth="sm"
|
||||
className={"centered serverContainer"}
|
||||
style={{
|
||||
opacity: checkServer.isLoading ? "0.5" : "1",
|
||||
opacity: checkServer.isPending ? "0.5" : "1",
|
||||
transition: "opacity 350ms",
|
||||
}}
|
||||
>
|
||||
@@ -126,7 +126,7 @@ export const ServerSetup = () => {
|
||||
variant="contained"
|
||||
sx={{ width: "100%" }}
|
||||
size="large"
|
||||
loading={checkServer.isLoading}
|
||||
loading={checkServer.isPending}
|
||||
endIcon={
|
||||
<SvgIcon>
|
||||
<path d={mdiChevronRight}></path>
|
||||
|
||||
@@ -49,10 +49,10 @@ export const usePlaybackStore = create((set) => ({
|
||||
}));
|
||||
|
||||
export const usePlaybackDataLoadStore = create((set) => ({
|
||||
isLoading: false,
|
||||
setIsLoading: (loading) =>
|
||||
isPending: false,
|
||||
setisPending: (loading) =>
|
||||
set((state) => ({
|
||||
...state,
|
||||
isLoading: loading,
|
||||
isPending: loading,
|
||||
})),
|
||||
}));
|
||||
Reference in new issue
Block a user