MCPcopy
hub / github.com/refined-github/refined-github / finalUpdateToast

Function finalUpdateToast

source/github-helpers/toast.tsx:56–76  ·  view source on GitHub ↗
(newMessage: ToastMessage | Error)

Source from the content-addressed store, hash-verified

54 };
55
56 const finalUpdateToast = async (newMessage: ToastMessage | Error): Promise<void> => {
57 if (newMessage instanceof Error && 'richMessage' in newMessage && newMessage.richMessage) {
58 newMessage = newMessage.richMessage as ToastMessage;
59 } else if (newMessage instanceof Error) {
60 newMessage = newMessage.message;
61 }
62
63 updateToast(newMessage);
64
65 // Without rAF the toast might be removed before the first page paint
66 // rAF also allows showToast to resolve as soon as task is done
67 await frame();
68
69 const displayTime = (typeof newMessage === 'string' ? newMessage.split(' ').length * 300 : 3000) + 2000;
70 await delay(displayTime);
71
72 // Display time is over, animate out
73 toast.classList.replace('Toast--animateIn', 'Toast--animateOut');
74 await oneEvent(toast, 'animationend');
75 toast.remove();
76 };
77
78 document.body.append(toast);
79 await delay(30); // Without this, the Toast doesn't appear in time

Callers 1

showToastFunction · 0.85

Calls 5

updateToastFunction · 0.85
frameFunction · 0.85
delayFunction · 0.85
replaceMethod · 0.80
removeMethod · 0.80

Tested by

no test coverage detected