import { IconDefinition } from "@fortawesome/fontawesome-svg-core"; import { faSpinner } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { FunctionComponent, MouseEvent, PropsWithChildren, useCallback, useState, } from "react"; import { Button } from "react-bootstrap"; interface CHButtonProps { disabled?: boolean; hidden?: boolean; icon: IconDefinition; updating?: boolean; updatingIcon?: IconDefinition; onClick?: (e: MouseEvent) => void; } const ContentHeaderButton: FunctionComponent = (props) => { const { children, icon, disabled, updating, updatingIcon, onClick } = props; let displayIcon = icon; if (updating) { displayIcon = updatingIcon ? updatingIcon : faSpinner; } return ( ); }; type CHAsyncButtonProps Promise> = { promise: T; onSuccess?: (item: R) => void; } & Omit; export function ContentHeaderAsyncButton Promise>( props: PropsWithChildren> ): JSX.Element { const { promise, onSuccess, ...button } = props; const [updating, setUpdate] = useState(false); const click = useCallback(() => { setUpdate(true); promise().then((val) => { setUpdate(false); onSuccess && onSuccess(val); }); }, [onSuccess, promise]); return ( ); } export default ContentHeaderButton;