refactor: move most routing logic to tanstack

This commit is contained in:
Prayag Prajapati committed 2024-05-29 18:10:22 +05:30
1 parent b8552ac35d
commit c22dbefeea
22 files changed
+1191 -1502

No files matched your search

+3
View File
@@ -22,6 +22,7 @@ import {
import { useIsFetching, useIsMutating } from "@tanstack/react-query";
import {
Outlet,
ScrollRestoration,
createRootRoute,
createRootRouteWithContext,
useNavigate,
@@ -64,6 +65,7 @@ export const Route = createRootRouteWithContext<ApiContext>()({
console.error(error.error);
},
component: () => {
"use memo";
const isQueryFetching = useIsFetching();
const isMutating = useIsMutating();
const routeIsLoading = useRouterState().isLoading;
@@ -107,6 +109,7 @@ export const Route = createRootRouteWithContext<ApiContext>()({
<ThemeProvider theme={theme}>
<SnackbarProvider maxSnack={5}>
<CssBaseline />
<ScrollRestoration />
<Settings />
<EasterEgg />
<NProgress
+13 -12
View File
@@ -29,22 +29,23 @@ export const Route = createFileRoute("/_api")({
try {
await getSystemApi(context.api).getPingSystem(); // Verify server status
} catch (error) {
console.error(error);
throw redirect({
to: "/setup/server/error",
search: {
redirect: location.href,
},
});
}
try {
await getUserApi(context.api).getCurrentUser(); // Verify user is able to authenticate
} catch (error) {
throw redirect({
to: "/login/manual",
search: {
redirect: location.href,
},
});
if (context.api.accessToken) {
try {
await getUserApi(context.api).getCurrentUser(); // Verify user is able to authenticate
} catch (error) {
console.error(error);
throw redirect({
to: "/login/manual",
search: {
redirect: location.href,
},
});
}
}
}
},
+7 -4
View File
@@ -38,7 +38,7 @@ import { useBackdropStore } from "@/utils/store/backdrop";
import "./album.scss";
import IconLink from "@/components/iconLink";
import { createFileRoute } from "@tanstack/react-router";
import { Link, createFileRoute } from "@tanstack/react-router";
function TabPanel(props) {
const { children, value, index, ...other } = props;
@@ -387,10 +387,13 @@ function MusicAlbumTitlePage() {
</Typography>
<div className="item-detail-cast-grid">
{item.data.ArtistItems.map((artist) => (
<NavLink
<Link
className="item-detail-cast-card"
key={artist.Id}
to={`/artist/${artist.Id}`}
to="/artist/$id"
params={{
id: artist.Id,
}}
>
<div
style={{
@@ -430,7 +433,7 @@ function MusicAlbumTitlePage() {
{artist.Role}
</Typography>
</div>
</NavLink>
</Link>
))}
</div>
</div>
+1 -1
View File
@@ -36,7 +36,7 @@ export const Route = createFileRoute("/_api/home/")({
});
function Home() {
const api = Route.useRouteContext().api;
const api = useApiInContext((s) => s.api);
const user = useQuery({
queryKey: ["user"],
+1
View File
@@ -97,6 +97,7 @@ export const Route = createFileRoute("/_api/item/$id")({
});
function ItemDetail() {
"use memo";
const { id } = Route.useParams();
const api = Route.useRouteContext().api;
+6 -1
View File
@@ -965,7 +965,12 @@ function SeriesTitlePage() {
return (
<motion.div
key={episode.Id}
onClick={() => navigate(`/episode/${episode.Id}`)}
onClick={() =>
navigate({
to: "/episode/$id",
params: { id: episode.Id },
})
}
initial={{
transform: "translateY(10px)",
opacity: 0,
+16
View File
@@ -0,0 +1,16 @@
.server-error {
&-container {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
gap: 1em;
.material-symbols-rounded {
font-size: 10em;
// --wght: 500;
// --opsz: 40
}
}
}
+31 -2
View File
@@ -1,6 +1,35 @@
import { createFileRoute } from "@tanstack/react-router";
import { Link, createFileRoute, useNavigate } from "@tanstack/react-router";
import React from "react";
import "./server.error.scss";
import { Button, ButtonGroup, Typography } from "@mui/material";
import { relaunch } from "@tauri-apps/api/process";
export const Route = createFileRoute("/setup/server/error")({
component: () => <div>Hello /setup/server/error!</div>,
component: () => {
const navigate = useNavigate();
return (
<div className="scrollY server-error-container">
<span className="material-symbols-rounded fill gradient-text">
report
</span>
<Typography variant="h4">Unable to connect to server!</Typography>
<div className="flex flex-align-center" style={{ gap: "1em" }}>
<Button
variant="contained"
onClick={() => navigate({ to: "/setup/server/list" })}
>
Change Server
</Button>
<Button
variant="contained"
color="secondary"
onClick={async () => await relaunch()}
>
Restart Blink
</Button>
</div>
</div>
);
},
});