From 423978baf4c53e6504b531f0577d9ea62b003f0f Mon Sep 17 00:00:00 2001 From: JustSong Date: Tue, 25 Apr 2023 09:46:58 +0800 Subject: [PATCH] fix: copy token to search input if clipboard.writeText is not available (close #6) --- web/src/components/TokensTable.js | 5 +++-- web/src/constants/toast.constants.js | 1 + web/src/helpers/utils.js | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/web/src/components/TokensTable.js b/web/src/components/TokensTable.js index d1177f08..8d1cbcc5 100644 --- a/web/src/components/TokensTable.js +++ b/web/src/components/TokensTable.js @@ -1,7 +1,7 @@ import React, { useEffect, useState } from 'react'; import { Button, Form, Label, Message, Pagination, Table } from 'semantic-ui-react'; import { Link } from 'react-router-dom'; -import { API, copy, showError, showSuccess, timestamp2string } from '../helpers'; +import { API, copy, showError, showInfo, showSuccess, showWarning, timestamp2string } from '../helpers'; import { ITEMS_PER_PAGE } from '../constants'; @@ -243,7 +243,8 @@ const TokensTable = () => { if (await copy(token.key)) { showSuccess('已复制到剪贴板!'); } else { - showError('复制失败!'); + showWarning('无法复制到剪贴板,请手动复制,已将令牌填入搜索框。') + setSearchKeyword(token.key); } }} > diff --git a/web/src/constants/toast.constants.js b/web/src/constants/toast.constants.js index fc4e1d1c..8b212350 100644 --- a/web/src/constants/toast.constants.js +++ b/web/src/constants/toast.constants.js @@ -2,5 +2,6 @@ export const toastConstants = { SUCCESS_TIMEOUT: 500, INFO_TIMEOUT: 3000, ERROR_TIMEOUT: 5000, + WARNING_TIMEOUT: 10000, NOTICE_TIMEOUT: 20000 }; diff --git a/web/src/helpers/utils.js b/web/src/helpers/utils.js index 1a555462..37464aea 100644 --- a/web/src/helpers/utils.js +++ b/web/src/helpers/utils.js @@ -31,6 +31,7 @@ export function isMobile() { } let showErrorOptions = { autoClose: toastConstants.ERROR_TIMEOUT }; +let showWarningOptions = { autoClose: toastConstants.WARNING_TIMEOUT }; let showSuccessOptions = { autoClose: toastConstants.SUCCESS_TIMEOUT }; let showInfoOptions = { autoClose: toastConstants.INFO_TIMEOUT }; let showNoticeOptions = { autoClose: false }; @@ -74,6 +75,10 @@ export function showError(error) { } } +export function showWarning(message) { + toast.warn(message, showWarningOptions); +} + export function showSuccess(message) { toast.success(message, showSuccessOptions); }