-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#2174: Replace unmaintained react-toast-notifications
(and use one style for all toasts)
#2836
Changes from 12 commits
d25e72a
ba8a251
5d15dfd
d86906f
fead813
fa9685a
26808c8
c0f6dcb
aea6a63
5435bd9
7c3b739
27b64dc
3907d04
1e420d8
fc8c8fa
8a54ce3
12196f8
4394530
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,7 @@ import browser, { Menus, Tabs } from "webextension-polyfill"; | |
import { getErrorMessage, hasCancelRootCause } from "@/errors"; | ||
import reportError from "@/telemetry/reportError"; | ||
import { noop } from "lodash"; | ||
import { | ||
handleMenuAction, | ||
showNotification, | ||
} from "@/contentScript/messenger/api"; | ||
import { handleMenuAction, notify } from "@/contentScript/messenger/api"; | ||
import { ensureContentScript } from "@/background/util"; | ||
import { reportEvent } from "@/telemetry/events"; | ||
import { UUID, IExtension, ResolvedExtension } from "@/core"; | ||
|
@@ -95,21 +92,16 @@ async function dispatchMenu( | |
extensionId: info.menuItemId.slice(MENU_PREFIX.length) as UUID, | ||
args: info, | ||
}); | ||
void showNotification(target, { | ||
message: "Ran content menu item action", | ||
type: "success", | ||
}); | ||
notify.success(target, "Ran content menu item action"); | ||
} catch (error) { | ||
if (hasCancelRootCause(error)) { | ||
void showNotification(target, { | ||
message: "The action was cancelled", | ||
}); | ||
notify.info(target, "The action was cancelled"); | ||
} else { | ||
const message = `Error handling context menu action: ${getErrorMessage( | ||
error | ||
)}`; | ||
reportError(new Error(message)); | ||
void showNotification(target, { message, type: "error" }); | ||
reportError(error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we want to report the original error here. The stack trace will point to this block anyway, but its origin will be better defined. Here it's called explicitly because the messaging API does not automatically serialize errors, especially deep inside other objects. |
||
notify.error(target, { message, reportError: false }); | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ import type { MessageLevel } from "@/background/logging"; | |
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { faSync, faTrash } from "@fortawesome/free-solid-svg-icons"; | ||
import React, { useCallback } from "react"; | ||
import { useToasts } from "react-toast-notifications"; | ||
import notify from "@/utils/notify"; | ||
import AsyncButton from "@/components/AsyncButton"; | ||
import Pagination from "@/components/pagination/Pagination"; | ||
|
||
|
@@ -48,30 +48,22 @@ const LogToolbar: React.FunctionComponent<{ | |
// Don't support "trace" by default | ||
levelOptions = ["debug", "info", "warn", "error"], | ||
}) => { | ||
const { addToast } = useToasts(); | ||
|
||
const onClear = () => { | ||
try { | ||
clear(); | ||
addToast("Cleared the log entries for this extension", { | ||
appearance: "success", | ||
autoDismiss: true, | ||
}); | ||
} catch { | ||
addToast("Error clearing log entries for extension", { | ||
appearance: "error", | ||
autoDismiss: true, | ||
notify.success("Cleared the log entries for this extension"); | ||
} catch (error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error was not reported, now it is. |
||
notify.error({ | ||
message: "Error clearing log entries for extension", | ||
error, | ||
}); | ||
} | ||
}; | ||
|
||
const onRefresh = useCallback(() => { | ||
refresh(); | ||
addToast("Refreshed the log entries", { | ||
appearance: "success", | ||
autoDismiss: true, | ||
}); | ||
}, [refresh, addToast]); | ||
notify.success("Refreshed the log entries"); | ||
}, [refresh]); | ||
|
||
return ( | ||
<div className="px-3 pt-2"> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API improvement: Either call it with a plain string or provide a regular
Notification
object.Pros:
{ error }
wrapunknown
as the first parameter ofnotify.error
just to allownotify.error(new Error())
Cons:
message:
if you need to include theerror
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we have the budget for the extra storage