Skip to content

Commit

Permalink
Merge pull request #20 from emilkowalski/fix-promise-data
Browse files Browse the repository at this point in the history
Pass props correctly
  • Loading branch information
emilkowalski authored Mar 3, 2023
2 parents 2cf3526 + 08a7888 commit 5d913fa
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
14 changes: 9 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';

import './styles.css';
import { getAsset, Loader } from './assets';
import { HeightT, Position, ToastT, ToastToDismiss } from './types';
import { HeightT, Position, PromiseData, ToastT, ToastToDismiss } from './types';
import { ToastState, toast } from './state';

// Visible toasts amount
Expand Down Expand Up @@ -202,17 +202,21 @@ const Toast = (props: ToastProps) => {
}, [toast.delete]);

const promiseTitle = React.useMemo(() => {
const isPromise = (toast: ToastT): toast is PromiseData & { id: number } => Boolean(toast.promise);

if (!isPromise(toast)) return null;

switch (promiseStatus) {
case 'loading':
return toast.promiseData.loading;
return toast.loading;
case 'success':
return toast.promiseData.success;
return toast.success;
case 'error':
return toast.promiseData.error;
return toast.error;
default:
return null;
}
}, [toast.promiseData, promiseStatus]);
}, [promiseStatus]);

return (
<li
Expand Down
2 changes: 1 addition & 1 deletion src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Observer {

promise = (promise: PromiseT, data?: PromiseData) => {
const id = toastsCounter++;
this.publish({ promiseData: data, promise, id });
this.publish({ ...data, promise, id });
return id;
};

Expand Down
9 changes: 4 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React from 'react';

export type ToastTypes = 'normal' | 'action' | 'success' | 'error' | 'loading';

export type PromiseData = {
loading: string;
export type PromiseT = Promise<any> | (() => Promise<any>);

export type PromiseData = ExternalToast & {
loading: string | React.ReactNode;
success: string | React.ReactNode;
error: string | React.ReactNode;
};

export type PromiseT = Promise<any> | (() => Promise<any>);

export interface ToastT {
id: number;
title?: string | React.ReactNode;
Expand All @@ -30,7 +30,6 @@ export interface ToastT {
onClick?: () => void;
};
promise?: PromiseT;
promiseData?: PromiseData;
style?: React.CSSProperties;
className?: string;
descriptionClassName?: string;
Expand Down
2 changes: 1 addition & 1 deletion website/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,6 @@ code {

@media (max-width: 600px) {
.buttons {
mask-image: linear-gradient(to right, transparent, black 24px, black calc(100% - 24px), transparent);
mask-image: linear-gradient(to right, transparent, black 16px, black calc(100% - 16px), transparent);
}
}
7 changes: 7 additions & 0 deletions website/src/components/Footer/footer.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@
.p a:hover {
text-decoration: underline;
}

@media (max-width: 600px) {
.wrapper {
margin-top: 128px;
padding: 16px 0;
}
}

1 comment on commit 5d913fa

@vercel
Copy link

@vercel vercel bot commented on 5d913fa Mar 3, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.