From c4a1bbf493f4764bc7332eada95a3c0442491ed8 Mon Sep 17 00:00:00 2001 From: Paulo Martins Date: Tue, 7 Jan 2020 15:45:52 -0300 Subject: [PATCH] Success message when link to online editor is copied. --- packages/chrome-extension/resources/style.css | 13 ++++++ .../components/single/SingleEditorToolbar.tsx | 43 +++++++++++++++++-- .../online-editor/src/editor/EditorPage.tsx | 4 +- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/packages/chrome-extension/resources/style.css b/packages/chrome-extension/resources/style.css index 1eba2ccbca8..e95bc0f5d4d 100644 --- a/packages/chrome-extension/resources/style.css +++ b/packages/chrome-extension/resources/style.css @@ -112,6 +112,19 @@ color: #959595; } +.kogito-github-action-alert { + background-color: #1F1F1F; + color: #FFFFFF; + text-align: center; + padding: 3px 10px; + font-size: 12px; + line-height: 20px; +} + +.kogito-github-action-alert:after { + border-bottom-color: #1F1F1F; +} + .info-icon-container { margin-left: -9px !important; font-size: 0.8em; diff --git a/packages/chrome-extension/src/app/components/single/SingleEditorToolbar.tsx b/packages/chrome-extension/src/app/components/single/SingleEditorToolbar.tsx index c1ac9455367..4e5ef38d504 100644 --- a/packages/chrome-extension/src/app/components/single/SingleEditorToolbar.tsx +++ b/packages/chrome-extension/src/app/components/single/SingleEditorToolbar.tsx @@ -17,6 +17,11 @@ import * as React from "react"; import { useRef } from "react"; import { useGlobals } from "../common/GlobalContext"; +import { useState } from "react"; +import { useCallback } from "react"; +import { useEffect } from "react"; + +const ALERT_AUTO_CLOSE_TIMEOUT = 3000; export function SingleEditorToolbar(props: { readonly: boolean; @@ -29,7 +34,9 @@ export function SingleEditorToolbar(props: { linkToExternalEditor: string | undefined; }) { const globals = useGlobals(); + const [copyLinkSuccessAlertVisible, setCopyLinkSuccessAlertVisible] = useState(false); const linkToExternalEditorTextAreaRef = useRef(null); + const copyLinkSuccessAlertRef = useRef(null); const goFullScreen = (e: any) => { e.preventDefault(); @@ -54,10 +61,25 @@ export function SingleEditorToolbar(props: { const copyLinkToExternalEditor = (e: any) => { e.preventDefault(); linkToExternalEditorTextAreaRef.current?.select(); - document.execCommand("copy"); + if (document.execCommand("copy")) { + setCopyLinkSuccessAlertVisible(true); + } e.target.focus(); }; + const closeCopyLinkSuccessAlert = useCallback(() => setCopyLinkSuccessAlertVisible(false), []); + + useEffect(() => { + if (closeCopyLinkSuccessAlert) { + const autoCloseCopyLinkSuccessAlert = setTimeout(closeCopyLinkSuccessAlert, ALERT_AUTO_CLOSE_TIMEOUT); + return () => clearInterval(autoCloseCopyLinkSuccessAlert); + } + + return () => { + /* Do nothing */ + }; + }, [copyLinkSuccessAlertVisible]); + return ( <>
@@ -77,9 +99,22 @@ export function SingleEditorToolbar(props: { )} {globals.externalEditorManager && props.linkToExternalEditor && ( - +
+ + {copyLinkSuccessAlertVisible && ( +
+
+ Link copied to clipboard +
+
+ )} +
)} {!props.textMode && (