refactor: cleanup some components
This commit is contained in:
12 files changed
+70
-39
No files matched your search
+4
-1
@@ -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": {
|
"organizeImports": {
|
||||||
"enabled": true
|
"enabled": true
|
||||||
},
|
},
|
||||||
@@ -21,6 +21,9 @@
|
|||||||
},
|
},
|
||||||
"suspicious": {
|
"suspicious": {
|
||||||
"noExplicitAny": "off"
|
"noExplicitAny": "off"
|
||||||
|
},
|
||||||
|
"nursery": {
|
||||||
|
"useComponentExportOnlyModules": "error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -14,7 +14,12 @@ import Menu from "@mui/material/Menu";
|
|||||||
import MenuItem from "@mui/material/MenuItem";
|
import MenuItem from "@mui/material/MenuItem";
|
||||||
import useScrollTrigger from "@mui/material/useScrollTrigger";
|
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";
|
import { getUserViewsApi } from "@jellyfin/sdk/lib/utils/api/user-views-api";
|
||||||
|
|
||||||
@@ -79,14 +84,19 @@ const MemoizeBackButton = React.memo(BackButton);
|
|||||||
|
|
||||||
export const AppBar = () => {
|
export const AppBar = () => {
|
||||||
const api = useApiInContext((s) => s.api);
|
const api = useApiInContext((s) => s.api);
|
||||||
|
const createApi = useApiInContext((s) => s.createApi);
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const [display, setDisplay] = useState(false);
|
const [display, setDisplay] = useState(false);
|
||||||
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
const user = useCentralStore((s) => s.currentUser);
|
const [user, resetCurrentUser] = useCentralStore((s) => [
|
||||||
|
s.currentUser,
|
||||||
|
s.resetCurrentUser,
|
||||||
|
]);
|
||||||
const libraries = useQuery({
|
const libraries = useQuery({
|
||||||
queryKey: ["libraries"],
|
queryKey: ["libraries"],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
@@ -123,8 +133,12 @@ export const AppBar = () => {
|
|||||||
const handleLogout = async () => {
|
const handleLogout = async () => {
|
||||||
console.log("Logging out user...");
|
console.log("Logging out user...");
|
||||||
await api?.logout();
|
await api?.logout();
|
||||||
|
createApi(api?.basePath ?? "", undefined);
|
||||||
|
console.log(api);
|
||||||
|
resetCurrentUser();
|
||||||
delUser();
|
delUser();
|
||||||
sessionStorage.removeItem("accessToken");
|
sessionStorage.removeItem("accessToken");
|
||||||
|
await router.invalidate();
|
||||||
queryClient.clear();
|
queryClient.clear();
|
||||||
setAnchorEl(null);
|
setAnchorEl(null);
|
||||||
navigate({ to: "/login" });
|
navigate({ to: "/login" });
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { useRouter } from "@tanstack/react-router";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import QuickConnectButton from "../buttons/quickConnectButton";
|
import QuickConnectButton from "../buttons/quickConnectButton";
|
||||||
|
|
||||||
export const AppBarBackOnly = () => {
|
export default function AppBarBackOnly() {
|
||||||
const { history } = useRouter();
|
const { history } = useRouter();
|
||||||
|
|
||||||
const handleBack = () => {
|
const handleBack = () => {
|
||||||
|
|||||||
@@ -141,9 +141,11 @@ const QuickConnectButton = (props: LoadingButtonProps) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
useInterval(
|
useInterval(
|
||||||
() => {
|
() => {
|
||||||
if (quickConnectSecret) {
|
if (quickConnectSecret) {
|
||||||
|
console.log(checkForQuickConnect);
|
||||||
checkQuickConnectStatus.mutate(quickConnectSecret);
|
checkQuickConnectStatus.mutate(quickConnectSecret);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -175,6 +177,7 @@ const QuickConnectButton = (props: LoadingButtonProps) => {
|
|||||||
open={Boolean(quickConnectCode)}
|
open={Boolean(quickConnectCode)}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setQuickConnectCode(null);
|
setQuickConnectCode(null);
|
||||||
|
setCheckForQuickConnect(false);
|
||||||
initQuickConnect.reset();
|
initQuickConnect.reset();
|
||||||
checkQuickConnectStatus.reset();
|
checkQuickConnectStatus.reset();
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -1,23 +1,30 @@
|
|||||||
import { getSetting, setSetting } from "@/utils/storage/settings";
|
import { getSetting, setSetting } from "@/utils/storage/settings";
|
||||||
import { FormControlLabel, Switch, Typography } from "@mui/material";
|
import { FormControlLabel, Switch, Typography } from "@mui/material";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
|
|
||||||
const SettingOption = ({
|
const SettingOption = ({
|
||||||
setting,
|
setting,
|
||||||
}: { setting: { key: string; name: string; description: string } }) => {
|
}: { setting: { key: string; name: string; description: string } }) => {
|
||||||
const [settingVal, setSettingVal] = useState(
|
const initValue = useQuery({
|
||||||
async () => (await getSetting(setting.key)) ?? false,
|
queryKey: ["setting", setting.key],
|
||||||
);
|
queryFn: async () => {
|
||||||
|
const result = await getSetting(setting.key);
|
||||||
|
return Boolean(result);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const [settingVal, setSettingVal] = useState(initValue.data ?? false);
|
||||||
return (
|
return (
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={
|
control={
|
||||||
<Switch
|
<Switch
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={settingVal}
|
checked={Boolean(settingVal)}
|
||||||
onChange={(e) => {
|
onChange={(_, checked) => {
|
||||||
setSetting(setting.key, e.target.checked);
|
setSetting(setting.key, checked);
|
||||||
setSettingVal(e.target.checked);
|
setSettingVal(Boolean(checked));
|
||||||
}}
|
}}
|
||||||
|
disabled={initValue.isLoading}
|
||||||
name={setting.name}
|
name={setting.name}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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() {
|
function ProviderWrapper() {
|
||||||
const [api, createApi, jellyfinSDK] = useApiInContext((s) => [
|
const [api, createApi, jellyfinSDK] = useApiInContext((s) => [
|
||||||
s.api,
|
s.api,
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ export const Route = createFileRoute("/_api")({
|
|||||||
} else if (context.api) {
|
} else if (context.api) {
|
||||||
if (context.api.accessToken && location.pathname !== "/login/manual") {
|
if (context.api.accessToken && location.pathname !== "/login/manual") {
|
||||||
try {
|
try {
|
||||||
|
console.info("AccessToken", context.api.accessToken);
|
||||||
await getUserApi(context.api).getCurrentUser(); // Verify user is able to authenticate
|
await getUserApi(context.api).getCurrentUser(); // Verify user is able to authenticate
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
@@ -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 { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||||
import { Outlet, createFileRoute, redirect } from "@tanstack/react-router";
|
import { Outlet, createFileRoute, redirect } from "@tanstack/react-router";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|||||||
@@ -134,25 +134,20 @@ function LoginUser() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<AvatarImage userId={userId} />
|
<AvatarImage userId={userId} />
|
||||||
<Typography
|
<div style={{ display: "inline-flex", margin: "1em 0" }}>
|
||||||
textAlign="center"
|
<Typography variant="h5">Login as</Typography>
|
||||||
variant="h5"
|
|
||||||
sx={{ opacity: 0.8 }}
|
|
||||||
mb={2}
|
|
||||||
mt={2}
|
|
||||||
>
|
|
||||||
Login as{" "}
|
|
||||||
<Typography
|
<Typography
|
||||||
variant="h5"
|
variant="h5"
|
||||||
style={{
|
style={{
|
||||||
display: "inline",
|
display: "inline",
|
||||||
}}
|
}}
|
||||||
|
ml={0.5}
|
||||||
fontWeight={700}
|
fontWeight={700}
|
||||||
className="gradient-text"
|
className="gradient-text"
|
||||||
>
|
>
|
||||||
{userName}
|
{userName}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Typography>
|
</div>
|
||||||
<form onSubmit={(e) => handleLogin.mutate(e)}>
|
<form onSubmit={(e) => handleLogin.mutate(e)}>
|
||||||
<FormControl
|
<FormControl
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import Paper from "@mui/material/Paper";
|
|||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import { red } from "@mui/material/colors";
|
import { red } from "@mui/material/colors";
|
||||||
|
|
||||||
import { AppBarBackOnly } from "@/components/appBar/backOnly";
|
import AppBarBackOnly from "@/components/appBar/backOnly";
|
||||||
import {
|
import {
|
||||||
delServer,
|
delServer,
|
||||||
getAllServers,
|
getAllServers,
|
||||||
|
|||||||
@@ -1,27 +1,30 @@
|
|||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
|
|
||||||
function useInterval(callback: () => void, delay: number) {
|
export default function useInterval(
|
||||||
const savedCallback = useRef<null | (() => void)>(null);
|
callback: () => void,
|
||||||
|
delay: number | null,
|
||||||
|
) {
|
||||||
|
const savedCallback = useRef(callback);
|
||||||
|
|
||||||
// Remember the latest callback.
|
// Remember the latest callback if it changes.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (savedCallback.current) {
|
|
||||||
savedCallback.current = callback;
|
savedCallback.current = callback;
|
||||||
}
|
|
||||||
}, [callback]);
|
}, [callback]);
|
||||||
|
|
||||||
// Set up the interval.
|
// Set up the interval.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function tick() {
|
// Don't schedule if no delay is specified.
|
||||||
if (savedCallback.current) {
|
// Note: 0 is a valid value for delay.
|
||||||
savedCallback.current();
|
if (delay === null) {
|
||||||
}
|
return;
|
||||||
}
|
|
||||||
if (delay !== null) {
|
|
||||||
const id = setInterval(tick, delay);
|
|
||||||
return () => clearInterval(id);
|
|
||||||
}
|
|
||||||
}, [delay]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default useInterval;
|
const id = setInterval(() => {
|
||||||
|
savedCallback.current();
|
||||||
|
}, delay);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearInterval(id);
|
||||||
|
};
|
||||||
|
}, [delay]);
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ type CentralStore = {
|
|||||||
clientVersion: string;
|
clientVersion: string;
|
||||||
currentUser: null | UserDto;
|
currentUser: null | UserDto;
|
||||||
fetchCurrentUser: (api: Api | undefined) => Promise<void>;
|
fetchCurrentUser: (api: Api | undefined) => Promise<void>;
|
||||||
|
resetCurrentUser: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,11 +59,14 @@ export const CentralProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
clientVersion: version,
|
clientVersion: version,
|
||||||
currentUser: null,
|
currentUser: null,
|
||||||
fetchCurrentUser: async (api) => {
|
fetchCurrentUser: async (api) => {
|
||||||
if (api) {
|
if (api?.accessToken) {
|
||||||
const user = (await getUserApi(api).getCurrentUser()).data;
|
const user = (await getUserApi(api).getCurrentUser()).data;
|
||||||
set((s) => ({ ...s, currentUser: user }));
|
set((s) => ({ ...s, currentUser: user }));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
resetCurrentUser: () => {
|
||||||
|
set((s) => ({ ...s, currentUser: null }));
|
||||||
|
},
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in new issue
Block a user