WebUI QoL improvements.

This commit is contained in:
Abdulmhsen B. A. A.
2024-07-05 01:04:57 +03:00
parent e678e4747e
commit 4687279b9f
4 changed files with 123 additions and 40 deletions

View File

@@ -273,13 +273,19 @@ const formatDuration = (milliseconds) => {
return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
}
const copyText = (str) => {
const copyText = (str, showNotification = true) => {
if (navigator.clipboard) {
navigator.clipboard.writeText(str).then(() => {
notification('success', 'Success', 'Report has been copied to clipboard.')
if (!showNotification) {
return
}
notification('success', 'Success', 'Text copied to clipboard.')
}).catch((error) => {
console.error('Failed to copy: ', error)
notification('error', 'Error', 'Failed to copy to clipboard.')
if (!showNotification) {
return
}
notification('error', 'Error', 'Failed to copy text to clipboard.')
});
return
}
@@ -290,7 +296,9 @@ const copyText = (str) => {
el.select()
document.execCommand('copy')
document.body.removeChild(el)
if (!showNotification) {
return
}
notification('success', 'Success', 'Text copied to clipboard.')
}