Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/renderer/common/components/toast/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ export class Toast extends React.Component<IProps, IState> {
public componentDidMount() {
this.triggerTimer(false);

if (this.ref?.current) {
this.ref?.current.addEventListener("transitionend", this.handleTransitionEnd, false);
}

// https://www.electronjs.org/docs/latest/tutorial/notifications
if (this.props.displaySystemNotification) {
new Notification(capitalizedAppName, {
Expand All @@ -103,10 +99,8 @@ export class Toast extends React.Component<IProps, IState> {
}
}

public componentWillRemove() {
if (this.ref?.current) {
this.ref?.current.removeEventListener("transitionend", this.handleTransitionEnd, false);
}
public componentWillUnmount() {
this.cancelTimer(false);
}

public render(): React.ReactElement<{}> {
Expand All @@ -132,6 +126,7 @@ export class Toast extends React.Component<IProps, IState> {

return (
<div
onTransitionEnd={this.handleTransitionEnd}
ref={this.ref}
onMouseMove={() => {
this.cancelTimer(false);
Expand Down
65 changes: 27 additions & 38 deletions src/renderer/common/components/toast/ToastManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import * as stylesToasts from "readium-desktop/renderer/assets/styles/components

import * as React from "react";
import { connect } from "react-redux";
import { ToastType } from "readium-desktop/common/models/toast";
import { IRendererCommonRootState } from "readium-desktop/common/redux/states/rendererCommonRootState";
import { IReaderRootState } from "readium-desktop/common/redux/states/renderer/readerRootState";
import { ToastState } from "readium-desktop/common/redux/states/toast";
Expand Down Expand Up @@ -51,56 +50,46 @@ export class ToastManager extends React.Component<IProps, IState> {
const { toast } = this.props;
if (toast !== oldProps.toast) {
const id = uuidv4();
const toastList = this.state.toastList;
toastList[id] = toast;
this.setState({toastList});
this.setState((prevState) => ({
toastList: {
...prevState.toastList,
[id]: toast,
},
}));
}
}

public render(): React.ReactElement<{}> {
const { toastList } = this.state;
return <div className={stylesToasts.toasts_wrapper}>
{ Object.keys(toastList).map((id: string) => {
const toast = toastList[id];
if (toast && (!toast?.publicationIdentifier || toast.publicationIdentifier === this.props.pubId)) {
switch (toast.type) {
case ToastType.Success:
return <Toast
message={toast.data}
key={id}
close={ () => this.close(id) }
type={toast.type}
displaySystemNotification={false}
/>;
case ToastType.Default:
return <Toast
message={toast.data}
const { pubId } = this.props;

return (
<div className={stylesToasts.toasts_wrapper}>
{Object.keys(toastList).map((id) => {
const toast = toastList[id];
if (toast && (!toast.publicationIdentifier || toast.publicationIdentifier === pubId)) {
return (
<Toast
key={id}
close={ () => this.close(id) }
type={toast.type}
displaySystemNotification={false}
/>;
case ToastType.Error:
return <Toast
id={id}
message={toast.data}
key={id}
close={ () => this.close(id) }
type={toast.type}
close={this.close}
displaySystemNotification={false}
/>;
default:
return (<></>);
/>
);
}
}
return undefined;
})}
</div>;
return null;
})}
</div>
);
}

private close(id: string) {
const { toastList } = this.state;
toastList[id] = undefined;
this.setState({ toastList });
this.setState((prevState) => {
const { [id]: _, ...rest } = prevState.toastList;
return { toastList: rest };
});
}
}

Expand Down
Loading