refactor: cleanup some components
This commit is contained in:
12 files changed
+71
-40
No files matched your search
@@ -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" });
|
||||
|
||||
@@ -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 = () => {
|
||||
|
||||
@@ -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();
|
||||
}}
|
||||
|
||||
@@ -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 (
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
color="primary"
|
||||
checked={settingVal}
|
||||
onChange={(e) => {
|
||||
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}
|
||||
/>
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user