-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: uptake of Seeds Toast component (#3962)
* Squashed commit of the following: commit d964056 Author: Jared White <[email protected]> Date: Mon Jan 22 15:41:22 2024 -0800 feat: adjust Seeds Toast inset commit 75b1e07 Author: Jared White <[email protected]> Date: Thu Jan 18 14:29:03 2024 -0800 test: get partners unit tests to pass commit af89871 Author: Jared White <[email protected]> Date: Wed Jan 17 22:18:31 2024 -0800 fix: more linting commit fca3211 Author: Jared White <[email protected]> Date: Wed Jan 17 21:50:21 2024 -0800 fix: another lint error commit 22243fe Author: Jared White <[email protected]> Date: Wed Jan 17 20:38:39 2024 -0800 fix: lint issues commit 1168e02 Author: Jared White <[email protected]> Date: Wed Jan 17 19:25:19 2024 -0800 feat: switch a number of site alert features to Toast commit 4309bda Author: Jared White <[email protected]> Date: Mon Jan 15 16:58:06 2024 -0800 feat: toast message context now working as expected commit 0835000 Author: Jared White <[email protected]> Date: Wed Jan 10 20:50:36 2024 -0800 chore: bump Seeds version commit 1feceb8 Merge: 5047464 dbcd45c Author: Jared White <[email protected]> Date: Wed Jan 10 20:37:42 2024 -0800 Merge commit 'dbcd45cf1060dc955e71e4dd11720c75a92efc3d' into 3434/react-context-messaging commit 5047464 Author: Morgan Ludtke <[email protected]> Date: Tue Oct 17 10:59:54 2023 -0500 fix: email csv fix commit 19cd8b2 Author: Morgan Ludtke <[email protected]> Date: Tue Oct 17 10:34:42 2023 -0500 fix: review comments commit fc220a7 Author: Morgan Ludtke <[email protected]> Date: Fri Oct 6 15:41:25 2023 -0500 fix: add comment commit 4aa3cfb Author: ColinBuyck <[email protected]> Date: Thu Jul 6 21:04:09 2023 -0700 fix: uptake toast component * feat: strip out old SiteAlert code in favor of toasts * fix: lint issues * fix: more linting * test: fix tests due to new Toasts * feat: fix some timing/context issues with Toast * fix: type error * fix: type error redux * fix: update React types to clean up false errors * fix: add back missing toast, use Seeds size tokens
- Loading branch information
1 parent
42b26e0
commit e7cf68d
Showing
59 changed files
with
286 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { FunctionComponent, createContext, createElement, useState, useRef } from "react" | ||
import { CommonMessageProps } from "@bloom-housing/ui-seeds/src/blocks/shared/CommonMessage" | ||
|
||
// TODO: this should be exportable from seeds directly | ||
interface ToastProps extends Omit<CommonMessageProps, "role" | "closeable"> { | ||
hideTimeout?: number | ||
} | ||
|
||
const defaultContext = { | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
addToast: (message: string, props: ToastProps): void => {}, | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
toastMessagesRef: {} as React.MutableRefObject<Record<string, any>[]>, | ||
} | ||
|
||
export const MessageContext = createContext(defaultContext) | ||
|
||
export const MessageProvider: FunctionComponent<React.PropsWithChildren> = ({ children }) => { | ||
const [_, setToastMessages] = useState<Record<string, any>[]>([]) | ||
const toastMessagesRef = useRef<Record<string, any>[]>([]) | ||
|
||
// Toast timeouts default to 5 seconds, unless otherwise specified in props | ||
const addToast = (message: string, props: ToastProps) => { | ||
const newMsg = { message, props: { hideTimeout: 5000, ...props }, timestamp: Date.now() } | ||
const msgs = [...toastMessagesRef.current, newMsg] | ||
|
||
// We need a stable ref so live toast messages can be read outside of this function | ||
toastMessagesRef.current = msgs | ||
setToastMessages(msgs) | ||
|
||
// Clean up messages after they're expired | ||
setTimeout(() => { | ||
toastMessagesRef.current = toastMessagesRef.current.filter( | ||
(msg) => msg.timestamp != newMsg.timestamp | ||
) | ||
}, newMsg.props.hideTimeout) | ||
} | ||
const contextValues = { | ||
addToast, | ||
toastMessagesRef, | ||
} | ||
return createElement( | ||
MessageContext.Provider, | ||
{ | ||
value: contextValues, | ||
}, | ||
|
||
children | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.