mirror of
https://github.com/ritz078/transform.git
synced 2026-11-23 01:12:07 +03:00
master merge
This commit is contained in:
commit
cebbbbb0b6
6 files changed
+138
-40
No files matched your search
@@ -1,12 +1,9 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import cn from "classnames";
|
||||
import Router from "next/router";
|
||||
import isBrowser from "is-in-browser";
|
||||
import copy from "copy-text-to-clipboard";
|
||||
import unfetch from "unfetch";
|
||||
|
||||
const theme = "tomorrow";
|
||||
|
||||
let CodeMirror;
|
||||
if (isBrowser) {
|
||||
CodeMirror = require("react-codemirror2").default;
|
||||
@@ -72,7 +69,8 @@ type Props = {
|
||||
splitValue: ?string,
|
||||
splitMode: ?string,
|
||||
showFetchButton: boolean,
|
||||
fetchButtonText: ?string
|
||||
fetchButtonText: ?string,
|
||||
getTransformedValue: Function
|
||||
};
|
||||
|
||||
export default class ConversionPanel extends PureComponent {
|
||||
@@ -99,13 +97,7 @@ export default class ConversionPanel extends PureComponent {
|
||||
componentDidMount() {
|
||||
const { defaultText, splitValue } = this.props;
|
||||
|
||||
const code = defaultText;
|
||||
const sValue = splitValue;
|
||||
this.setState({
|
||||
value: code,
|
||||
splitValue: sValue,
|
||||
resultValue: this.props.getTransformedValue(code, sValue)
|
||||
});
|
||||
this.onChange(defaultText, splitValue)
|
||||
}
|
||||
|
||||
fetchJSON = async () => {
|
||||
@@ -116,7 +108,7 @@ export default class ConversionPanel extends PureComponent {
|
||||
this.onChange(JSON.stringify(json, null, 2))
|
||||
}
|
||||
|
||||
onChange = (newValue, leftSplitValue) => {
|
||||
onChange = async (newValue, leftSplitValue) => {
|
||||
const nValue = newValue || this.state.value;
|
||||
const splitValue =
|
||||
leftSplitValue && typeof leftSplitValue === "string"
|
||||
@@ -124,8 +116,7 @@ export default class ConversionPanel extends PureComponent {
|
||||
: this.state.splitValue;
|
||||
|
||||
try {
|
||||
const code = this.props.getTransformedValue(nValue, splitValue);
|
||||
|
||||
const code = await this.props.getTransformedValue(nValue, splitValue);
|
||||
this.setState({
|
||||
resultValue: code,
|
||||
info: "",
|
||||
@@ -148,9 +139,7 @@ export default class ConversionPanel extends PureComponent {
|
||||
const checked = e.currentTarget.checked;
|
||||
if (this.props.onCheckboxChange) {
|
||||
this.props.onCheckboxChange(checked, () => {
|
||||
this.setState({
|
||||
resultValue: this.props.getTransformedValue(this.state.value)
|
||||
});
|
||||
this.onChange()
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user