diff --git a/package.json b/package.json index 758019f..03f2450 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,8 @@ "react-redux": "^7.2.4", "react-router-dom": "^5.2.0", "react-scripts": "^5.0.0", + "react-share": "^4.4.0", + "react-spinners": "^0.13.3", "reactour": "^1.18.7", "redux": "^4.0.5", "redux-thunk": "^2.3.0", diff --git a/src/components/Workspace/ShareProject.js b/src/components/Workspace/ShareProject.js index f2114c1..d03cd25 100644 --- a/src/components/Workspace/ShareProject.js +++ b/src/components/Workspace/ShareProject.js @@ -4,15 +4,16 @@ import { connect } from "react-redux"; import { shareProject } from "../../actions/projectActions"; import { clearMessages } from "../../actions/messageActions"; import QRCode from "react-qr-code"; -import axios from 'axios'; +// import axios from 'axios'; import moment from "moment"; import Dialog from "../Dialog"; import Snackbar from "../Snackbar"; -import { Link } from "react-router-dom"; +// import { Link } from "react-router-dom"; +import GridLoader from "react-spinners/GridLoader"; import { withStyles } from "@material-ui/core/styles"; import IconButton from "@material-ui/core/IconButton"; import Tooltip from "@material-ui/core/Tooltip"; @@ -58,6 +59,8 @@ class WorkspaceFunc extends Component { open: false, id: "", shortLink: "", + isFetching: false, + loading: false, }; } @@ -117,6 +120,7 @@ class WorkspaceFunc extends Component { }; createShortlink(id) { + this.setState({ isFetching: true, loading: true }) const requestOptions = { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -124,7 +128,7 @@ class WorkspaceFunc extends Component { }; fetch('https://www.snsbx.de/api/shorty', requestOptions) .then(response => response.json()) - .then(data => this.setState({ shortLink: data[0].link })); + .then(data => this.setState({ shortLink: data[0].link, isFetching: false, loading: false })); } render() { @@ -152,75 +156,88 @@ class WorkspaceFunc extends Component { onClose={this.toggleDialog} onClick={this.toggleDialog} button={Blockly.Msg.button_close} - > -
- - Über den folgenden Link kannst du dein Programm teilen: - - this.toggleDialog()} - className={this.props.classes.link} - >{this.state.shortLink} - - { - navigator.clipboard.writeText( - this.state.shortLink - ); - this.setState({ - snackbar: true, - key: Date.now(), - message: Blockly.Msg.messages_copylink_success, - type: "success", - }); - }} - > - - - -
- + > + { this.state.isFetching ? ( +
+
- {this.props.project && - this.props.project.shared && - this.props.message.id !== "SHARE_SUCCESS" ? ( - {`Das Projekt wurde bereits geteilt. Der Link ist noch mindestens ${ - moment(this.props.project.shared).diff( - moment().utc(), - "days" - ) === 0 - ? moment(this.props.project.shared).diff( - moment().utc(), - "hours" - ) === 0 - ? `${moment(this.props.project.shared).diff( - moment().utc(), - "minutes" - )} Minuten` - : `${moment(this.props.project.shared).diff( - moment().utc(), - "hours" - )} Stunden` - : `${moment(this.props.project.shared).diff( - moment().utc(), - "days" - )} Tage` - } gültig.`} ) : ( - {`Der Link ist nun ${process.env.REACT_APP_SHARE_LINK_EXPIRES} Tage gültig.`} - )} -
+
+ + Über den folgenden Link kannst du dein Programm teilen: + + this.toggleDialog()} + className={this.props.classes.link} + target="_blank" + >{this.state.shortLink} + + { + navigator.clipboard.writeText( + this.state.shortLink + ); + this.setState({ + snackbar: true, + key: Date.now(), + message: Blockly.Msg.messages_copylink_success, + type: "success", + }); + }} + > + + + +
+ +
+ { this.props.project && + this.props.project.shared && + this.props.message.id !== "SHARE_SUCCESS" ? ( + + {`Das Projekt wurde bereits geteilt. Der Link ist noch mindestens ${ + moment(this.props.project.shared).diff( + moment().utc(), + "days" + ) === 0 + ? moment(this.props.project.shared).diff( + moment().utc(), + "hours" + ) === 0 + ? `${moment(this.props.project.shared).diff( + moment().utc(), + "minutes" + )} Minuten` + : `${moment(this.props.project.shared).diff( + moment().utc(), + "hours" + )} Stunden` + : `${moment(this.props.project.shared).diff( + moment().utc(), + "days" + )} Tage` + } gültig.`} + + ) : ( + + {`Der Link ist nun ${process.env.REACT_APP_SHARE_LINK_EXPIRES} Tage gültig.`} + + ) + } +
+ ) + }
);