Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Display loading animation during page transitions.
nzbdav-devbebddc402414
diff --git a/frontend/app/root.tsx b/frontend/app/root.tsxindex cb702a1f..58f93241 100644--- a/frontend/app/root.tsx+++ b/frontend/app/root.tsx@@ -5,6 +5,8 @@ import {redirect,Scripts,ScrollRestoration,+ useLocation,+ useNavigation,} from "react-router";import 'bootstrap/dist/css/bootstrap.min.css';@@ -14,6 +16,7 @@ import { sessionStorage } from "~/auth/authentication.server";import { TopNavigation } from "./routes/_index/components/top-navigation/top-navigation";import { LeftNavigation } from "./routes/_index/components/left-navigation/left-navigation";import { PageLayout } from "./routes/_index/components/page-layout/page-layout";+import { Loading } from "./routes/_index/components/loading/loading";export async function loader({ request }: Route.LoaderArgs) {// unauthenticated routes@@ -50,12 +53,21 @@ export function Layout({ children }: { children: React.ReactNode }) {export default function App({ loaderData }: Route.ComponentProps) {const { useLayout } = loaderData;+ const location = useLocation();+ const navigation = useNavigation();+ const isNavigating = Boolean(navigation.location);++ // display loading animiation during top-level page transitions,+ // but allow the `/explore` page to handle it's own loading screen.+ const isCurrentExplorePage = location.pathname.startsWith("/explore");+ const isNextExplorePage = navigation.location?.pathname?.startsWith("/explore");+ const showLoading = isNavigating && !(isCurrentExplorePage && isNextExplorePage);if (useLayout) {return (<PageLayouttopNavComponent={TopNavigation}- bodyChild={<Outlet />}+ bodyChild={showLoading ? <Loading /> : <Outlet />}leftNavChild={<LeftNavigation />} />);}diff --git a/frontend/app/routes/_index/components/loading/loading.module.css b/frontend/app/routes/_index/components/loading/loading.module.cssnew file mode 100644index 00000000..7d214831--- /dev/null+++ b/frontend/app/routes/_index/components/loading/loading.module.css@@ -0,0 +1,44 @@+.container {+ width: 100%;+ min-height: 100%;+ display: flex;+ justify-content: center;+ align-items: center;+ position: absolute;+}++.loader-ring {+ width: 250px;+ height: 250px;+ border-radius: 50%;+ border: 12px solid rgba(147, 161, 161, 0.2);+ border-top-color: #93a1a1;+ animation: spin 1.5s linear infinite;+ box-shadow: 0 0 20px rgba(147, 161, 161, 0.5);+ position: absolute;+ top: 50%;+ left: 50%;+ transform: translate(-50%, -50%);+}++@keyframes spin {+ 0% {+ transform: translate(-50%, -50%) rotate(0deg);+ }++ 100% {+ transform: translate(-50%, -50%) rotate(360deg);+ }+}++.loading-text {+ color: #93a1a1;+ font-size: 2em;+ font-weight: bold;+ text-shadow: 0 0 6px rgba(147, 161, 161, 0.5);+ position: absolute;+ top: 50%;+ left: 50%;+ transform: translate(-50%, -50%);+ z-index: 1;+}\ No newline at end of filediff --git a/frontend/app/routes/_index/components/loading/loading.module.css.d.ts b/frontend/app/routes/_index/components/loading/loading.module.css.d.tsnew file mode 100644index 00000000..bcf45351--- /dev/null+++ b/frontend/app/routes/_index/components/loading/loading.module.css.d.ts@@ -0,0 +1,7 @@+declare const styles: {+ readonly "container": string;+ readonly "loader-ring": string;+ readonly "loading-text": string;+};+export = styles;+diff --git a/frontend/app/routes/_index/components/loading/loading.tsx b/frontend/app/routes/_index/components/loading/loading.tsxnew file mode 100644index 00000000..6e2cf592--- /dev/null+++ b/frontend/app/routes/_index/components/loading/loading.tsx@@ -0,0 +1,14 @@+import styles from "./loading.module.css";++export type LoadingProps = {+ className?: string+}++export function Loading({ className }: LoadingProps) {+ return (+ <div className={`${styles.container} ${className ? className : ''}`}>+ <div className={styles["loader-ring"]}></div>+ <div className={styles["loading-text"]}>Loading...</div>+ </div>+ );+}\ No newline at end of filediff --git a/frontend/app/routes/explore/route.module.css b/frontend/app/routes/explore/route.module.cssindex ad144c74..1bead573 100644--- a/frontend/app/routes/explore/route.module.css+++ b/frontend/app/routes/explore/route.module.css@@ -4,6 +4,9 @@padding: 30px 35px 20px 35px;color: #93a1a1;font-size: 16px;+ display: flex;+ flex-direction: column;+ position: absolute;}.item {@@ -86,4 +89,11 @@.item-name {word-break: break-all;overflow-wrap: break-word;+}++.loading {+ width: calc(100% - 75px);+ flex-grow: 1;+ position: unset;+ min-height: unset;}\ No newline at end of filediff --git a/frontend/app/routes/explore/route.module.css.d.ts b/frontend/app/routes/explore/route.module.css.d.tsindex 57332fd8..a0bd42ac 100644--- a/frontend/app/routes/explore/route.module.css.d.ts+++ b/frontend/app/routes/explore/route.module.css.d.ts@@ -6,6 +6,7 @@ declare const styles: {readonly "item": string;readonly "item-name": string;readonly "video-icon": string;+ readonly "loading": string;};export = styles;diff --git a/frontend/app/routes/explore/route.tsx b/frontend/app/routes/explore/route.tsxindex 9c5dfa9a..110d12b9 100644--- a/frontend/app/routes/explore/route.tsx+++ b/frontend/app/routes/explore/route.tsx@@ -1,12 +1,12 @@import type { Route } from "./+types/route";import { Breadcrumbs } from "./breadcrumbs/breadcrumbs";import styles from "./route.module.css"-import { Link, redirect, useLocation, useNavigate } from "react-router";+import { Link, useLocation, useNavigation } from "react-router";import { backendClient, type DirectoryItem } from "~/clients/backend-client.server";-import { sessionStorage } from "~/auth/authentication.server";import { useCallback } from "react";import { lookup as getMimeType } from 'mime-types';import { getDownloadKey } from "~/auth/downloads.server";+import { Loading } from "../_index/components/loading/loading";export type ExplorePageData = {parentDirectories: string[],@@ -20,17 +20,10 @@ export type ExploreFile = DirectoryItem & {export async function loader({ request }: Route.LoaderArgs) {- let session = await sessionStorage.getSession(request.headers.get("cookie"));- let user = session.get("user");- if (!user) return redirect("/login");-- let path = new URL(request.url).pathname;- if (path.startsWith("/")) path = path.slice(1);- if (path.startsWith("explore")) path = path.slice(7);- if (path.startsWith("/")) path = path.slice(1);+ let path = getWebdavPath(new URL(request.url).pathname);return {- parentDirectories: path == "" ? [] : path.split('/'),+ parentDirectories: getParentDirectories(path),items: (await backendClient.listWebdavDirectory(path)).map(x => {if (x.isDirectory) return x;return {@@ -42,20 +35,25 @@ export async function loader({ request }: Route.LoaderArgs) {}}-export default function Explore({ loaderData }: Route.ComponentProps) {return (<Body {...loaderData} />);}-function Body({ parentDirectories, items }: ExplorePageData) {+function Body(props: ExplorePageData) {const location = useLocation();- const navigate = useNavigate();+ const navigation = useNavigation();+ const isNavigating = Boolean(navigation.location);++ const items = props.items;+ const parentDirectories = isNavigating+ ? getParentDirectories(getWebdavPath(navigation.location!.pathname))+ : props.parentDirectories;const getDirectoryPath = useCallback((directoryName: string) => {return `${location.pathname}/${directoryName}`- }, [location.pathname, navigate]);+ }, [location.pathname]);const getFilePath = useCallback((file: ExploreFile) => {var pathname = location.pathname;@@ -63,33 +61,46 @@ function Body({ parentDirectories, items }: ExplorePageData) {if (pathname.startsWith("explore")) pathname = pathname.slice(7);if (pathname.startsWith("/")) pathname = pathname.slice(1);return `/view/${pathname}/${file.name}?downloadKey=${file.downloadKey}`;- }, [location.pathname, navigate]);+ }, [location.pathname]);return (<div className={styles.container}><Breadcrumbs parentDirectories={parentDirectories} />- <div>- {items.filter(x => x.isDirectory).map((x, index) =>- <Link key={`${index}_dir_item`} to={getDirectoryPath(x.name)} className={styles.item}>- <div className={styles["directory-icon"]} />- <div className={styles["item-name"]}>{x.name}</div>- </Link>- )}- {items.filter(x => !x.isDirectory).map((x, index) =>- <a key={`${index}_file_item`} href={getFilePath(x as ExploreFile)} className={styles.item}>- <div className={getIcon(x as ExploreFile)} />- <div className={styles["item-name"]}>{x.name}</div>- </a>- )}- </div>+ {!isNavigating &&+ <div>+ {items.filter(x => x.isDirectory).map((x, index) =>+ <Link key={`${index}_dir_item`} to={getDirectoryPath(x.name)} className={styles.item}>+ <div className={styles["directory-icon"]} />+ <div className={styles["item-name"]}>{x.name}</div>+ </Link>+ )}+ {items.filter(x => !x.isDirectory).map((x, index) =>+ <a key={`${index}_file_item`} href={getFilePath(x as ExploreFile)} className={styles.item}>+ <div className={getIcon(x as ExploreFile)} />+ <div className={styles["item-name"]}>{x.name}</div>+ </a>+ )}+ </div>+ }+ {isNavigating && <Loading className={styles.loading} />}</div >);}-function getIcon(file: ExploreFile) {if (file.name.toLowerCase().endsWith(".mkv")) return styles["video-icon"];if (file.mimeType && file.mimeType.startsWith("video")) return styles["video-icon"];if (file.mimeType && file.mimeType.startsWith("image")) return styles["image-icon"];return styles["file-icon"];}++function getWebdavPath(pathname: string): string {+ if (pathname.startsWith("/")) pathname = pathname.slice(1);+ if (pathname.startsWith("explore")) pathname = pathname.slice(7);+ if (pathname.startsWith("/")) pathname = pathname.slice(1);+ return pathname;+}++function getParentDirectories(webdavPath: string): string[] {+ return webdavPath == "" ? [] : webdavPath.split('/');+}\ No newline at end of file