Skip to content

Commit

Permalink
add close button to error toast
Browse files Browse the repository at this point in the history
  • Loading branch information
mnholtz committed Nov 14, 2024
1 parent 2199aa3 commit d7a93eb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,29 @@
}

.error {
display: flex !important;
align-items: center;
color: #dc3545;
padding: 4px 8px;
font-size: 0.875rem;
position: absolute;
bottom: 4px;
left: 4px;

:global(.btn) {
margin-left: 8px;
color: #dc3545;
padding: 0;
border: none;
background-color: transparent;

&:focus,
&:active,
&:hover,
&:active:focus {
color: #dc3545;
background-color: transparent;
box-shadow: none !important;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ import React, { useState } from "react";
import Toolbar from "@/components/richTextEditor/toolbar/Toolbar";
import { type UUID } from "@/types/stringTypes";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faExclamationCircle } from "@fortawesome/free-solid-svg-icons";
import {
faExclamationCircle,
faTimes,
} from "@fortawesome/free-solid-svg-icons";
import ErrorContext from "@/components/richTextEditor/ErrorContext";
import { Toast } from "react-bootstrap";
import { Button, Toast } from "react-bootstrap";

type EditorProps = EditorProviderProps & {
// A PixieBrix asset database ID to use for uploading images. If not included, the image extension will be disabled.
Expand Down Expand Up @@ -71,7 +74,22 @@ const RichTextEditor: React.FunctionComponent<EditorProps> = ({
]}
slotBefore={<Toolbar />}
slotAfter={
<Toast show={Boolean(error)} onClose={() => {setError(null)}} className={styles.error} autohide><FontAwesomeIcon icon={faExclamationCircle} /> {error}</Toast>
<Toast
show={Boolean(error)}
onClose={() => {
setError(null);
}}
className={styles.error}
autohide
animation={false}
delay={5000}
>
<FontAwesomeIcon className="mr-2" icon={faExclamationCircle} />{" "}
{error}
<Button variant="outline-danger" onClick={() => setError(null)}>
<FontAwesomeIcon icon={faTimes} />
</Button>
</Toast>
}
{...props}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { faImage } from "@fortawesome/free-solid-svg-icons";
import { assertNotNullish } from "@/utils/nullishUtils";
import useUploadAsset from "@/components/richTextEditor/toolbar/ImageButton/useUploadAsset";
import { validateUUID } from "@/types/helpers";
import {useShowError} from "@/components/richTextEditor/ErrorContext";
import { useShowError } from "@/components/richTextEditor/ErrorContext";

const getAssetDatabaseId = (editor: Editor) => {
const imageExtension = editor.options.extensions.find(
Expand Down Expand Up @@ -71,9 +71,7 @@ const ImageButton: React.FunctionComponent = () => {
.setImage({ src: downloadUrl.href, alt: "" })
.run();
} catch (error) {
// TODO: Implement error message handling in UI
setError("Failed to upload image asset, try again");

setError("Failed to upload image, try again");
reportError(
new Error("Failed to upload image asset", {
cause: error,
Expand Down

0 comments on commit d7a93eb

Please sign in to comment.