mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-23 12:51:13 +00:00
Merge branch 'main' into cursor_pagination
This commit is contained in:
commit
afb2a2a964
8 changed files with 48 additions and 15 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { isAuthPath, setIsoData } from "@utils/app";
|
import { isAnonymousPath, isAuthPath, setIsoData } from "@utils/app";
|
||||||
import { dataBsTheme } from "@utils/browser";
|
import { dataBsTheme } from "@utils/browser";
|
||||||
import { Component, RefObject, createRef, linkEvent } from "inferno";
|
import { Component, RefObject, createRef, linkEvent } from "inferno";
|
||||||
import { Provider } from "inferno-i18next-dess";
|
import { Provider } from "inferno-i18next-dess";
|
||||||
|
@ -14,6 +14,7 @@ import { Footer } from "./footer";
|
||||||
import { Navbar } from "./navbar";
|
import { Navbar } from "./navbar";
|
||||||
import "./styles.scss";
|
import "./styles.scss";
|
||||||
import { Theme } from "./theme";
|
import { Theme } from "./theme";
|
||||||
|
import AnonymousGuard from "../common/anonymous-guard";
|
||||||
|
|
||||||
interface AppProps {
|
interface AppProps {
|
||||||
user?: MyUserInfo;
|
user?: MyUserInfo;
|
||||||
|
@ -78,6 +79,10 @@ export class App extends Component<AppProps, any> {
|
||||||
<AuthGuard {...routeProps}>
|
<AuthGuard {...routeProps}>
|
||||||
<RouteComponent {...routeProps} />
|
<RouteComponent {...routeProps} />
|
||||||
</AuthGuard>
|
</AuthGuard>
|
||||||
|
) : isAnonymousPath(path ?? "") ? (
|
||||||
|
<AnonymousGuard>
|
||||||
|
<RouteComponent {...routeProps} />
|
||||||
|
</AnonymousGuard>
|
||||||
) : (
|
) : (
|
||||||
<RouteComponent {...routeProps} />
|
<RouteComponent {...routeProps} />
|
||||||
))}
|
))}
|
||||||
|
|
31
src/shared/components/common/anonymous-guard.tsx
Normal file
31
src/shared/components/common/anonymous-guard.tsx
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import { Component } from "inferno";
|
||||||
|
import { UserService } from "../../services";
|
||||||
|
import { Spinner } from "./icon";
|
||||||
|
|
||||||
|
interface AnonymousGuardState {
|
||||||
|
hasRedirected: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousGuard extends Component<any, AnonymousGuardState> {
|
||||||
|
state = {
|
||||||
|
hasRedirected: false,
|
||||||
|
} as AnonymousGuardState;
|
||||||
|
|
||||||
|
constructor(props: any, context: any) {
|
||||||
|
super(props, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
if (UserService.Instance.myUserInfo) {
|
||||||
|
this.context.router.history.replace(`/`);
|
||||||
|
} else {
|
||||||
|
this.setState({ hasRedirected: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return this.state.hasRedirected ? this.props.children : <Spinner />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AnonymousGuard;
|
|
@ -201,6 +201,8 @@ class RemoteFetchModal extends Component<
|
||||||
value={this.state.instanceText}
|
value={this.state.instanceText}
|
||||||
onInput={linkEvent(this, handleInput)}
|
onInput={linkEvent(this, handleInput)}
|
||||||
required
|
required
|
||||||
|
enterKeyHint="go"
|
||||||
|
inputMode="url"
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
<footer className="modal-footer">
|
<footer className="modal-footer">
|
||||||
|
|
|
@ -226,6 +226,7 @@ export default class TotpModal extends Component<
|
||||||
ref={element => {
|
ref={element => {
|
||||||
this.inputRefs[i] = element;
|
this.inputRefs[i] = element;
|
||||||
}}
|
}}
|
||||||
|
enterKeyHint="done"
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { setIsoData } from "@utils/app";
|
||||||
import { capitalizeFirstLetter, validEmail } from "@utils/helpers";
|
import { capitalizeFirstLetter, validEmail } from "@utils/helpers";
|
||||||
import { Component, linkEvent } from "inferno";
|
import { Component, linkEvent } from "inferno";
|
||||||
import { GetSiteResponse } from "lemmy-js-client";
|
import { GetSiteResponse } from "lemmy-js-client";
|
||||||
import { HttpService, I18NextService, UserService } from "../../services";
|
import { HttpService, I18NextService } from "../../services";
|
||||||
import { toast } from "../../toast";
|
import { toast } from "../../toast";
|
||||||
import { HtmlTags } from "../common/html-tags";
|
import { HtmlTags } from "../common/html-tags";
|
||||||
import { Spinner } from "../common/icon";
|
import { Spinner } from "../common/icon";
|
||||||
|
@ -30,12 +30,6 @@ export class LoginReset extends Component<any, State> {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
if (UserService.Instance.myUserInfo) {
|
|
||||||
this.context.router.history.push("/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get documentTitle(): string {
|
get documentTitle(): string {
|
||||||
return `${capitalizeFirstLetter(
|
return `${capitalizeFirstLetter(
|
||||||
I18NextService.i18n.t("forgot_password"),
|
I18NextService.i18n.t("forgot_password"),
|
||||||
|
|
|
@ -124,13 +124,6 @@ export class Login extends Component<
|
||||||
this.handleSubmitTotp = this.handleSubmitTotp.bind(this);
|
this.handleSubmitTotp = this.handleSubmitTotp.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
// Navigate to home if already logged in
|
|
||||||
if (UserService.Instance.myUserInfo) {
|
|
||||||
this.context.router.history.push("/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get documentTitle(): string {
|
get documentTitle(): string {
|
||||||
return `${I18NextService.i18n.t("login")} - ${
|
return `${I18NextService.i18n.t("login")} - ${
|
||||||
this.state.siteRes.site_view.site.name
|
this.state.siteRes.site_view.site.name
|
||||||
|
|
|
@ -54,6 +54,7 @@ import updateCommunityBlock from "./update-community-block";
|
||||||
import updatePersonBlock from "./update-person-block";
|
import updatePersonBlock from "./update-person-block";
|
||||||
import instanceToChoice from "./instance-to-choice";
|
import instanceToChoice from "./instance-to-choice";
|
||||||
import updateInstanceBlock from "./update-instance-block";
|
import updateInstanceBlock from "./update-instance-block";
|
||||||
|
import isAnonymousPath from "./is-anonymous-path";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
buildCommentsTree,
|
buildCommentsTree,
|
||||||
|
@ -112,4 +113,5 @@ export {
|
||||||
updatePersonBlock,
|
updatePersonBlock,
|
||||||
instanceToChoice,
|
instanceToChoice,
|
||||||
updateInstanceBlock,
|
updateInstanceBlock,
|
||||||
|
isAnonymousPath,
|
||||||
};
|
};
|
||||||
|
|
5
src/shared/utils/app/is-anonymous-path.ts
Normal file
5
src/shared/utils/app/is-anonymous-path.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
export default function isAnonymousPath(pathname: string) {
|
||||||
|
return /^\/(login.*|signup|password_change.*|verify_email.*)\b/g.test(
|
||||||
|
pathname,
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in a new issue