link: add "groupPath" to link-submit.js

This commit is contained in:
Matilde Park 2020-02-06 19:42:26 -05:00
parent 140e1b4d9d
commit 83a7e45e74
2 changed files with 58 additions and 60139 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,5 @@
import React, { Component } from 'react' import React, { Component } from "react";
import { api } from '../../api'; import { api } from "../../api";
export class LinkSubmit extends Component { export class LinkSubmit extends Component {
constructor() { constructor() {
@ -9,23 +8,25 @@ export class LinkSubmit extends Component {
linkValue: "", linkValue: "",
linkTitle: "", linkTitle: "",
linkValid: false linkValid: false
} };
this.setLinkValue = this.setLinkValue.bind(this); this.setLinkValue = this.setLinkValue.bind(this);
this.setLinkTitle = this.setLinkTitle.bind(this); this.setLinkTitle = this.setLinkTitle.bind(this);
} }
onClickPost() { onClickPost() {
let link = this.state.linkValue; let link = this.state.linkValue;
let title = (this.state.linkTitle) let title = this.state.linkTitle
? this.state.linkTitle ? this.state.linkTitle
: this.state.linkValue; : 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: "" }); this.setState({ linkValue: "", linkTitle: "" });
}); });
} }
setLinkValid(link) { 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); let validURL = URLparser.exec(link);
@ -35,7 +36,7 @@ export class LinkSubmit extends Component {
this.setState({ linkValid: true }); this.setState({ linkValid: true });
this.setState({ linkValue: "http://" + link }); this.setState({ linkValue: "http://" + link });
} else { } else {
this.setState({linkValid: false}) this.setState({ linkValid: false });
} }
} else if (validURL) { } else if (validURL) {
this.setState({ linkValid: true }); this.setState({ linkValid: true });
@ -52,10 +53,7 @@ export class LinkSubmit extends Component {
} }
render() { render() {
let activeClasses = this.state.linkValid ? "green2 pointer" : "gray2";
let activeClasses = (this.state.linkValid)
? "green2 pointer"
: "gray2";
return ( return (
<div className="relative ba b--gray4 b--gray2-d br1 w-100 mb6"> <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} value={this.state.linkTitle}
/> />
<button <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} disabled={!this.state.linkValid}
onClick={this.onClickPost.bind(this)} onClick={this.onClickPost.bind(this)}
style={{ style={{
@ -108,7 +108,7 @@ export class LinkSubmit extends Component {
Post Post
</button> </button>
</div> </div>
) );
} }
} }