Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

add copy button to NoEvents

Blue Mouse4de9b2cb374b
diff --git a/src/pages/Project/View/components/NoEvents.jsx b/src/pages/Project/View/components/NoEvents.jsx
index fe9de55b3..5c1f27dca 100644
--- a/src/pages/Project/View/components/NoEvents.jsx
+++ b/src/pages/Project/View/components/NoEvents.jsx
@@ -1,7 +1,10 @@
-import React, { memo, useEffect } from 'react'
+import React, {
+ memo, useEffect, useState, useRef,
+} from 'react'
import { useTranslation, Trans } from 'react-i18next'
import { Link } from 'react-router-dom'
import Prism from 'prismjs'
+import { ClipboardDocumentIcon } from '@heroicons/react/24/outline'
import _isEmpty from 'lodash/isEmpty'
import PropTypes from 'prop-types'
@@ -22,10 +25,27 @@ const NoEvents = ({
filters, resetFilters, pid,
}) => {
const { t } = useTranslation('common')
+ const [copied, setCopied] = useState(false)
const umdBuildExample = getUMDBuildExample(pid)
+ const copyTimerRef = useRef(null)
+
+ const setToClipboard = (value) => {
+ if (!copied) {
+ navigator.clipboard.writeText(value)
+ setCopied(true)
+ copyTimerRef.current = setTimeout(() => {
+ setCopied(false)
+ }, 2000)
+ }
+ }
+
useEffect(() => {
Prism.highlightAll()
+
+ return () => {
+ clearTimeout(copyTimerRef.current)
+ }
}, [])
return (
@@ -61,7 +81,24 @@ const NoEvents = ({
<h2 className='text-2xl mb-2 text-center leading-snug'>
{t('project.codeExample')}
</h2>
- <Code text={umdBuildExample} language='html' />
+ <div className='relative'>
+ <Code text={umdBuildExample} language='html' />
+ <div className='absolute top-3 right-5'>
+ <Button
+ type='button'
+ onClick={() => setToClipboard(umdBuildExample)}
+ className='opacity-80 hover:opacity-100'
+ noBorder
+ >
+ <ClipboardDocumentIcon className='w-6 h-6 text-gray-100' />
+ {copied && (
+ <div className='animate-appear cursor-auto rounded p-1 absolute sm:top-0 top-0.5 right-8 text-xs text-green-500'>
+ {t('common.copied')}
+ </div>
+ )}
+ </Button>
+ </div>
+ </div>
</>
)}
</div>
diff --git a/src/pages/UserSettings/UserSettings.jsx b/src/pages/UserSettings/UserSettings.jsx
index 4dc565062..f01b7726d 100644
--- a/src/pages/UserSettings/UserSettings.jsx
+++ b/src/pages/UserSettings/UserSettings.jsx
@@ -431,7 +431,7 @@ const UserSettings = ({
>
<ClipboardDocumentIcon className='w-6 h-6' />
{copied && (
- <div className='animate-appear bg-white dark:bg-gray-700 cursor-auto rounded p-1 pl-2 absolute sm:top-0 top-0.5 right-8 text-xs text-green-600'>
+ <div className='animate-appear bg-white dark:bg-gray-700 cursor-auto rounded p-1 absolute sm:top-0 top-0.5 right-8 text-xs text-green-600'>
{t('common.copied')}
</div>
)}