add id to toast

pull/5370/head
filip mertens 2 years ago committed by Aniket
parent 6f07f8fc97
commit 6a427ea9eb
  1. 4
      apps/remix-ide/src/app/plugins/notification.tsx
  2. 2
      libs/remix-ui/app/src/lib/remix-app/actions/modals.ts
  3. 2
      libs/remix-ui/app/src/lib/remix-app/components/modals/dialogs.tsx
  4. 4
      libs/remix-ui/app/src/lib/remix-app/context/context.tsx
  5. 4
      libs/remix-ui/app/src/lib/remix-app/context/provider.tsx
  6. 4
      libs/remix-ui/app/src/lib/remix-app/interface/index.ts
  7. 3
      libs/remix-ui/app/src/lib/remix-app/reducer/modals.ts
  8. 5
      libs/remix-ui/toaster/src/lib/toaster.tsx

@ -38,7 +38,7 @@ export class NotificationPlugin extends Plugin implements MethodApi<INotificatio
return this.dispatcher.alert(args) return this.dispatcher.alert(args)
} }
async toast (message: string | JSX.Element) { async toast (message: string | JSX.Element, uid?: string | number) {
this.dispatcher.toast(message) this.dispatcher.toast(message, uid)
} }
} }

@ -22,7 +22,7 @@ export const enum modalActionTypes {
type ModalPayload = { type ModalPayload = {
[modalActionTypes.setModal]: AppModal [modalActionTypes.setModal]: AppModal
[modalActionTypes.handleHideModal]: any [modalActionTypes.handleHideModal]: any
[modalActionTypes.setToast]: string | JSX.Element [modalActionTypes.setToast]: { message: string | JSX.Element, uid: string | number }
[modalActionTypes.handleToaster]: any, [modalActionTypes.handleToaster]: any,
[modalActionTypes.processQueue]: any [modalActionTypes.processQueue]: any
} }

@ -10,7 +10,7 @@ const AppDialogs = () => {
return ( return (
<> <>
<ModalWrapper {...focusModal} handleHide={handleHideModal}></ModalWrapper> <ModalWrapper {...focusModal} handleHide={handleHideModal}></ModalWrapper>
<Toaster message={focusToaster} handleHide={handleToaster} /> <Toaster message={focusToaster.message} uid={focusToaster.uid} handleHide={handleToaster} />
</>) </>)
} }
export default AppDialogs export default AppDialogs

@ -6,7 +6,7 @@ export const AppContext = React.createContext<any>(null)
export interface dispatchModalInterface { export interface dispatchModalInterface {
modal: (data: AppModal) => void modal: (data: AppModal) => void
toast: (message: string | JSX.Element) => void toast: (message: string | JSX.Element, uid?:string | number) => void
alert: (data: AlertModal) => void alert: (data: AlertModal) => void
handleHideModal: () => void, handleHideModal: () => void,
handleToaster: () => void handleToaster: () => void
@ -14,7 +14,7 @@ export interface dispatchModalInterface {
export const dispatchModalContext = React.createContext<dispatchModalInterface>({ export const dispatchModalContext = React.createContext<dispatchModalInterface>({
modal: (data: AppModal) => { }, modal: (data: AppModal) => { },
toast: (message: string | JSX.Element) => {}, toast: (message: string | JSX.Element, uid?:string | number) => {},
alert: (data: AlertModal) => {}, alert: (data: AlertModal) => {},
handleHideModal: () => {}, handleHideModal: () => {},
handleToaster: () => {} handleToaster: () => {}

@ -36,10 +36,10 @@ export const ModalProvider = ({ children = [], reducer = modalReducer, initialSt
}) })
} }
const toast = (message: string | JSX.Element) => { const toast = (message: string | JSX.Element, uid?: string | number) => {
dispatch({ dispatch({
type: modalActionTypes.setToast, type: modalActionTypes.setToast,
payload: message payload: { message, uid }
}) })
} }

@ -33,7 +33,7 @@ export interface AlertModal {
export interface ModalState { export interface ModalState {
modals: AppModal[], modals: AppModal[],
toasters: (string | JSX.Element)[], toasters: {message: (string | JSX.Element), uid: string | number }[],
focusModal: AppModal, focusModal: AppModal,
focusToaster: string | JSX.Element focusToaster: {message: (string | JSX.Element), uid: string | number }
} }

@ -62,8 +62,7 @@ export const modalReducer = (state: ModalState = ModalInitialState, action: Moda
} }
case modalActionTypes.setToast: { case modalActionTypes.setToast: {
const toasterList = state.toasters.slice() const toasterList = state.toasters.slice()
const message = action.payload toasterList.push(action.payload)
toasterList.push(message)
if (toasterList.length === 1) { if (toasterList.length === 1) {
return { ...state, toasters: toasterList, focusToaster: action.payload } return { ...state, toasters: toasterList, focusToaster: action.payload }
} else { } else {

@ -7,7 +7,8 @@ import './toaster.css'
export interface ToasterProps { export interface ToasterProps {
message: string | JSX.Element message: string | JSX.Element
timeOut?: number, timeOut?: number,
handleHide?: () => void handleHide?: () => void,
uid?: string | number
} }
export const Toaster = (props: ToasterProps) => { export const Toaster = (props: ToasterProps) => {
@ -49,7 +50,7 @@ export const Toaster = (props: ToasterProps) => {
} }
}) })
} }
}, [props.message]) }, [props.message, props.uid])
useEffect(() => { useEffect(() => {
if (state.hiding) { if (state.hiding) {

Loading…
Cancel
Save