From 6d58e6793d40df4fec518f37351868803a02a033 Mon Sep 17 00:00:00 2001 From: Rémy Raes Date: Mon, 10 Apr 2023 14:25:32 +0200 Subject: refactor: Notifications (#259) * feat: wrap ElNotification class in a showNotification method * refactor: replace notification invocations in mod views * feat: add 'info' type to showNotification method * refactor: replace notification invocations in repair view * refactor: replace notification invocations in settings view * refactor: replace notification invocations in developer view * feat: showNotification method now returns a NotificationHandle * feat: showNotification has a duration argument * refactor: replace notification invocations in pull requests module * refactor: replace notification invocation in repair view * refactor: replace notification invocations in UI store * refactor: remove unused import from play view * refactor: use showErrorNotification method to wrap up error display * fix: add missing showErrorNotification imports * style: format code * style: format ThunderstoreModCard.vue * style: format pull_requests.ts * style: format SettingsView.vue * style: format RepairView.vue * style: format DeveloperView.vue * refactor: remove useless import * refactor: add missing showErrorNotification invocation * feat: showErrorNotification has an optional title argument * style: format LocalModsView.vue --- src-vue/src/utils/ui.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src-vue/src/utils/ui.ts (limited to 'src-vue/src/utils') diff --git a/src-vue/src/utils/ui.ts b/src-vue/src/utils/ui.ts new file mode 100644 index 00000000..b84d7666 --- /dev/null +++ b/src-vue/src/utils/ui.ts @@ -0,0 +1,29 @@ +import { ElNotification, NotificationHandle } from "element-plus"; +import { i18n } from "../main"; + +/** + * Displays content to the user in the form of a notification appearing on screen bottom right. + **/ +function showNotification( + title: string, + message: string = '', + type: 'success' | 'warning' | 'error' | 'info' = 'success', + duration: number = 4500 +): NotificationHandle { + return ElNotification({ + title, message, type, duration, + position: 'bottom-right', + }); +} + +/** + * Helper method displaying an error message to the user. + **/ +function showErrorNotification( + error: string, + title: string = i18n.global.tc('generic.error') +): NotificationHandle { + return showNotification(title, error, 'error'); +} + +export {showNotification, showErrorNotification}; -- cgit v1.2.3