refactor: move to tanstack router
This commit is contained in:
1 parent
a4ea932153
commit
522621ed69
136 files changed
+7063
-6127
No files matched your search
@@ -1,33 +1,33 @@
|
||||
import React, { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
import { setDefaultServer, setServer } from "../../../utils/storage/servers";
|
||||
import { setDefaultServer, setServer } from "@/utils/storage/servers";
|
||||
|
||||
import LoadingButton from "@mui/lab/LoadingButton";
|
||||
import Container from "@mui/material/Container";
|
||||
import Grid from "@mui/material/Grid";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
import SvgIcon from "@mui/material/SvgIcon";
|
||||
// MUI
|
||||
import TextField from "@mui/material/TextField";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
import { useSnackbar } from "notistack";
|
||||
|
||||
import { createApi, jellyfin } from "@/utils/store/api";
|
||||
import { yellow } from "@mui/material/colors";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { createApi, useApi } from "../../../utils/store/api";
|
||||
// SCSS
|
||||
import "./server.scss";
|
||||
import { createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
|
||||
export const ServerSetup = () => {
|
||||
const [jellyfin] = useApi((state) => [state.jellyfin]);
|
||||
export const Route = createFileRoute("/setup/server/add")({
|
||||
component: ServerSetup,
|
||||
});
|
||||
|
||||
function ServerSetup() {
|
||||
const [serverIp, setServerIp] = useState("");
|
||||
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
const navigate = useNavigate();
|
||||
const navigate = useNavigate({ from: "/setup/server/add" });
|
||||
|
||||
const checkServer = useMutation({
|
||||
mutationFn: async () => {
|
||||
@@ -40,14 +40,14 @@ export const ServerSetup = () => {
|
||||
if (bestServer) {
|
||||
createApi(bestServer.address, undefined);
|
||||
|
||||
setDefaultServer(bestServer.systemInfo.Id);
|
||||
setServer(bestServer.systemInfo.Id, bestServer);
|
||||
setDefaultServer(bestServer.systemInfo?.Id);
|
||||
setServer(bestServer.systemInfo?.Id, bestServer);
|
||||
|
||||
enqueueSnackbar("Client added successfully", {
|
||||
variant: "success",
|
||||
});
|
||||
|
||||
navigate("/login/index");
|
||||
navigate({ to: "/login/index" });
|
||||
}
|
||||
},
|
||||
onError: (err) => {
|
||||
@@ -149,4 +149,4 @@ export const ServerSetup = () => {
|
||||
</Container>
|
||||
</>
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -1,29 +1,31 @@
|
||||
import React, { useLayoutEffect, useState } from "react";
|
||||
|
||||
import { relaunch } from "@tauri-apps/api/process";
|
||||
|
||||
import Chip from "@mui/material/Chip";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import Paper from "@mui/material/Paper";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { red } from "@mui/material/colors";
|
||||
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { AppBarBackOnly } from "../../../components/appBar/backOnly";
|
||||
import { AppBarBackOnly } from "@/components/appBar/backOnly";
|
||||
import {
|
||||
delServer,
|
||||
getAllServers,
|
||||
getDefaultServer,
|
||||
setDefaultServer,
|
||||
} from "../../../utils/storage/servers";
|
||||
import { delUser } from "../../../utils/storage/user";
|
||||
import { createApi, useApi } from "../../../utils/store/api";
|
||||
import { setBackdrop } from "../../../utils/store/backdrop";
|
||||
} from "@/utils/storage/servers";
|
||||
import { delUser } from "@/utils/storage/user";
|
||||
import { createApi } from "@/utils/store/api";
|
||||
import { setBackdrop } from "@/utils/store/backdrop";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
import { useSnackbar } from "notistack";
|
||||
import "./serverList.scss";
|
||||
|
||||
const ServerList = () => {
|
||||
export const Route = createFileRoute("/setup/server/list")({
|
||||
component: ServerList,
|
||||
});
|
||||
|
||||
function ServerList() {
|
||||
const navigate = useNavigate();
|
||||
const [serverState, setServerState] = useState(null);
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
@@ -46,11 +48,11 @@ const ServerList = () => {
|
||||
await setDefaultServer(serverState.id);
|
||||
queryClient.clear();
|
||||
await defaultServer.refetch();
|
||||
createApi(serverState.address);
|
||||
createApi(serverState.address, undefined);
|
||||
queryClient.removeQueries();
|
||||
},
|
||||
onSuccess: async () => {
|
||||
navigate("/login/index");
|
||||
navigate({ to: "/login/index" });
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error(error);
|
||||
@@ -69,12 +71,12 @@ const ServerList = () => {
|
||||
|
||||
if (servers.length > 0) {
|
||||
setDefaultServer(servers[0].id);
|
||||
createApi(servers[0].address);
|
||||
createApi(servers[0].address, undefined);
|
||||
} else {
|
||||
useApi.setState(useApi.getInitialState());
|
||||
// TODO: reset api in context here
|
||||
}
|
||||
queryClient.removeQueries();
|
||||
navigate("/");
|
||||
navigate({ to: "/" });
|
||||
}
|
||||
enqueueSnackbar("Server deleted successfully!", { variant: "success" });
|
||||
|
||||
@@ -105,7 +107,7 @@ const ServerList = () => {
|
||||
style={{
|
||||
fontSize: "1.64em",
|
||||
}}
|
||||
onClick={() => navigate("/setup/server")}
|
||||
onClick={() => navigate({ to: "/setup/server" })}
|
||||
>
|
||||
<div className="material-symbols-rounded">add</div>
|
||||
</IconButton>
|
||||
@@ -198,5 +200,5 @@ const ServerList = () => {
|
||||
</Paper>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
}
|
||||
export default ServerList;
|
||||
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user