From 51972060a71448b83984bc199133427da73ba0eb Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> Date: Tue, 16 Apr 2024 13:56:01 -0400 Subject: [PATCH] Remove delay between page loading and being blurred --- lemmy-translations | 2 +- src/client/index.tsx | 2 +- src/server/handlers/catch-all-handler.tsx | 2 +- src/shared/components/app/app.tsx | 197 ++++++++++++---------- 4 files changed, 110 insertions(+), 93 deletions(-) diff --git a/lemmy-translations b/lemmy-translations index d250d15f..e0150333 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit d250d15f4fbf3e1b9565529f7d0cea90c8270757 +Subproject commit e015033336375d2743a314b166a3c7c16526915e diff --git a/src/client/index.tsx b/src/client/index.tsx index db0a9ef7..27031189 100644 --- a/src/client/index.tsx +++ b/src/client/index.tsx @@ -1,7 +1,7 @@ import { initializeSite } from "@utils/app"; import { hydrate } from "inferno-hydrate"; import { BrowserRouter } from "inferno-router"; -import { App } from "../shared/components/app/app"; +import App from "../shared/components/app/app"; import { lazyHighlightjs } from "../shared/lazy-highlightjs"; import { loadUserLanguage } from "../shared/services/I18NextService"; import { verifyDynamicImports } from "../shared/dynamic-imports"; diff --git a/src/server/handlers/catch-all-handler.tsx b/src/server/handlers/catch-all-handler.tsx index 33d4d7a6..8aafaa82 100644 --- a/src/server/handlers/catch-all-handler.tsx +++ b/src/server/handlers/catch-all-handler.tsx @@ -6,7 +6,7 @@ import { StaticRouter, matchPath } from "inferno-router"; import { Match } from "inferno-router/dist/Route"; import { renderToString } from "inferno-server"; import { GetSiteResponse, LemmyHttp } from "lemmy-js-client"; -import { App } from "../../shared/components/app/app"; +import App from "../../shared/components/app/app"; import { InitialFetchRequest, IsoDataOptionalSite, diff --git a/src/shared/components/app/app.tsx b/src/shared/components/app/app.tsx index a9c8b793..e655f6fb 100644 --- a/src/shared/components/app/app.tsx +++ b/src/shared/components/app/app.tsx @@ -1,5 +1,11 @@ import { isAnonymousPath, isAuthPath, setIsoData } from "@utils/app"; -import { Component, createRef, linkEvent } from "inferno"; +import { + Component, + RefObject, + createRef, + forwardRef, + linkEvent, +} from "inferno"; import { Provider } from "inferno-i18next-dess"; import { Route, Switch } from "inferno-router"; import { IsoDataOptionalSite } from "../../interfaces"; @@ -16,9 +22,99 @@ import AnonymousGuard from "../common/anonymous-guard"; import { destroyTippy, setupTippy } from "../../tippy"; import AdultConsentModal from "../common/adult-consent-modal"; -export class App extends Component { +interface AppProps { + ref: RefObject; +} + +function handleJumpToContent(event) { + event.preventDefault(); +} + +class App extends Component { + private isoData: IsoDataOptionalSite = setIsoData(this.context); + + render() { + const siteRes = this.isoData.site_res; + const siteView = siteRes?.site_view; + + return ( +
+ + {siteView && } + +
+ + {routes.map( + ({ + path, + component: RouteComponent, + fetchInitialData, + getQueryParams, + }) => ( + { + if (!fetchInitialData) { + FirstLoadService.falsify(); + } + + let queryProps = routeProps; + if (getQueryParams && this.isoData.site_res) { + // ErrorGuard will not render its children when + // site_res is missing, this guarantees that props + // will always contain the query params. + queryProps = { + ...routeProps, + ...getQueryParams( + routeProps.location.search, + this.isoData.site_res, + ), + }; + } + + return ( + +
+ {RouteComponent && + (isAuthPath(path ?? "") ? ( + + + + ) : isAnonymousPath(path ?? "") ? ( + + + + ) : ( + + ))} +
+
+ ); + }} + /> + ), + )} + +
+
+
+
+ ); + } +} + +const AppForwardRef = forwardRef((props, ref) => ); + +export default class AppWrapper extends Component { private isoData: IsoDataOptionalSite = setIsoData(this.context); - private readonly mainContentRef = createRef(); private readonly rootRef = createRef(); componentDidMount(): void { @@ -29,96 +125,17 @@ export class App extends Component { destroyTippy(); } - handleJumpToContent(event) { - event.preventDefault(); - this.mainContentRef.current?.focus(); - } - render() { - const siteRes = this.isoData.site_res; - const siteView = siteRes?.site_view; + const contentWarning = + this.isoData.site_res?.site_view.site.content_warning; return ( - <> - -
- - {siteView && ( - - )} - - {siteRes?.site_view.site.content_warning && ( - - )} -
- - {routes.map( - ({ - path, - component: RouteComponent, - fetchInitialData, - getQueryParams, - }) => ( - { - if (!fetchInitialData) { - FirstLoadService.falsify(); - } - - let queryProps = routeProps; - if (getQueryParams && this.isoData.site_res) { - // ErrorGuard will not render its children when - // site_res is missing, this guarantees that props - // will always contain the query params. - queryProps = { - ...routeProps, - ...getQueryParams( - routeProps.location.search, - this.isoData.site_res, - ), - }; - } - - return ( - -
- {RouteComponent && - (isAuthPath(path ?? "") ? ( - - - - ) : isAnonymousPath(path ?? "") ? ( - - - - ) : ( - - ))} -
-
- ); - }} - /> - ), - )} - -
-
-
-
-
- + + {contentWarning && ( + + )} + + ); } }