refactore: cleanup __root.tsx
This commit is contained in:
10 files changed
+274
-256
No files matched your search
+3
-1
@@ -37,4 +37,6 @@ target/
|
||||
**/*.rs.bk
|
||||
|
||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
*.pdb
|
||||
|
||||
generateBanner
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "blink",
|
||||
"private": true,
|
||||
"version": "0.0.7-dev",
|
||||
"version": "0.0.6-dev",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite --force && tsr watch",
|
||||
|
||||
@@ -58,7 +58,11 @@
|
||||
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEZEMTg0MjEzRDYzRjJDN0EKUldSNkxEL1dFMElZL1dxbHA0V2lyVDFEdGpOZXkxMG9XdHVLVnRpVVV5c1Z0OFNRUE45dkpxbFAK",
|
||||
"endpoints": [
|
||||
"https://rawcdn.githack.com/prayag17/Blink/refs/heads/main/latest.json"
|
||||
]
|
||||
],
|
||||
"windows": {
|
||||
"installMode": "passive"
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
"app": {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { useBackdropStore } from "@/utils/store/backdrop";
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
import React, { useLayoutEffect, useState } from "react";
|
||||
|
||||
export default function Backdrop() {
|
||||
const [backdropLoading, setBackdropLoading] = useState(true);
|
||||
|
||||
const [backdropId, backdropUrl] = useBackdropStore((state) => [
|
||||
state.backdropId,
|
||||
state.backdropUrl,
|
||||
]);
|
||||
|
||||
// Reset loading status for backdrop
|
||||
useLayoutEffect(() => {
|
||||
setBackdropLoading(true);
|
||||
}, [backdropId]);
|
||||
|
||||
return (
|
||||
<div className="app-backdrop-container">
|
||||
<AnimatePresence>
|
||||
<motion.img
|
||||
key={backdropId}
|
||||
src={backdropUrl}
|
||||
alt=""
|
||||
className="app-backdrop"
|
||||
initial={{
|
||||
opacity: 0,
|
||||
}}
|
||||
animate={{
|
||||
opacity: backdropLoading ? 0 : 1,
|
||||
}}
|
||||
exit={{
|
||||
opacity: 0,
|
||||
}}
|
||||
transition={{
|
||||
opacity: {
|
||||
duration: 1.2,
|
||||
},
|
||||
}}
|
||||
onLoad={() => setBackdropLoading(false)}
|
||||
loading="lazy"
|
||||
/>
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,27 +1,40 @@
|
||||
import { LinearProgress } from "@mui/material";
|
||||
import { useNProgress } from "@tanem/react-nprogress";
|
||||
import React from "react";
|
||||
import { useIsFetching, useIsMutating } from "@tanstack/react-query";
|
||||
import { useRouterState } from "@tanstack/react-router";
|
||||
import React, { useMemo } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
|
||||
export default function NProgress() {
|
||||
const isQueryFetching = useIsFetching();
|
||||
const isMutating = useIsMutating();
|
||||
const routeIsLoading = useRouterState().isLoading;
|
||||
|
||||
const isAnimating = useMemo(() => {
|
||||
if (isQueryFetching || isMutating || routeIsLoading) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}, [isQueryFetching, isMutating, routeIsLoading]);
|
||||
|
||||
const NProgress: React.FC<{ isAnimating: boolean | number }> = ({
|
||||
isAnimating,
|
||||
}) => {
|
||||
const { animationDuration, isFinished, progress } = useNProgress({
|
||||
isAnimating,
|
||||
});
|
||||
|
||||
if (isAnimating) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
pointerEvents: "none",
|
||||
transition: `opacity ${animationDuration}ms linear`,
|
||||
position: "fixed",
|
||||
top: "0",
|
||||
left: "0",
|
||||
right: "0",
|
||||
zIndex: "10001",
|
||||
}}
|
||||
>
|
||||
return createPortal(
|
||||
<div
|
||||
style={{
|
||||
pointerEvents: "none",
|
||||
transition: "opacity 250ms linear",
|
||||
position: "fixed",
|
||||
top: "0",
|
||||
left: "0",
|
||||
right: "0",
|
||||
zIndex: "10001",
|
||||
opacity: isFinished ? 0 : 1,
|
||||
}}
|
||||
>
|
||||
{isAnimating && (
|
||||
<LinearProgress
|
||||
sx={{
|
||||
height: 3,
|
||||
@@ -30,9 +43,9 @@ const NProgress: React.FC<{ isAnimating: boolean | number }> = ({
|
||||
value={progress * 100}
|
||||
variant="determinate"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
)}
|
||||
</div>,
|
||||
document.body,
|
||||
);
|
||||
};
|
||||
|
||||
export default NProgress;
|
||||
+1
-1
@@ -4,7 +4,7 @@ import Typography from "@mui/material/Typography";
|
||||
import { yellow } from "@mui/material/colors";
|
||||
import React from "react";
|
||||
|
||||
export const EmptyNotice = ({ extraMsg }) => {
|
||||
export const EmptyNotice = ({ extraMsg }: { extraMsg?: string }) => {
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
@@ -0,0 +1,24 @@
|
||||
import { CircularProgress } from "@mui/material";
|
||||
import { useRouterState } from "@tanstack/react-router";
|
||||
import React from "react";
|
||||
|
||||
export default function RouterLoading() {
|
||||
const routeLoading = useRouterState().isLoading;
|
||||
if (!routeLoading) return null;
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
width: "100vw",
|
||||
height: "100vh",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
background: "rgb(0 0 0 / 0.35)",
|
||||
position: "fixed",
|
||||
zIndex: 10000,
|
||||
}}
|
||||
>
|
||||
<CircularProgress size={72} thickness={2} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -422,10 +422,10 @@ const Settings = () => {
|
||||
icon={
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{ "--wght": 500 }}
|
||||
// style={{ "--wght": 500 }}
|
||||
>
|
||||
{updateInfo.data?.available
|
||||
? "new_release"
|
||||
? "release_alert"
|
||||
: "new_releases"}
|
||||
</span>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
import { LoadingButton } from "@mui/lab";
|
||||
import {
|
||||
Button,
|
||||
Chip,
|
||||
Dialog,
|
||||
DialogActions,
|
||||
DialogContent,
|
||||
DialogContentText,
|
||||
DialogTitle,
|
||||
Link,
|
||||
} from "@mui/material";
|
||||
import { relaunch } from "@tauri-apps/plugin-process";
|
||||
import { type Update, check } from "@tauri-apps/plugin-updater";
|
||||
import { useSnackbar } from "notistack";
|
||||
import React, { useLayoutEffect, useState } from "react";
|
||||
|
||||
export default function Updater() {
|
||||
const [updateDialog, setUpdateDialog] = useState(false);
|
||||
const [updateDialogButton, setUpdateDialogButton] = useState(false);
|
||||
const [updateInfo, setUpdateInfo] = useState<Update | undefined>(undefined);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
async function checkForUpdates() {
|
||||
try {
|
||||
const update = await check();
|
||||
|
||||
if (update?.available) {
|
||||
setUpdateInfo(update);
|
||||
setUpdateDialog(true);
|
||||
|
||||
console.info(`Update found : ${update.version}, ${update.date}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
checkForUpdates();
|
||||
}, []);
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
if (!updateInfo) return null;
|
||||
return (
|
||||
<Dialog
|
||||
open={updateDialog}
|
||||
maxWidth="xs"
|
||||
PaperProps={{
|
||||
style: {
|
||||
borderRadius: "20px",
|
||||
},
|
||||
className: "glass",
|
||||
}}
|
||||
sx={{
|
||||
"& img": {
|
||||
width: "100%",
|
||||
},
|
||||
}}
|
||||
>
|
||||
<DialogTitle variant="h5" align="center" textAlign={"center"}>
|
||||
Update Available!
|
||||
</DialogTitle>
|
||||
<DialogContent
|
||||
className="flex flex-center"
|
||||
style={{ gap: "0.5em", padding: "0 2em 1em 2em", flexWrap: "wrap" }}
|
||||
>
|
||||
<Chip
|
||||
icon={<span className="material-symbols-rounded">update</span>}
|
||||
label={`v${updateInfo.currentVersion}`}
|
||||
variant="outlined"
|
||||
/>
|
||||
<span className="material-symbols-rounded">arrow_right_alt</span>
|
||||
<Chip
|
||||
icon={<span className="material-symbols-rounded">update</span>}
|
||||
label={`v${updateInfo.version}`}
|
||||
variant="outlined"
|
||||
/>
|
||||
<DialogContentText sx={{ width: "100%" }}>
|
||||
<Link
|
||||
href={`https://github.com/prayag17/Blink/releases/v${updateInfo.version}`}
|
||||
target="_blank"
|
||||
>
|
||||
Open changelog
|
||||
</Link>
|
||||
</DialogContentText>
|
||||
</DialogContent>
|
||||
|
||||
<DialogActions
|
||||
style={{
|
||||
padding: "1em",
|
||||
}}
|
||||
className="flex flex-center"
|
||||
>
|
||||
{/* <Button
|
||||
variant="outlined"
|
||||
//@ts-ignore
|
||||
color="white"
|
||||
disabled={updateDialogButton}
|
||||
onClick={() => setUpdateDialog(false)}
|
||||
>
|
||||
changelog
|
||||
</Button> */}
|
||||
<Button
|
||||
color="error"
|
||||
variant="contained"
|
||||
disabled={updateDialogButton}
|
||||
onClick={() => setUpdateDialog(false)}
|
||||
style={{ borderRadius: "10px" }}
|
||||
disableElevation
|
||||
>
|
||||
close
|
||||
</Button>
|
||||
<LoadingButton
|
||||
style={{ borderRadius: "10px" }}
|
||||
color="success"
|
||||
variant="contained"
|
||||
loading={updateDialogButton}
|
||||
loadingIndicator="Updating..."
|
||||
disableElevation
|
||||
onClick={async () => {
|
||||
setUpdateDialogButton(true);
|
||||
await updateInfo.downloadAndInstall();
|
||||
enqueueSnackbar(
|
||||
"Update has been installed! You need to relaunch JellyPlayer.",
|
||||
{
|
||||
variant: "success",
|
||||
},
|
||||
);
|
||||
await relaunch();
|
||||
}}
|
||||
>
|
||||
Update
|
||||
</LoadingButton>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
+23
-229
@@ -3,37 +3,14 @@ import NProgress from "@/components/nProgress";
|
||||
import AudioPlayer from "@/components/playback/audioPlayer";
|
||||
import Settings from "@/components/settings";
|
||||
import { EasterEgg } from "@/components/utils/easterEgg";
|
||||
import { useBackdropStore } from "@/utils/store/backdrop";
|
||||
import { LoadingButton } from "@mui/lab";
|
||||
import {
|
||||
Button,
|
||||
Chip,
|
||||
CircularProgress,
|
||||
CssBaseline,
|
||||
Dialog,
|
||||
DialogActions,
|
||||
DialogContent,
|
||||
DialogContentText,
|
||||
DialogTitle,
|
||||
IconButton,
|
||||
SvgIcon,
|
||||
ThemeProvider,
|
||||
} from "@mui/material";
|
||||
import { useIsFetching, useIsMutating } from "@tanstack/react-query";
|
||||
import { CssBaseline, ThemeProvider } from "@mui/material";
|
||||
import {
|
||||
Outlet,
|
||||
ScrollRestoration,
|
||||
createRootRouteWithContext,
|
||||
useRouterState,
|
||||
} from "@tanstack/react-router";
|
||||
import { TanStackRouterDevtools } from "@tanstack/router-devtools";
|
||||
import { relaunch } from "@tauri-apps/plugin-process";
|
||||
import { type Update, check } from "@tauri-apps/plugin-updater";
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
import { SnackbarProvider, useSnackbar } from "notistack";
|
||||
import React, { Suspense, useEffect, useLayoutEffect, useState } from "react";
|
||||
import Markdown from "react-markdown";
|
||||
import remarkGfm from "remark-gfm";
|
||||
import { SnackbarProvider } from "notistack";
|
||||
import React from "react";
|
||||
|
||||
import "../styles/global.scss";
|
||||
import { theme } from "@/theme";
|
||||
@@ -43,7 +20,10 @@ import "@fontsource-variable/jetbrains-mono";
|
||||
import "@fontsource-variable/noto-sans";
|
||||
|
||||
import "material-symbols/rounded.scss";
|
||||
import Backdrop from "@/components/backdrop";
|
||||
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
||||
import RouterLoading from "@/components/routerLoading";
|
||||
import Updater from "@/components/updater";
|
||||
import type { Api, Jellyfin } from "@jellyfin/sdk";
|
||||
import type { UserDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
||||
@@ -60,213 +40,27 @@ type ApiContext = {
|
||||
|
||||
export const Route = createRootRouteWithContext<ApiContext>()({
|
||||
component: () => {
|
||||
const isQueryFetching = useIsFetching();
|
||||
const isMutating = useIsMutating();
|
||||
const routeIsLoading = useRouterState().isLoading;
|
||||
const [updateDialog, setUpdateDialog] = useState(false);
|
||||
const [updateDialogButton, setUpdateDialogButton] = useState(false);
|
||||
const [updateInfo, setUpdateInfo] = useState<Update | undefined>(undefined);
|
||||
useLayoutEffect(() => {
|
||||
async function checkForUpdates() {
|
||||
try {
|
||||
const update = await check();
|
||||
|
||||
if (update?.available) {
|
||||
setUpdateInfo(update);
|
||||
setUpdateDialog(true);
|
||||
|
||||
console.log(`Update found : ${update.version}, ${update.date}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
checkForUpdates();
|
||||
}, []);
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
const [backdropUrl, backdropId] = useBackdropStore((state) => [
|
||||
state.backdropUrl,
|
||||
state.backdropId,
|
||||
]);
|
||||
|
||||
const [backdropLoading, setBackdropLoading] = useState(true);
|
||||
// Reset BackdropImageLoading for every new image
|
||||
useEffect(() => {
|
||||
setBackdropLoading(true);
|
||||
}, [backdropId]);
|
||||
return (
|
||||
<DndProvider backend={HTML5Backend}>
|
||||
<Suspense fallback={<h1>Loading...</h1>}>
|
||||
<ThemeProvider theme={theme}>
|
||||
<SnackbarProvider maxSnack={5}>
|
||||
<CssBaseline />
|
||||
<ScrollRestoration />
|
||||
<Settings />
|
||||
<EasterEgg />
|
||||
<NProgress
|
||||
key={
|
||||
isQueryFetching || isMutating || routeIsLoading
|
||||
? `show${(isQueryFetching ?? 1) * (isMutating ?? 1) * (routeIsLoading ? 1 : 2)}`
|
||||
: "hide"
|
||||
}
|
||||
isAnimating={isQueryFetching && isMutating && routeIsLoading}
|
||||
/>
|
||||
<ThemeProvider theme={theme}>
|
||||
<SnackbarProvider maxSnack={5}>
|
||||
<CssBaseline />
|
||||
<ScrollRestoration />
|
||||
<Settings />
|
||||
<EasterEgg />
|
||||
<NProgress />
|
||||
|
||||
{routeIsLoading && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
style={{
|
||||
width: "100vw",
|
||||
height: "100vh",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
background: "rgb(0 0 0 / 0.35)",
|
||||
position: "fixed",
|
||||
zIndex: 10000,
|
||||
}}
|
||||
>
|
||||
<CircularProgress size={72} thickness={2} />
|
||||
</motion.div>
|
||||
)}
|
||||
<RouterLoading />
|
||||
|
||||
<Dialog
|
||||
open={updateDialog}
|
||||
fullWidth
|
||||
PaperProps={{
|
||||
style: {
|
||||
borderRadius: "14px",
|
||||
background: "rgb(0 0 0 / 0.5)",
|
||||
backdropFilter: "blur(10px)",
|
||||
border: "1px solid rgb(255 255 255 / 0.2)",
|
||||
},
|
||||
}}
|
||||
sx={{
|
||||
"& img": {
|
||||
width: "100%",
|
||||
},
|
||||
}}
|
||||
>
|
||||
{updateInfo !== undefined && (
|
||||
<>
|
||||
<DialogTitle
|
||||
variant="h5"
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "flex-start",
|
||||
gap: "0.4em",
|
||||
}}
|
||||
>
|
||||
Update Available!
|
||||
<Chip
|
||||
icon={
|
||||
<span className="material-symbols-rounded">
|
||||
update
|
||||
</span>
|
||||
}
|
||||
label={`v${updateInfo.version}`}
|
||||
color="success"
|
||||
/>
|
||||
</DialogTitle>
|
||||
<DialogContent dividers>
|
||||
<DialogContentText>
|
||||
<Markdown remarkPlugins={[remarkGfm]}>
|
||||
{updateInfo.body}
|
||||
</Markdown>
|
||||
</DialogContentText>
|
||||
</DialogContent>
|
||||
<DialogActions
|
||||
style={{
|
||||
padding: "1em",
|
||||
}}
|
||||
>
|
||||
<IconButton
|
||||
disabled={updateDialogButton}
|
||||
target="_blank"
|
||||
href={`https://github.com/prayag17/JellyPlayer/releases/${updateInfo.version}`}
|
||||
>
|
||||
<SvgIcon>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
fill="currentColor"
|
||||
viewBox="0 0 16 16"
|
||||
>
|
||||
<title>Update</title>
|
||||
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8" />
|
||||
</svg>
|
||||
</SvgIcon>
|
||||
</IconButton>
|
||||
<Button
|
||||
size="large"
|
||||
color="error"
|
||||
variant="outlined"
|
||||
disabled={updateDialogButton}
|
||||
onClick={() => setUpdateDialog(false)}
|
||||
>
|
||||
close
|
||||
</Button>
|
||||
<LoadingButton
|
||||
size="large"
|
||||
color="success"
|
||||
variant="contained"
|
||||
loading={updateDialogButton}
|
||||
loadingIndicator="Updating..."
|
||||
onClick={async () => {
|
||||
setUpdateDialogButton(true);
|
||||
await updateInfo.downloadAndInstall();
|
||||
enqueueSnackbar(
|
||||
"Update has been installed! You need to relaunch JellyPlayer.",
|
||||
{
|
||||
variant: "success",
|
||||
},
|
||||
);
|
||||
await relaunch();
|
||||
}}
|
||||
>
|
||||
Update
|
||||
</LoadingButton>
|
||||
</DialogActions>
|
||||
</>
|
||||
)}
|
||||
</Dialog>
|
||||
<div className="app-backdrop-container">
|
||||
<AnimatePresence>
|
||||
<motion.img
|
||||
key={backdropId}
|
||||
src={backdropUrl}
|
||||
alt=""
|
||||
className="app-backdrop"
|
||||
initial={{
|
||||
opacity: 0,
|
||||
}}
|
||||
animate={{
|
||||
opacity: backdropLoading ? 0 : 1,
|
||||
}}
|
||||
exit={{
|
||||
opacity: 0,
|
||||
}}
|
||||
transition={{
|
||||
opacity: {
|
||||
duration: 1.2,
|
||||
},
|
||||
}}
|
||||
onLoad={() => setBackdropLoading(false)}
|
||||
loading="lazy"
|
||||
/>
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
<AppBar />
|
||||
<AudioPlayer />
|
||||
<Outlet />
|
||||
<ReactQueryDevtools />
|
||||
{/* <TanStackRouterDevtools /> */}
|
||||
</SnackbarProvider>
|
||||
</ThemeProvider>
|
||||
</Suspense>
|
||||
<Updater />
|
||||
<Backdrop />
|
||||
<AppBar />
|
||||
<AudioPlayer />
|
||||
<Outlet />
|
||||
<ReactQueryDevtools />
|
||||
{/* <TanStackRouterDevtools /> */}
|
||||
</SnackbarProvider>
|
||||
</ThemeProvider>
|
||||
</DndProvider>
|
||||
);
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user