From eab3c38c880da6f0159e02b73f2bc7938fe1f67a Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sat, 27 Jul 2024 13:49:19 +0300 Subject: [PATCH 1/2] uuid v4 gen --- src/nav.jsx | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/nav.jsx b/src/nav.jsx index 41b4b48..32c996f 100644 --- a/src/nav.jsx +++ b/src/nav.jsx @@ -2,6 +2,8 @@ import React from 'react'; import "@theme-toggles/react/css/Expand.css" import { Expand } from "@theme-toggles/react" import { Helmet, HelmetProvider } from 'react-helmet-async'; +import { v4 } from 'uuid'; +import { Notify } from 'notiflix/build/notiflix-notify-aio'; export default class NavComponent extends React.Component { /** @@ -15,15 +17,44 @@ export default class NavComponent extends React.Component { super(props); } + /** + * Generates a new UUID and copies it to the clipboard. + * + * @param {function} setUuid - A function to set the UUID state. + * @return {void} + */ + generateV4 = (setUuid) => { + // Generate a new UUID + const uuid = v4(); + + // Copy the UUID to the clipboard + navigator.clipboard.writeText(uuid) + .then(() => { + // Display a success message with the copied UUID + Notify.success('Text ' + uuid + ' copied'); + }) + .catch((error) => { + // Display an error message if the copy operation fails + Notify.failure('Error copying text: ' + error); + }); + + // Set the generated UUID as the new state + setUuid(uuid); + } + /** * Render method for the NavComponent. + * * This method returns the navigation panel (