]> Untitled Git - lemmy-ui.git/commitdiff
Refactor first load handling
authorSleeplessOne1917 <abias1122@gmail.com>
Fri, 23 Jun 2023 19:41:10 +0000 (15:41 -0400)
committerJay Sitter <jay@jaysitter.com>
Sat, 24 Jun 2023 04:14:11 +0000 (00:14 -0400)
src/shared/components/app/app.tsx
src/shared/components/community/create-community.tsx
src/shared/components/home/legal.tsx
src/shared/components/home/login.tsx
src/shared/components/home/setup.tsx
src/shared/components/home/signup.tsx
src/shared/components/person/password-change.tsx
src/shared/components/person/settings.tsx
src/shared/components/person/verify-email.tsx
src/shared/services/FirstLoadService.ts

index e50a70709fe572116e150315f2cf7ca2f316374d..96bf10168e8e47aa9729e3f59390eb06d9ddc11f 100644 (file)
@@ -4,7 +4,7 @@ import { Provider } from "inferno-i18next-dess";
 import { Route, Switch } from "inferno-router";
 import { IsoDataOptionalSite } from "../../interfaces";
 import { routes } from "../../routes";
-import { I18NextService } from "../../services";
+import { FirstLoadService, I18NextService } from "../../services";
 import AuthGuard from "../common/auth-guard";
 import ErrorGuard from "../common/error-guard";
 import { ErrorPage } from "./error-page";
