Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEV][Playground] remove switch case in ToastManager return #2009

Closed
wants to merge 6 commits into from
Closed
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
55 changes: 23 additions & 32 deletions src/renderer/common/components/toast/ToastManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

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 { ToastState } from "readium-desktop/common/redux/states/toast";
import * as stylesToasts from "readium-desktop/renderer/assets/styles/components/toasts.css";
import { v4 as uuidv4 } from "uuid";

import { TranslatorProps, withTranslator } from "../hoc/translator";
import Toast from "./Toast";
import { ToastType } from "readium-desktop/common/models/toast";

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface IBaseProps extends TranslatorProps {
Expand Down Expand Up @@ -57,42 +57,33 @@ export class ToastManager extends React.Component<IProps, IState> {

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) {
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}
key={id}
close={ () => this.close(id) }
type={toast.type}
displaySystemNotification={false}
/>;
case ToastType.Error:
return <Toast

return (
<div className={stylesToasts.toasts_wrapper}>
{Object.keys(toastList).map((id: string) => {
const toast = toastList[id];
if (toast) {
switch (toast.type) {
case ToastType.Success:
case ToastType.Default:
case ToastType.Error:
return (
<Toast
message={toast.data}
key={id}
close={ () => this.close(id) }
close={() => this.close(id)}
type={toast.type}
displaySystemNotification={false}
/>;
default:
return (<></>);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, you change the logic of the component. If toastType is undefined for example the component will be render with <></> (empty jsx tag) but in your change, you return undefined and not a jsx tag

/>
);
default:
return <></>;
}
}
}
return undefined;
})}
</div>;
return undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not return undefined but an empty jsx tag

})}
</div>
);
}

private close(id: string) {
Expand Down