fetch shortlink
This commit is contained in:
parent
b97ce364ce
commit
c71a150f38
@ -57,6 +57,7 @@ class WorkspaceFunc extends Component {
|
|||||||
content: "",
|
content: "",
|
||||||
open: false,
|
open: false,
|
||||||
id: "",
|
id: "",
|
||||||
|
shortLink: "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,6 +68,7 @@ class WorkspaceFunc extends Component {
|
|||||||
(!this.props.multiple ||
|
(!this.props.multiple ||
|
||||||
this.props.message.status === this.props.project._id)
|
this.props.message.status === this.props.project._id)
|
||||||
) {
|
) {
|
||||||
|
this.createShortlink(this.props.message.status);
|
||||||
this.setState({
|
this.setState({
|
||||||
share: true,
|
share: true,
|
||||||
open: true,
|
open: true,
|
||||||
@ -105,48 +107,24 @@ class WorkspaceFunc extends Component {
|
|||||||
title: Blockly.Msg.messages_SHARE_SUCCESS,
|
title: Blockly.Msg.messages_SHARE_SUCCESS,
|
||||||
id: this.props.project._id,
|
id: this.props.project._id,
|
||||||
});
|
});
|
||||||
this.createShortlink();
|
|
||||||
} else {
|
} else {
|
||||||
this.props.shareProject(
|
this.props.shareProject(
|
||||||
this.props.name || this.props.project.title,
|
this.props.name || this.props.project.title,
|
||||||
this.props.projectType,
|
this.props.projectType,
|
||||||
this.props.project ? this.props.project._id : undefined
|
this.props.project ? this.props.project._id : undefined
|
||||||
);
|
);
|
||||||
this.createShortlink();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async createShortlink() {
|
createShortlink(id) {
|
||||||
// const requestOptions = {
|
const requestOptions = {
|
||||||
// method: 'POST',
|
method: 'POST',
|
||||||
// headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
// body: JSON.stringify({ "slug": "fabscm", "url": "https://www.google.de" })
|
body: JSON.stringify({ "slug": `blockly-${id}`, "url": `${window.location.origin}/share/${id}` })
|
||||||
// };
|
};
|
||||||
// const response = await fetch('https://snsbx.de/api/shorty', requestOptions);
|
fetch('https://www.snsbx.de/api/shorty', requestOptions)
|
||||||
// const data = await response.json();
|
.then(response => response.json())
|
||||||
// console.log(data);
|
.then(data => this.setState({ shortLink: data[0].link }));
|
||||||
|
|
||||||
var data = JSON.stringify({
|
|
||||||
"slug": "testest",
|
|
||||||
"url": "https://www.google.de"
|
|
||||||
});
|
|
||||||
|
|
||||||
var config = {
|
|
||||||
method: 'post',
|
|
||||||
url: 'https://snsbx.de/api/shorty',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
data : data
|
|
||||||
};
|
|
||||||
|
|
||||||
axios(config)
|
|
||||||
.then(function (response) {
|
|
||||||
console.log(JSON.stringify(response.data));
|
|
||||||
})
|
|
||||||
.catch(function (error) {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -180,10 +158,10 @@ class WorkspaceFunc extends Component {
|
|||||||
Über den folgenden Link kannst du dein Programm teilen:
|
Über den folgenden Link kannst du dein Programm teilen:
|
||||||
</Typography>
|
</Typography>
|
||||||
<Link
|
<Link
|
||||||
to={`/share/${this.state.id}`}
|
to={this.state.shortLink}
|
||||||
onClick={() => this.toggleDialog()}
|
onClick={() => this.toggleDialog()}
|
||||||
className={this.props.classes.link}
|
className={this.props.classes.link}
|
||||||
>{`${window.location.origin}/share/${this.state.id}`}</Link>
|
>{this.state.shortLink}</Link>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
title={Blockly.Msg.tooltip_copy_link}
|
title={Blockly.Msg.tooltip_copy_link}
|
||||||
arrow
|
arrow
|
||||||
@ -192,7 +170,7 @@ class WorkspaceFunc extends Component {
|
|||||||
<IconButton
|
<IconButton
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigator.clipboard.writeText(
|
navigator.clipboard.writeText(
|
||||||
`${window.location.origin}/share/${this.state.id}`
|
this.state.shortLink
|
||||||
);
|
);
|
||||||
this.setState({
|
this.setState({
|
||||||
snackbar: true,
|
snackbar: true,
|
||||||
@ -206,7 +184,7 @@ class WorkspaceFunc extends Component {
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<div style={{ display: 'flex', justifyContent: 'center' }}>
|
<div style={{ display: 'flex', justifyContent: 'center' }}>
|
||||||
<QRCode value={`${window.location.origin}/share/${this.state.id}`} />
|
<QRCode value={this.state.shortLink} />
|
||||||
</div>
|
</div>
|
||||||
{this.props.project &&
|
{this.props.project &&
|
||||||
this.props.project.shared &&
|
this.props.project.shared &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user