diff --git a/biome.json b/biome.json index 6daca8a..cabe0c7 100644 --- a/biome.json +++ b/biome.json @@ -1,5 +1,5 @@ { - "$schema": "https://biomejs.dev/schemas/1.8.0/schema.json", + "$schema": "https://biomejs.dev/schemas/1.9.2/schema.json", "organizeImports": { "enabled": true }, @@ -21,6 +21,9 @@ }, "suspicious": { "noExplicitAny": "off" + }, + "nursery": { + "useComponentExportOnlyModules": "error" } } }, diff --git a/src/components/appBar/appBar.tsx b/src/components/appBar/appBar.tsx index 41bd736..159a5e2 100644 --- a/src/components/appBar/appBar.tsx +++ b/src/components/appBar/appBar.tsx @@ -14,7 +14,12 @@ import Menu from "@mui/material/Menu"; import MenuItem from "@mui/material/MenuItem"; import useScrollTrigger from "@mui/material/useScrollTrigger"; -import { Link, useLocation, useNavigate } from "@tanstack/react-router"; +import { + Link, + useLocation, + useNavigate, + useRouter, +} from "@tanstack/react-router"; import { getUserViewsApi } from "@jellyfin/sdk/lib/utils/api/user-views-api"; @@ -79,14 +84,19 @@ const MemoizeBackButton = React.memo(BackButton); export const AppBar = () => { const api = useApiInContext((s) => s.api); + const createApi = useApiInContext((s) => s.createApi); const navigate = useNavigate(); const [display, setDisplay] = useState(false); const location = useLocation(); + const router = useRouter(); - const user = useCentralStore((s) => s.currentUser); + const [user, resetCurrentUser] = useCentralStore((s) => [ + s.currentUser, + s.resetCurrentUser, + ]); const libraries = useQuery({ queryKey: ["libraries"], queryFn: async () => { @@ -123,8 +133,12 @@ export const AppBar = () => { const handleLogout = async () => { console.log("Logging out user..."); await api?.logout(); + createApi(api?.basePath ?? "", undefined); + console.log(api); + resetCurrentUser(); delUser(); sessionStorage.removeItem("accessToken"); + await router.invalidate(); queryClient.clear(); setAnchorEl(null); navigate({ to: "/login" }); diff --git a/src/components/appBar/backOnly.tsx b/src/components/appBar/backOnly.tsx index a58aa27..edd69d3 100644 --- a/src/components/appBar/backOnly.tsx +++ b/src/components/appBar/backOnly.tsx @@ -5,7 +5,7 @@ import { useRouter } from "@tanstack/react-router"; import React from "react"; import QuickConnectButton from "../buttons/quickConnectButton"; -export const AppBarBackOnly = () => { +export default function AppBarBackOnly() { const { history } = useRouter(); const handleBack = () => { diff --git a/src/components/buttons/quickConnectButton.tsx b/src/components/buttons/quickConnectButton.tsx index 88f5886..9e87271 100644 --- a/src/components/buttons/quickConnectButton.tsx +++ b/src/components/buttons/quickConnectButton.tsx @@ -141,9 +141,11 @@ const QuickConnectButton = (props: LoadingButtonProps) => { }, }); + useInterval( () => { if (quickConnectSecret) { + console.log(checkForQuickConnect); checkQuickConnectStatus.mutate(quickConnectSecret); } }, @@ -175,6 +177,7 @@ const QuickConnectButton = (props: LoadingButtonProps) => { open={Boolean(quickConnectCode)} onClose={() => { setQuickConnectCode(null); + setCheckForQuickConnect(false); initQuickConnect.reset(); checkQuickConnectStatus.reset(); }} diff --git a/src/components/settingOption/index.tsx b/src/components/settingOption/index.tsx index f3f3dc7..87c75c6 100644 --- a/src/components/settingOption/index.tsx +++ b/src/components/settingOption/index.tsx @@ -1,23 +1,30 @@ import { getSetting, setSetting } from "@/utils/storage/settings"; import { FormControlLabel, Switch, Typography } from "@mui/material"; +import { useQuery } from "@tanstack/react-query"; import React, { useState } from "react"; const SettingOption = ({ setting, }: { setting: { key: string; name: string; description: string } }) => { - const [settingVal, setSettingVal] = useState( - async () => (await getSetting(setting.key)) ?? false, - ); + const initValue = useQuery({ + queryKey: ["setting", setting.key], + queryFn: async () => { + const result = await getSetting(setting.key); + return Boolean(result); + }, + }); + const [settingVal, setSettingVal] = useState(initValue.data ?? false); return ( { - setSetting(setting.key, e.target.checked); - setSettingVal(e.target.checked); + checked={Boolean(settingVal)} + onChange={(_, checked) => { + setSetting(setting.key, checked); + setSettingVal(Boolean(checked)); }} + disabled={initValue.isLoading} name={setting.name} /> } diff --git a/src/main.tsx b/src/main.tsx index 6027cec..2eda81b 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -49,6 +49,7 @@ export const queryClient = new QueryClient({ }, }); +// biome-ignore lint/nursery/useComponentExportOnlyModules : This is a valid use case for a component export function ProviderWrapper() { const [api, createApi, jellyfinSDK] = useApiInContext((s) => [ s.api, diff --git a/src/routes/_api.tsx b/src/routes/_api.tsx index 5364609..c38037d 100644 --- a/src/routes/_api.tsx +++ b/src/routes/_api.tsx @@ -59,6 +59,7 @@ export const Route = createFileRoute("/_api")({ } else if (context.api) { if (context.api.accessToken && location.pathname !== "/login/manual") { try { + console.info("AccessToken", context.api.accessToken); await getUserApi(context.api).getCurrentUser(); // Verify user is able to authenticate } catch (error) { console.error(error); diff --git a/src/routes/_api/login.tsx b/src/routes/_api/login.tsx index c0db892..89d92d9 100644 --- a/src/routes/_api/login.tsx +++ b/src/routes/_api/login.tsx @@ -1,4 +1,4 @@ -import { AppBarBackOnly } from "@/components/appBar/backOnly"; +import AppBarBackOnly from "@/components/appBar/backOnly"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; import { Outlet, createFileRoute, redirect } from "@tanstack/react-router"; import React from "react"; diff --git a/src/routes/_api/login/$userId.$userName.tsx b/src/routes/_api/login/$userId.$userName.tsx index b5105e7..e7d8b7e 100644 --- a/src/routes/_api/login/$userId.$userName.tsx +++ b/src/routes/_api/login/$userId.$userName.tsx @@ -134,25 +134,20 @@ function LoginUser() { }} > - - Login as{" "} +
+ Login as {userName} - +
handleLogin.mutate(e)}> void, delay: number) { - const savedCallback = useRef void)>(null); +export default function useInterval( + callback: () => void, + delay: number | null, +) { + const savedCallback = useRef(callback); - // Remember the latest callback. + // Remember the latest callback if it changes. useEffect(() => { - if (savedCallback.current) { - savedCallback.current = callback; - } + savedCallback.current = callback; }, [callback]); // Set up the interval. useEffect(() => { - function tick() { - if (savedCallback.current) { - savedCallback.current(); - } + // Don't schedule if no delay is specified. + // Note: 0 is a valid value for delay. + if (delay === null) { + return; } - if (delay !== null) { - const id = setInterval(tick, delay); - return () => clearInterval(id); - } - }, [delay]); -} -export default useInterval; \ No newline at end of file + const id = setInterval(() => { + savedCallback.current(); + }, delay); + + return () => { + clearInterval(id); + }; + }, [delay]); +} \ No newline at end of file diff --git a/src/utils/store/central.tsx b/src/utils/store/central.tsx index 3770927..b3ad7f0 100644 --- a/src/utils/store/central.tsx +++ b/src/utils/store/central.tsx @@ -26,6 +26,7 @@ type CentralStore = { clientVersion: string; currentUser: null | UserDto; fetchCurrentUser: (api: Api | undefined) => Promise; + resetCurrentUser: () => void; }; /** @@ -58,11 +59,14 @@ export const CentralProvider = ({ children }: { children: ReactNode }) => { clientVersion: version, currentUser: null, fetchCurrentUser: async (api) => { - if (api) { + if (api?.accessToken) { const user = (await getUserApi(api).getCurrentUser()).data; set((s) => ({ ...s, currentUser: user })); } }, + resetCurrentUser: () => { + set((s) => ({ ...s, currentUser: null })); + }, })), ); return (