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,106 +8,107 @@ 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);
if (!validURL) { if (!validURL) {
let checkProtocol = URLparser.exec("http://" + link); let checkProtocol = URLparser.exec("http://" + link);
if (checkProtocol) { if (checkProtocol) {
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 });
} }
} }
setLinkValue(event) { setLinkValue(event) {
this.setState({linkValue: event.target.value}); this.setState({ linkValue: event.target.value });
this.setLinkValid(event.target.value); this.setLinkValid(event.target.value);
} }
setLinkTitle(event) { setLinkTitle(event) {
this.setState({linkTitle: event.target.value}); this.setState({ linkTitle: event.target.value });
} }
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">
<textarea <textarea
className="pl2 bg-gray0-d white-d w-100 f8" className="pl2 bg-gray0-d white-d w-100 f8"
style={{ style={{
resize: "none", resize: "none",
height: 40, height: 40,
paddingTop: 10 paddingTop: 10
}} }}
placeholder="Paste link here" placeholder="Paste link here"
onChange={this.setLinkValue} onChange={this.setLinkValue}
spellCheck="false" spellCheck="false"
rows={1} rows={1}
onKeyPress={e => { onKeyPress={e => {
if (e.key === "Enter") { if (e.key === "Enter") {
e.preventDefault(); e.preventDefault();
this.onClickPost(); this.onClickPost();
} }
}} }}
value={this.state.linkValue} value={this.state.linkValue}
/> />
<textarea <textarea
className="pl2 bg-gray0-d white-d w-100 f8" className="pl2 bg-gray0-d white-d w-100 f8"
style={{ style={{
resize: "none", resize: "none",
height: 40, height: 40,
paddingTop: 16 paddingTop: 16
}} }}
placeholder="Enter title" placeholder="Enter title"
onChange={this.setLinkTitle} onChange={this.setLinkTitle}
spellCheck="false" spellCheck="false"
rows={1} rows={1}
onKeyPress={e => { onKeyPress={e => {
if (e.key === "Enter") { if (e.key === "Enter") {
e.preventDefault(); e.preventDefault();
this.onClickPost(); this.onClickPost();
} }
}} }}
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={{
bottom: 12, bottom: 12,
right: 8 right: 8
}}> }}>
Post Post
</button> </button>
</div> </div>
) );
} }
} }