Skip to content

Commit

Permalink
feat: create prop for Notification; small readability changes
Browse files Browse the repository at this point in the history
  • Loading branch information
asharonbaltazar committed Dec 7, 2022
1 parent 3db1ff2 commit add3075
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type NotificationType = "success" | "error";
export type Notification = {
text: string;
type: NotificationType;
timeoutMs?: number;
};

type NotificationContextState = {
Expand Down Expand Up @@ -36,14 +37,20 @@ const NotificationProvider = ({ children }: NotificationProviderProps) => {
return setNotifications([]);
};

const createNotification = ({ text, type = "success" }: Notification) => {
const createNotification = ({
text,
type = "success",
timeoutMs = 2000,
}: Notification) => {
const doesNotifExist = notifications.some((notif) => notif.text === text);

if (doesNotifExist) {
return;
}

return setNotifications((state) => [...state, { text, type }]);
const newNotification: Notification = { text, type, timeoutMs };

return setNotifications((state) => [...state, newNotification]);
};

return (
Expand Down

0 comments on commit add3075

Please sign in to comment.