mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-15 10:02:47 +03:00
link: add "groupPath" to link-submit.js
This commit is contained in:
parent
140e1b4d9d
commit
83a7e45e74
File diff suppressed because one or more lines are too long
@ -1,6 +1,5 @@
|
||||
import React, { Component } from 'react'
|
||||
import { api } from '../../api';
|
||||
|
||||
import React, { Component } from "react";
|
||||
import { api } from "../../api";
|
||||
|
||||
export class LinkSubmit extends Component {
|
||||
constructor() {
|
||||
@ -9,23 +8,25 @@ export class LinkSubmit extends Component {
|
||||
linkValue: "",
|
||||
linkTitle: "",
|
||||
linkValid: false
|
||||
}
|
||||
};
|
||||
this.setLinkValue = this.setLinkValue.bind(this);
|
||||
this.setLinkTitle = this.setLinkTitle.bind(this);
|
||||
}
|
||||
|
||||
onClickPost() {
|
||||
let link = this.state.linkValue;
|
||||
let title = (this.state.linkTitle)
|
||||
let title = this.state.linkTitle
|
||||
? this.state.linkTitle
|
||||
: this.state.linkValue;
|
||||
api.postLink(this.props.path, link, title).then((r) => {
|
||||
api.postLink(this.props.groupPath, link, title).then(r => {
|
||||
this.setState({ linkValue: "", linkTitle: "" });
|
||||
});
|
||||
}
|
||||
|
||||
setLinkValid(link) {
|
||||
let URLparser = new RegExp(/((?:([\w\d\.-]+)\:\/\/?){1}(?:(www)\.?){0,1}(((?:[\w\d-]+\.)*)([\w\d-]+\.[\w\d]+))){1}(?:\:(\d+)){0,1}((\/(?:(?:[^\/\s\?]+\/)*))(?:([^\?\/\s#]+?(?:.[^\?\s]+){0,1}){0,1}(?:\?([^\s#]+)){0,1})){0,1}(?:#([^#\s]+)){0,1}/);
|
||||
let URLparser = new RegExp(
|
||||
/((?:([\w\d\.-]+)\:\/\/?){1}(?:(www)\.?){0,1}(((?:[\w\d-]+\.)*)([\w\d-]+\.[\w\d]+))){1}(?:\:(\d+)){0,1}((\/(?:(?:[^\/\s\?]+\/)*))(?:([^\?\/\s#]+?(?:.[^\?\s]+){0,1}){0,1}(?:\?([^\s#]+)){0,1})){0,1}(?:#([^#\s]+)){0,1}/
|
||||
);
|
||||
|
||||
let validURL = URLparser.exec(link);
|
||||
|
||||
@ -35,7 +36,7 @@ export class LinkSubmit extends Component {
|
||||
this.setState({ linkValid: true });
|
||||
this.setState({ linkValue: "http://" + link });
|
||||
} else {
|
||||
this.setState({linkValid: false})
|
||||
this.setState({ linkValid: false });
|
||||
}
|
||||
} else if (validURL) {
|
||||
this.setState({ linkValid: true });
|
||||
@ -52,10 +53,7 @@ export class LinkSubmit extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
let activeClasses = (this.state.linkValid)
|
||||
? "green2 pointer"
|
||||
: "gray2";
|
||||
let activeClasses = this.state.linkValid ? "green2 pointer" : "gray2";
|
||||
|
||||
return (
|
||||
<div className="relative ba b--gray4 b--gray2-d br1 w-100 mb6">
|
||||
@ -98,7 +96,9 @@ export class LinkSubmit extends Component {
|
||||
value={this.state.linkTitle}
|
||||
/>
|
||||
<button
|
||||
className={"absolute bg-gray0-d f8 ml2 flex-shrink-0 " + activeClasses}
|
||||
className={
|
||||
"absolute bg-gray0-d f8 ml2 flex-shrink-0 " + activeClasses
|
||||
}
|
||||
disabled={!this.state.linkValid}
|
||||
onClick={this.onClickPost.bind(this)}
|
||||
style={{
|
||||
@ -108,7 +108,7 @@ export class LinkSubmit extends Component {
|
||||
Post
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user