Mark toasts read before redirecting

This commit is contained in:
Maxime Lalo 2023-12-05 10:04:07 +01:00
parent b1410b9ea5
commit 8431e467bd
2 changed files with 11 additions and 6 deletions

View File

@ -38,6 +38,7 @@ class ToastElementClass extends React.Component<IPropsClass, IState> {
}
public override render(): JSX.Element {
console.log(this.props);
const toast = this.props.toast;
const style = {
"--data-duration": `${toast.time}ms`,
@ -98,7 +99,8 @@ class ToastElementClass extends React.Component<IPropsClass, IState> {
this.close();
}
private close() {
private async close() {
await Toasts.getInstance().markRead(this.props.toast);
window.clearTimeout(this.closeTimeout);
this.setState({
willClose: true,
@ -110,7 +112,7 @@ class ToastElementClass extends React.Component<IPropsClass, IState> {
private async handleClick(e: React.MouseEvent) {
if (this.props.toast.redirectUrl) {
this.onClose(e);
await this.onClose(e);
await this.props.router.push(this.props.toast.redirectUrl);
this.props.router.reload();
}

View File

@ -85,15 +85,18 @@ export default class Toasts {
return () => this.close(toast);
}
public markRead(toast: IToast) {
if (!toast.uid) return;
Notifications.getInstance().put(toast.uid, {
read: true,
});
}
public close(toast: IToast) {
const index = this.toastList.indexOf(toast);
if (index === -1) return;
this.toastList.splice(index, 1);
if (toast.uid)
Notifications.getInstance().put(toast.uid, {
read: true,
});
this.event.emit("change", this.toastList);
}