Files
ThreadNet-Web/apps/web/src/components/structures/NonUrgentToastContainer.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
1.6 KiB
TypeScript
Raw Normal View History

2020-07-29 12:43:35 -06:00
/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
2020-07-29 12:43:35 -06:00
Copyright 2020 The Matrix.org Foundation C.I.C.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
2024-09-09 14:57:16 +01:00
Please see LICENSE files in the repository root for full details.
2020-07-29 12:43:35 -06:00
*/
2025-03-19 10:39:52 +00:00
import React from "react";
2025-02-05 13:25:06 +00:00
import { type EmptyObject } from "matrix-js-sdk/src/matrix";
2021-10-22 17:23:32 -05:00
2025-02-05 13:25:06 +00:00
import { type ComponentClass } from "../../@types/common";
2020-07-29 12:43:35 -06:00
import NonUrgentToastStore from "../../stores/NonUrgentToastStore";
import { UPDATE_EVENT } from "../../stores/AsyncStore";
interface IState {
2021-07-01 23:23:03 +01:00
toasts: ComponentClass[];
2020-07-29 12:43:35 -06:00
}
export default class NonUrgentToastContainer extends React.PureComponent<EmptyObject, IState> {
public constructor(props: EmptyObject) {
2023-02-13 11:39:16 +00:00
super(props);
2020-07-29 12:43:35 -06:00
this.state = {
toasts: NonUrgentToastStore.instance.components,
};
}
2020-07-29 12:43:35 -06:00
public componentDidMount(): void {
2020-07-29 12:43:35 -06:00
NonUrgentToastStore.instance.on(UPDATE_EVENT, this.onUpdateToasts);
}
public componentWillUnmount(): void {
2020-07-29 12:43:35 -06:00
NonUrgentToastStore.instance.off(UPDATE_EVENT, this.onUpdateToasts);
}
private onUpdateToasts = (): void => {
2021-06-29 13:11:58 +01:00
this.setState({ toasts: NonUrgentToastStore.instance.components });
2020-07-29 12:43:35 -06:00
};
public render(): React.ReactNode {
2020-07-29 12:43:35 -06:00
const toasts = this.state.toasts.map((t, i) => {
return (
<div className="mx_NonUrgentToastContainer_toast" key={`toast-${i}`}>
{React.createElement(t, {})}
2020-07-29 12:43:35 -06:00
</div>
);
});
return (
<div className="mx_NonUrgentToastContainer" role="alert">
{toasts}
2020-07-29 12:43:35 -06:00
</div>
);
}
}