@@ -45,27 +45,35 @@ export class App extends Component<any, any> {
             <Navbar siteRes={siteRes} />
             <div className="mt-4 p-0 fl-1">
               <Switch>
-                {routes.map(({ path, component: RouteComponent }) => (
-                  <Route
-                    key={path}
-                    path={path}
-                    exact
-                    component={routeProps => (
-                      <ErrorGuard>
-                        <main tabIndex={-1} ref={this.mainContentRef}>
-                          {RouteComponent &&
-                            (isAuthPath(path ?? "") ? (
-                              <AuthGuard>
-                                <RouteComponent {...routeProps} />
-                              </AuthGuard>
-                            ) : (
-                              <RouteComponent {...routeProps} />
-                            ))}
-                        </main>
-                      </ErrorGuard>
-                    )}
-                  />
-                ))}
+                {routes.map(
+                  ({ path, component: RouteComponent, fetchInitialData }) => (
+                    <Route
+                      key={path}
+                      path={path}
+                      exact
+                      component={routeProps => {
+                        if (!fetchInitialData) {
+                          FirstLoadService.falsify();
+                        }
+
+                        return (
+                          <ErrorGuard>
+                            <main tabIndex={-1} ref={this.mainContentRef}>
+                              {RouteComponent &&
+                                (isAuthPath(path ?? "") ? (
+                                  <AuthGuard>
+                                    <RouteComponent {...routeProps} />
+                                  </AuthGuard>
+                                ) : (
+                                  <RouteComponent {...routeProps} />
+                                ))}
+                            </main>
+                          </ErrorGuard>
+                        );
+                      }}
+                    />
+                  )
+                )}
                 <Route component={ErrorPage} />
               </Switch>
             </div>
index aad6630eb8dcf682f7c179ebd67351f65899955c..2ce5af5a67cf01037872e9693b2e6290d34273bd 100644 (file)
@@ -4,7 +4,7 @@ import {
   CreateCommunity as CreateCommunityI,
   GetSiteResponse,
 } from "lemmy-js-client";
-import { FirstLoadService, HttpService, I18NextService } from "../../services";
+import { HttpService, I18NextService } from "../../services";
 import { HtmlTags } from "../common/html-tags";
 import { CommunityForm } from "./community-form";
 
@@ -22,8 +22,6 @@ export class CreateCommunity extends Component<any, CreateCommunityState> {
   constructor(props: any, context: any) {
     super(props, context);
     this.handleCommunityCreate = this.handleCommunityCreate.bind(this);
-
-    FirstLoadService.isFirstLoad;
   }
 
   get documentTitle(): string {
index 750a91e911b5ef1a3540f13e987fa57914886a1a..85a413ebb9d4a5edecbbde00021dd079196a12a2 100644 (file)
@@ -2,7 +2,7 @@ import { setIsoData } from "@utils/app";
 import { Component } from "inferno";
 import { GetSiteResponse } from "lemmy-js-client";
 import { mdToHtml } from "../../markdown";
-import { FirstLoadService, I18NextService } from "../../services";
+import { I18NextService } from "../../services";
 import { HtmlTags } from "../common/html-tags";
 
 interface LegalState {
@@ -17,8 +17,6 @@ export class Legal extends Component<any, LegalState> {
 
   constructor(props: any, context: any) {
     super(props, context);
-
-    FirstLoadService.isFirstLoad;
   }
 
   get documentTitle(): string {
index d5dd4d2949b21c16d358a1038d71e8e8ebead1ca..1853a82b92d3c1b096ab7265c126d50a5a40e36e 100644 (file)
@@ -3,7 +3,7 @@ import { isBrowser } from "@utils/browser";
 import { validEmail } from "@utils/helpers";
 import { Component, linkEvent } from "inferno";
 import { GetSiteResponse, LoginResponse } from "lemmy-js-client";
-import { FirstLoadService, I18NextService, UserService } from "../../services";
+import { I18NextService, UserService } from "../../services";
 import { HttpService, RequestState } from "../../services/HttpService";
 import { toast } from "../../toast";
 import { HtmlTags } from "../common/html-tags";
@@ -32,8 +32,6 @@ export class Login extends Component<any, State> {
 
   constructor(props: any, context: any) {
     super(props, context);
-
-    FirstLoadService.isFirstLoad;
   }
 
   componentDidMount() {
index fb4c710f3dd4c3a8dab8adf0d8450819445cadf6..bed1262038eb2a098724e07405c0ece852e1a520 100644 (file)
@@ -7,7 +7,7 @@ import {
   LoginResponse,
   Register,
 } from "lemmy-js-client";
-import { FirstLoadService, I18NextService, UserService } from "../../services";
+import { I18NextService, UserService } from "../../services";
 import { HttpService, RequestState } from "../../services/HttpService";
 import { Spinner } from "../common/icon";
 import { SiteForm } from "./site-form";
@@ -47,8 +47,6 @@ export class Setup extends Component<any, State> {
     super(props, context);
 
     this.handleCreateSite = this.handleCreateSite.bind(this);
-
-    FirstLoadService.isFirstLoad;
   }
 
   async componentDidMount() {
index 3bb7ea0e5f16367b18f24b7f1bc226aa0786c1ee..a2d960dc675a5ba10f973e44e1673e9c5d73cb83 100644 (file)
@@ -14,7 +14,7 @@ import {
 } from "lemmy-js-client";
 import { joinLemmyUrl } from "../../config";
 import { mdToHtml } from "../../markdown";
-import { FirstLoadService, I18NextService, UserService } from "../../services";
+import { I18NextService, UserService } from "../../services";
 import { HttpService, RequestState } from "../../services/HttpService";
 import { toast } from "../../toast";
 import { HtmlTags } from "../common/html-tags";
@@ -84,8 +84,6 @@ export class Signup extends Component<any, State> {
     super(props, context);
 
     this.handleAnswerChange = this.handleAnswerChange.bind(this);
-
-    FirstLoadService.isFirstLoad;
   }
 
   async componentDidMount() {
index 0403c553616d8dc91a6b78263720e85d7d3f13c8..dd85e05b3a1961e9f91975ac74185f8db8489291 100644 (file)
@@ -2,12 +2,7 @@ import { myAuth, setIsoData } from "@utils/app";
 import { capitalizeFirstLetter } from "@utils/helpers";
 import { Component, linkEvent } from "inferno";
 import { GetSiteResponse, LoginResponse } from "lemmy-js-client";
-import {
-  FirstLoadService,
-  HttpService,
-  I18NextService,
-  UserService,
-} from "../../services";
+import { HttpService, I18NextService, UserService } from "../../services";
 import { RequestState } from "../../services/HttpService";
 import { HtmlTags } from "../common/html-tags";
 import { Spinner } from "../common/icon";
@@ -35,8 +30,6 @@ export class PasswordChange extends Component<any, State> {
 
   constructor(props: any, context: any) {
     super(props, context);
-
-    FirstLoadService.isFirstLoad;
   }
 
   get documentTitle(): string {
index 1ef95f5a5dd02cc3e29c5d30ebdd54d1a4a2c9a3..6ed11ef8cd48d16b00bcff7084e4222744774325 100644 (file)
@@ -29,7 +29,7 @@ import {
   SortType,
 } from "lemmy-js-client";
 import { elementUrl, emDash, relTags } from "../../config";
-import { FirstLoadService, UserService } from "../../services";
+import { UserService } from "../../services";
 import { HttpService, RequestState } from "../../services/HttpService";
 import { I18NextService, languages } from "../../services/I18NextService";
 import { setupTippy } from "../../tippy";
@@ -170,8 +170,6 @@ export class Settings extends Component<any, SettingsState> {
     this.handleBlockPerson = this.handleBlockPerson.bind(this);
     this.handleBlockCommunity = this.handleBlockCommunity.bind(this);
 
-    FirstLoadService.isFirstLoad;
-
     const mui = UserService.Instance.myUserInfo;
     if (mui) {
       const {
index a13df2d94e8d69309626b751134cb7ff4c0d8e0a..1800c3f25753fc255b3807591cde390ea34941a5 100644 (file)
@@ -1,7 +1,7 @@
 import { setIsoData } from "@utils/app";
 import { Component } from "inferno";
 import { GetSiteResponse, VerifyEmailResponse } from "lemmy-js-client";
-import { FirstLoadService, I18NextService } from "../../services";
+import { I18NextService } from "../../services";
 import { HttpService, RequestState } from "../../services/HttpService";
 import { toast } from "../../toast";
 import { HtmlTags } from "../common/html-tags";
@@ -22,8 +22,6 @@ export class VerifyEmail extends Component<any, State> {
 
   constructor(props: any, context: any) {
     super(props, context);
-
-    FirstLoadService.isFirstLoad;
   }
 
   async verify() {
index 926e3acd6eed44e8e3021797355e78d10349b786..f059e37707d1e473dc88aebcfcaf81b833e2ef2b 100644 (file)
@@ -17,6 +17,10 @@ export class FirstLoadService {
     return isFirst;
   }
 
+  falsify() {
+    this.#isFirstLoad = false;
+  }
+
   static get #Instance() {
     return this.#instance ?? (this.#instance = new this());
   }
@@ -24,4 +28,8 @@ export class FirstLoadService {
   static get isFirstLoad() {
     return !isBrowser() || this.#Instance.isFirstLoad;
   }
+
+  static falsify() {
+    this.#Instance.falsify();
+  }
 }