diff --git a/src/components/structures/HostSignupAction.tsx b/src/components/structures/HostSignupAction.tsx index 266114bb2a..3044cab7d3 100644 --- a/src/components/structures/HostSignupAction.tsx +++ b/src/components/structures/HostSignupAction.tsx @@ -20,7 +20,7 @@ import { IconizedContextMenuOptionList, } from "../views/context_menus/IconizedContextMenu"; import { _t } from "../../languageHandler"; -import { OwnProfileStore } from "../../stores/OwnProfileStore"; +import { HostSignupStore } from "../../stores/HostSignupStore"; interface IProps {} @@ -28,7 +28,7 @@ interface IState {} export default class HostSignupAction extends React.PureComponent { private openDialog = async () => { - await OwnProfileStore.instance.setHostSignupActive(true); + await HostSignupStore.instance.setHostSignupActive(true); } public render(): React.ReactNode { diff --git a/src/components/views/dialogs/HostSignupDialog.tsx b/src/components/views/dialogs/HostSignupDialog.tsx index b9dbcfcbcf..fabfdb07f5 100644 --- a/src/components/views/dialogs/HostSignupDialog.tsx +++ b/src/components/views/dialogs/HostSignupDialog.tsx @@ -21,6 +21,7 @@ import QuestionDialog from './QuestionDialog'; import SdkConfig from "../../../SdkConfig"; import {_t} from "../../../languageHandler"; import {MatrixClientPeg} from "../../../MatrixClientPeg"; +import {HostSignupStore} from "../../../stores/HostSignupStore"; import {OwnProfileStore} from "../../../stores/OwnProfileStore"; import {IPostmessage, IPostmessageResponseData, PostmessageAction} from "./HostSignupDialogTypes"; @@ -72,8 +73,7 @@ export default class HostSignupDialog extends React.PureComponent { + private onFinished = async (result: boolean) => { if (result || this.state.completed) { // We're done, close return this.closeDialog(); @@ -153,7 +153,7 @@ export default class HostSignupDialog extends React.PureComponent { - const [isActive, setIsActive] = useState(OwnProfileStore.instance.isHostSignupActive); - useEventEmitter(OwnProfileStore.instance, UPDATE_EVENT, () => { - setIsActive(OwnProfileStore.instance.isHostSignupActive); + const [isActive, setIsActive] = useState(HostSignupStore.instance.isHostSignupActive); + useEventEmitter(HostSignupStore.instance, UPDATE_EVENT, () => { + setIsActive(HostSignupStore.instance.isHostSignupActive); }); return
diff --git a/src/stores/HostSignupStore.ts b/src/stores/HostSignupStore.ts new file mode 100644 index 0000000000..d50a7f6b43 --- /dev/null +++ b/src/stores/HostSignupStore.ts @@ -0,0 +1,49 @@ +/* +Copyright 2021 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import defaultDispatcher from "../dispatcher/dispatcher"; +import {AsyncStore} from "./AsyncStore"; +import {ActionPayload} from "../dispatcher/payloads"; + +interface IState { + hostSignupActive?: boolean; +} + +export class HostSignupStore extends AsyncStore { + private static internalInstance = new HostSignupStore(); + + private constructor() { + super(defaultDispatcher, {hostSignupActive: false}); + } + + public static get instance(): HostSignupStore { + return HostSignupStore.internalInstance; + } + + public get isHostSignupActive(): boolean { + return this.state.hostSignupActive; + } + + public async setHostSignupActive(status: boolean) { + return this.updateState({ + hostSignupActive: status, + }); + } + + protected onDispatch(payload: ActionPayload) { + // Nothing to do + } +} diff --git a/src/stores/OwnProfileStore.ts b/src/stores/OwnProfileStore.ts index 7a674151d1..8983380fec 100644 --- a/src/stores/OwnProfileStore.ts +++ b/src/stores/OwnProfileStore.ts @@ -26,7 +26,6 @@ import { _t } from "../languageHandler"; interface IState { displayName?: string; avatarUrl?: string; - hostSignupActive?: boolean; } export class OwnProfileStore extends AsyncStoreWithClient { @@ -42,16 +41,6 @@ export class OwnProfileStore extends AsyncStoreWithClient { return OwnProfileStore.internalInstance; } - public get isHostSignupActive(): boolean { - return this.state.hostSignupActive; - } - - public async setHostSignupActive(status: boolean) { - await this.updateState({ - hostSignupActive: status, - }); - } - /** * Gets the display name for the user, or null if not present. */