addon web: copied state

addon-dailer
lqqyt2423 3 years ago
parent b1ab6d8b73
commit f68e20296a

@ -17,6 +17,7 @@ interface Iprops {
interface IState { interface IState {
flowTab: 'Headers' | 'Preview' | 'Response' flowTab: 'Headers' | 'Preview' | 'Response'
copied: boolean
} }
class ViewFlow extends React.Component<Iprops, IState> { class ViewFlow extends React.Component<Iprops, IState> {
@ -25,6 +26,7 @@ class ViewFlow extends React.Component<Iprops, IState> {
this.state = { this.state = {
flowTab: 'Headers', flowTab: 'Headers',
copied: false,
} }
} }
@ -98,7 +100,7 @@ class ViewFlow extends React.Component<Iprops, IState> {
{ {
!(flowTab === 'Headers') ? null : !(flowTab === 'Headers') ? null :
<div> <div>
<p><Button size="sm" onClick={() => { <p><Button size="sm" variant={ this.state.copied ? 'success' : 'primary' } disabled={this.state.copied} onClick={() => {
const curl = fetchToCurl({ const curl = fetchToCurl({
url: flow.request.url, url: flow.request.url,
method: flow.request.method, method: flow.request.method,
@ -109,7 +111,14 @@ class ViewFlow extends React.Component<Iprops, IState> {
body: flow.requestBody(), body: flow.requestBody(),
}) })
copy(curl) copy(curl)
}}>Copy as cURL</Button></p>
this.setState({ copied: true }, () => {
setTimeout(() => {
this.setState({ copied: false })
}, 1000)
})
}}>{ this.state.copied ? 'Copied' : 'Copy as cURL' }</Button></p>
<div className="header-block"> <div className="header-block">
<p>General</p> <p>General</p>

Loading…
Cancel
Save