Merge pull request #248 from dan-online/fix/queries
fix(queries): staleTime and invalidating cache
This commit is contained in:
5 files changed
+122
-91
No files matched your search
@@ -18,6 +18,12 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
transition: opacity 0.25s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-loading.hidden {
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.app-loading-logo {
|
.app-loading-logo {
|
||||||
|
|||||||
+109
-1
@@ -95,16 +95,27 @@ import AudioPlayer from "./components/playback/audioPlayer/index.jsx";
|
|||||||
// Utils
|
// Utils
|
||||||
import { useAudioPlayback } from "./utils/store/audioPlayback.js";
|
import { useAudioPlayback } from "./utils/store/audioPlayback.js";
|
||||||
import { useBackdropStore } from "./utils/store/backdrop.js";
|
import { useBackdropStore } from "./utils/store/backdrop.js";
|
||||||
import { useCentralStore } from "./utils/store/central.js";
|
import { setInitialRoute, useCentralStore } from "./utils/store/central.js";
|
||||||
import { usePlaybackDataLoadStore } from "./utils/store/playback";
|
import { usePlaybackDataLoadStore } from "./utils/store/playback";
|
||||||
|
|
||||||
// 3rd Party
|
// 3rd Party
|
||||||
|
import { Api } from "@jellyfin/sdk";
|
||||||
|
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||||
import { CircularProgress } from "@mui/material";
|
import { CircularProgress } from "@mui/material";
|
||||||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
||||||
import { useSnackbar } from "notistack";
|
import { useSnackbar } from "notistack";
|
||||||
import { ErrorBoundary } from "react-error-boundary";
|
import { ErrorBoundary } from "react-error-boundary";
|
||||||
import { EasterEgg } from "./components/utils/easterEgg.jsx";
|
import { EasterEgg } from "./components/utils/easterEgg.jsx";
|
||||||
import { handleRelaunch } from "./utils/misc/relaunch";
|
import { handleRelaunch } from "./utils/misc/relaunch";
|
||||||
|
import {
|
||||||
|
delServer,
|
||||||
|
getAllServers,
|
||||||
|
getDefaultServer,
|
||||||
|
getServer,
|
||||||
|
setDefaultServer,
|
||||||
|
} from "./utils/storage/servers";
|
||||||
|
import { UserStore, delUser, getUser } from "./utils/storage/user";
|
||||||
|
import { createApi, useApi } from "./utils/store/api";
|
||||||
|
|
||||||
// const anim = {
|
// const anim = {
|
||||||
// initial: {
|
// initial: {
|
||||||
@@ -138,7 +149,104 @@ import { handleRelaunch } from "./utils/misc/relaunch";
|
|||||||
// );
|
// );
|
||||||
// };
|
// };
|
||||||
|
|
||||||
|
const handleAuthError = async () => {
|
||||||
|
await delUser();
|
||||||
|
setInitialRoute("/login/index");
|
||||||
|
};
|
||||||
|
|
||||||
|
const authenticateUser = async (address: string, user: UserStore["user"]) => {
|
||||||
|
try {
|
||||||
|
createApi(address, user.AccessToken);
|
||||||
|
setInitialRoute("/home");
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
setInitialRoute("/error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const init = async () => {
|
||||||
|
if (window.location.pathname !== "/") {
|
||||||
|
window.location.href = "/";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultServerOnDisk = await getDefaultServer();
|
||||||
|
|
||||||
|
if (defaultServerOnDisk) {
|
||||||
|
const defaultServerInfo = await getServer(defaultServerOnDisk);
|
||||||
|
if (!defaultServerInfo) {
|
||||||
|
await setDefaultServer(null);
|
||||||
|
await delServer(defaultServerOnDisk);
|
||||||
|
|
||||||
|
const servers = await getAllServers();
|
||||||
|
|
||||||
|
setInitialRoute(servers.length > 0 ? "/servers/list" : "/setup/server");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const userOnDisk = await getUser();
|
||||||
|
createApi(defaultServerInfo.address, "");
|
||||||
|
|
||||||
|
if (userOnDisk) {
|
||||||
|
try {
|
||||||
|
let authApi = useApi.getState().api;
|
||||||
|
|
||||||
|
if (!authApi) {
|
||||||
|
handleAuthError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await authenticateUser(defaultServerInfo.address, userOnDisk);
|
||||||
|
|
||||||
|
authApi = useApi.getState().api!;
|
||||||
|
|
||||||
|
const user = await getUserApi(authApi).getCurrentUser();
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
await delUser();
|
||||||
|
handleAuthError();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
handleAuthError();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setInitialRoute("/login/index");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setInitialRoute("/setup/server");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
const [appReady, setAppReady] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
init().then(() => {
|
||||||
|
setAppReady(true);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (!appReady) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: "fixed",
|
||||||
|
top: "50%",
|
||||||
|
left: "50%",
|
||||||
|
transform: "translate(-50%, -50%)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CircularProgress size={72} thickness={1.4} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return <AppReady />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function AppReady() {
|
||||||
const [audioPlayerVisible] = useAudioPlayback((state) => [state.display]);
|
const [audioPlayerVisible] = useAudioPlayback((state) => [state.display]);
|
||||||
const { enqueueSnackbar } = useSnackbar();
|
const { enqueueSnackbar } = useSnackbar();
|
||||||
|
|
||||||
|
|||||||
+5
-88
@@ -1,25 +1,16 @@
|
|||||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
|
||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import ReactDOM from "react-dom/client";
|
import ReactDOM from "react-dom/client";
|
||||||
import { BrowserRouter as Router } from "react-router-dom";
|
import { BrowserRouter as Router } from "react-router-dom";
|
||||||
|
|
||||||
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
|
|
||||||
import App from "./App";
|
import App from "./App";
|
||||||
import {
|
|
||||||
delServer,
|
|
||||||
getAllServers,
|
|
||||||
getDefaultServer,
|
|
||||||
getServer,
|
|
||||||
setDefaultServer,
|
|
||||||
} from "./utils/storage/servers";
|
|
||||||
import { UserStore, delUser, getUser } from "./utils/storage/user";
|
|
||||||
import { createApi, useApi } from "./utils/store/api";
|
|
||||||
import { setInitialRoute } from "./utils/store/central";
|
|
||||||
|
|
||||||
const queryClient = new QueryClient({
|
const queryClient = new QueryClient({
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
queries: {
|
queries: {
|
||||||
networkMode: "always",
|
networkMode: "always",
|
||||||
gcTime: 120000,
|
staleTime: 2 * 60 * 1000, // 2 minutes
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
networkMode: "always",
|
networkMode: "always",
|
||||||
@@ -27,79 +18,6 @@ const queryClient = new QueryClient({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleAuthError = async () => {
|
|
||||||
await delUser();
|
|
||||||
setInitialRoute("/login/index");
|
|
||||||
};
|
|
||||||
|
|
||||||
const authenticateUser = async (address: string, user: UserStore["user"]) => {
|
|
||||||
try {
|
|
||||||
createApi(address, user.AccessToken);
|
|
||||||
|
|
||||||
setInitialRoute("/home");
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
setInitialRoute("/error");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const init = async () => {
|
|
||||||
if (window.location.pathname !== "/") {
|
|
||||||
window.location.href = "/";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const defaultServerOnDisk = await getDefaultServer();
|
|
||||||
console.log(defaultServerOnDisk);
|
|
||||||
|
|
||||||
if (defaultServerOnDisk) {
|
|
||||||
const defaultServerInfo = await getServer(defaultServerOnDisk);
|
|
||||||
if (!defaultServerInfo) {
|
|
||||||
await setDefaultServer(null);
|
|
||||||
await delServer(defaultServerOnDisk);
|
|
||||||
|
|
||||||
const servers = await getAllServers();
|
|
||||||
|
|
||||||
setInitialRoute(servers.length > 0 ? "/servers/list" : "/setup/server");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const userOnDisk = await getUser();
|
|
||||||
createApi(defaultServerInfo.address, "");
|
|
||||||
|
|
||||||
if (userOnDisk) {
|
|
||||||
try {
|
|
||||||
let authApi = useApi.getState().api;
|
|
||||||
|
|
||||||
if (!authApi) {
|
|
||||||
handleAuthError();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await authenticateUser(defaultServerInfo.address, userOnDisk);
|
|
||||||
|
|
||||||
authApi = useApi.getState().api!;
|
|
||||||
|
|
||||||
const user = await getUserApi(authApi).getCurrentUser();
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
await delUser();
|
|
||||||
handleAuthError();
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
handleAuthError();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setInitialRoute("/login/index");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setInitialRoute("/setup/server");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
init().then(() => {
|
|
||||||
ReactDOM.createRoot(document.getElementById("root")!).render(
|
ReactDOM.createRoot(document.getElementById("root")!).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
@@ -110,5 +28,4 @@ init().then(() => {
|
|||||||
</React.StrictMode>,
|
</React.StrictMode>,
|
||||||
);
|
);
|
||||||
|
|
||||||
document.querySelector(".app-loading")!.setAttribute("style", "display:none");
|
document.querySelector(".app-loading")!.classList.toggle("hidden");
|
||||||
});
|
|
||||||
@@ -96,7 +96,7 @@ const LibraryView = () => {
|
|||||||
},
|
},
|
||||||
enabled: !!user.data,
|
enabled: !!user.data,
|
||||||
networkMode: "always",
|
networkMode: "always",
|
||||||
gcTime: 0,
|
staleTime: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [isPlayed, setIsPlayed] = useState(false);
|
const [isPlayed, setIsPlayed] = useState(false);
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ export const UserLogin = () => {
|
|||||||
const users = await getUserApi(api).getPublicUsers();
|
const users = await getUserApi(api).getPublicUsers();
|
||||||
return users.data;
|
return users.data;
|
||||||
},
|
},
|
||||||
gcTime: 0,
|
staleTime: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleInitiateQuickConnect = useMutation({
|
const handleInitiateQuickConnect = useMutation({
|
||||||
|
|||||||
Reference in new issue
Block a user