From 1b8e9d8d328d842a42356de431a93cb835e4a8b5 Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 22 Jun 2023 23:06:22 +0200 Subject: [PATCH] add warning toast --- templates/devtest/gitea-ui.tmpl | 8 ++++++-- web_src/js/modules/toast.js | 10 ++++++++++ web_src/js/modules/toast.test.js | 11 ++++++++--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/templates/devtest/gitea-ui.tmpl b/templates/devtest/gitea-ui.tmpl index 5c45d54d8fcab..ae568a4c346cd 100644 --- a/templates/devtest/gitea-ui.tmpl +++ b/templates/devtest/gitea-ui.tmpl @@ -232,14 +232,18 @@

Toast

+
diff --git a/web_src/js/modules/toast.js b/web_src/js/modules/toast.js index 33e564282e4c1..a15c4914b405f 100644 --- a/web_src/js/modules/toast.js +++ b/web_src/js/modules/toast.js @@ -7,6 +7,11 @@ const levels = { background: 'var(--color-green)', duration: 2000, }, + warning: { + icon: 'gitea-exclamation', + background: 'var(--color-orange)', + duration: -1, // needs to be clicked away + }, error: { icon: 'gitea-exclamation', background: 'var(--color-red)', @@ -47,6 +52,10 @@ export async function showInfo(message, opts) { return await showToast(message, 'info', opts); } +export async function showWarning(message, opts) { + return await showToast(message, 'warning', opts); +} + export async function showError(message, opts) { return await showToast(message, 'error', opts); } @@ -54,5 +63,6 @@ export async function showError(message, opts) { // export for devtest page in development if (process.env.NODE_ENV === 'development') { window.giteaShowInfo = showInfo; + window.giteaShowWarning = showWarning; window.giteaShowError = showError; } diff --git a/web_src/js/modules/toast.test.js b/web_src/js/modules/toast.test.js index 6c35451a8f987..9c6d938be19cc 100644 --- a/web_src/js/modules/toast.test.js +++ b/web_src/js/modules/toast.test.js @@ -1,12 +1,17 @@ import {test, expect} from 'vitest'; -import {showInfo, showError} from './toast.js'; +import {showInfo, showError, showWarning} from './toast.js'; test('showInfo', async () => { - await showInfo('success :)', {duration: -1}); + await showInfo('success 😀', {duration: -1}); + expect(document.querySelector('.toastify')).toBeTruthy(); +}); + +test('showWarning', async () => { + await showWarning('success 😐', {duration: -1}); expect(document.querySelector('.toastify')).toBeTruthy(); }); test('showError', async () => { - await showError('error :(', {duration: -1}); + await showError('error 🙁', {duration: -1}); expect(document.querySelector('.toastify')).toBeTruthy(); });