Skip to content

Commit f6034b2

Browse files
committed
show duplicate number
1 parent d4bd99b commit f6034b2

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

web_src/css/modules/animations.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ code.language-math.is-loading::after {
9797
transform: scale(1);
9898
}
9999
50% {
100-
transform: scale(1.8);
100+
transform: scale(1.5);
101101
}
102102
100% {
103103
transform: scale(1);
104104
}
105105
}
106106

107107
.pulse {
108-
animation: pulse 2s linear;
108+
animation: pulse 200ms linear;
109109
}
110110

111111
.ui.modal,

web_src/css/modules/toast.css

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,23 @@
2929
background: transparent;
3030
border: none;
3131
display: flex;
32-
width: 30px;
33-
height: 30px;
32+
min-width: 30px;
33+
min-height: 30px;
3434
justify-content: center;
3535
align-items: center;
3636
}
3737

38+
.toast-duplicate-number::before {
39+
content: '(';
40+
}
41+
.toast-duplicate-number {
42+
display: inline-flex;
43+
margin: 0 2px;
44+
}
45+
.toast-duplicate-number::after {
46+
content: ')';
47+
}
48+
3849
.toast-close:hover {
3950
background: var(--color-hover);
4051
}

web_src/js/modules/toast.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {htmlEscape} from 'escape-goat';
22
import {svg} from '../svg.js';
3-
import Toastify from 'toastify-js'; // don't use "async import", because when network error occurs, the "async import" also fails and nothing is shown
3+
import Toastify from 'toastify-js';
4+
import {showElem} from "../utils/dom.js"; // don't use "async import", because when network error occurs, the "async import" also fails and nothing is shown
45

56
const levels = {
67
info: {
@@ -27,17 +28,23 @@ function showToast(message, level, {gravity, position, duration, useHtmlBody, pr
2728

2829
// prevent showing duplicate toasts with same level and message, hide all existing toasts with same key
2930
if (preventDuplicates) {
30-
const toastElements = document.querySelectorAll(`.toastify[data-toast-unique-key="${CSS.escape(key)}"]`);
31-
for (const el of toastElements) {
32-
el.remove(); // "hideToast" only removes the toast after an unchangeable delay, so we need to remove it immediately to make the "reposition" work with new toasts
33-
el._toastInst?.hideToast();
31+
const toastEl = document.querySelector(`.toastify[data-toast-unique-key="${CSS.escape(key)}"]`);
32+
if (toastEl) {
33+
const toastDupNumEl = toastEl.querySelector('.toast-duplicate-number');
34+
showElem(toastDupNumEl);
35+
toastDupNumEl.textContent = String(Number(toastDupNumEl.textContent) + 1);
36+
toastDupNumEl.classList.remove('pulse');
37+
requestAnimationFrame(() => {
38+
toastDupNumEl.classList.add('pulse');
39+
});
40+
return;
3441
}
3542
}
3643

3744
const {icon, background, duration: levelDuration} = levels[level ?? 'info'];
3845
const toast = Toastify({
3946
text: `
40-
<div class='toast-icon'>${svg(icon)}</div>
47+
<div class='toast-icon'>${svg(icon)}<span class="toast-duplicate-number tw-hidden">1</span></div>
4148
<div class='toast-body'>${body}</div>
4249
<button class='toast-close'>${svg('octicon-x')}</button>
4350
`,

0 commit comments

Comments
 (0)