From f56d177b9bb94b7bb4e19925e0b1298c93123371 Mon Sep 17 00:00:00 2001 From: Developer <> Date: Thu, 11 Feb 2021 00:16:43 -0500 Subject: [PATCH] Added ability to copy g/ group link in GroupHeader to clipboard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Added: - ability to copy g/ group link in GroupHeader to clipboard on then show an alert on desktop --- .../gabsocial/components/group_header.js | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/app/javascript/gabsocial/components/group_header.js b/app/javascript/gabsocial/components/group_header.js index 42b99c6f..06150d66 100644 --- a/app/javascript/gabsocial/components/group_header.js +++ b/app/javascript/gabsocial/components/group_header.js @@ -5,6 +5,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes' import ImmutablePureComponent from 'react-immutable-pure-component' import { defineMessages, injectIntl } from 'react-intl' import { openPopover } from '../actions/popover' +import { showToast } from '../actions/toasts' import { addShortcut, removeShortcut, @@ -12,6 +13,7 @@ import { import { PLACEHOLDER_MISSING_HEADER_SRC, BREAKPOINT_EXTRA_SMALL, + TOAST_TYPE_SUCCESS, } from '../constants' import { me } from '../initial_state' import Responsive from '../features/ui/util/responsive_component' @@ -50,6 +52,29 @@ class GroupHeader extends ImmutablePureComponent { } } + handleCopySlug = () => { + const { group } = this.props + const url = !!group ? !!group.get('slug') ? `https://gab.com/g/${group.get('slug')}` : undefined : undefined + if (!url) return + + const textarea = document.createElement('textarea') + + textarea.textContent = url + textarea.style.position = 'fixed' + + document.body.appendChild(textarea) + + try { + textarea.select() + document.execCommand('copy') + } catch (e) { + // + } + + document.body.removeChild(textarea) + this.props.onShowCopyToast() + } + setInfoBtn = (c) => { this.infoBtn = c; } @@ -160,15 +185,22 @@ class GroupHeader extends ImmutablePureComponent {
-
+
{title} { !!slug && - - {slug} - + }
@@ -251,6 +283,11 @@ const mapDispatchToProps = (dispatch, { intl }) => ({ onRemoveShortcut(groupId) { dispatch(removeShortcut(null, 'group', groupId)) }, + onShowCopyToast() { + dispatch(showToast(TOAST_TYPE_SUCCESS, { + type: "SUCCESSFULLY_COPIED_TO_CLIPBOARD" + })) + }, })