diff --git a/src/shared/components/app/app.tsx b/src/shared/components/app/app.tsx index b2f0df43..323be486 100644 --- a/src/shared/components/app/app.tsx +++ b/src/shared/components/app/app.tsx @@ -1,4 +1,4 @@ -import { isAuthPath, setIsoData } from "@utils/app"; +import { isAnonymousPath, isAuthPath, setIsoData } from "@utils/app"; import { dataBsTheme } from "@utils/browser"; import { Component, RefObject, createRef, linkEvent } from "inferno"; import { Provider } from "inferno-i18next-dess"; @@ -14,6 +14,7 @@ import { Footer } from "./footer"; import { Navbar } from "./navbar"; import "./styles.scss"; import { Theme } from "./theme"; +import AnonymousGuard from "../common/anonymous-guard"; interface AppProps { user?: MyUserInfo; @@ -78,6 +79,10 @@ export class App extends Component { + ) : isAnonymousPath(path ?? "") ? ( + + + ) : ( ))} diff --git a/src/shared/components/common/anonymous-guard.tsx b/src/shared/components/common/anonymous-guard.tsx new file mode 100644 index 00000000..70a1f7aa --- /dev/null +++ b/src/shared/components/common/anonymous-guard.tsx @@ -0,0 +1,31 @@ +import { Component } from "inferno"; +import { UserService } from "../../services"; +import { Spinner } from "./icon"; + +interface AnonymousGuardState { + hasRedirected: boolean; +} + +class AnonymousGuard extends Component { + 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 : ; + } +} + +export default AnonymousGuard; diff --git a/src/shared/components/common/subscribe-button.tsx b/src/shared/components/common/subscribe-button.tsx index 9ae4426f..58195391 100644 --- a/src/shared/components/common/subscribe-button.tsx +++ b/src/shared/components/common/subscribe-button.tsx @@ -201,6 +201,8 @@ class RemoteFetchModal extends Component< value={this.state.instanceText} onInput={linkEvent(this, handleInput)} required + enterKeyHint="go" + inputMode="url" />