diff --git a/pkg/interface/publish/src/js/components/lib/join.js b/pkg/interface/publish/src/js/components/lib/join.js index d61b4d1eaa..e9843314af 100644 --- a/pkg/interface/publish/src/js/components/lib/join.js +++ b/pkg/interface/publish/src/js/components/lib/join.js @@ -1,13 +1,135 @@ import React, { Component } from 'react' +import classnames from 'classnames'; +import { Route, Link } from 'react-router-dom'; +import urbitOb from 'urbit-ob'; //TODO textarea + join button to make an api call export class JoinScreen extends Component { + constructor(props) { + super(props); + + this.state = { + book: '/', + error: false + }; + + this.bookChange = this.bookChange.bind(this); + } + + notebooksInclude(text, notebookObj) { + let verdict = false; + let keyPair = []; + // validate that it's a worthwhile thing to check + // certainly a unit would be nice here + if (text.indexOf('/') === -1) { + return verdict; + } else { + keyPair = text.split('/'); + }; + // check both levels of object + if (keyPair[0] in notebookObj) { + if (keyPair[1] in notebookObj[keyPair[0]]) { + verdict = true; + } + } + return verdict; + } + + onClickJoin() { + const { props, state } = this; + + let text = state.book; + // an error condition to prevent double joins? + if (this.notebooksInclude(state.book,props.notebooks) || + text.length === 0) { + props.history.push('/~publish'); + } + + let book = text.split('/'); + let ship = book[0]; + book.splice(0, 1); + book = '/' + book.join('/'); + + if (book.length < 2 || !urbitOb.isValidPatp(ship)) { + this.setState({ + error: true, + }); + return; + } + + let actionData = { + subscribe: { + who: ship.replace('~',''), + book: /\/?(.*)/.exec(book)[1] + } + } + + console.log('actionData', actionData); + + // TODO: askHistory setting + window.api.action("publish","publish-action", actionData); + + } + + bookChange(event) { + this.setState({ + book: event.target.value + }); + } + render() { + const { props } = this; + + let joinClasses = "db f9 green2 ba pa2 b--green2 bg-gray0-d pointer"; + if ((!this.state.book) || (this.state.book === "/")) { + joinClasses = 'db f9 gray2 ba pa2 b--gray3 bg-gray0-d pointer'; + } + + let errElem = (); + if (this.state.error) { + errElem = ( + + Notebook must have a valid name. + + ); + } + return ( -
- +
+
+ {"⟵ All Notebooks"} +
+

Subscribe to an Existing Notebook

+
+

Enter a ~ship/notebook-name

+

Notebook names use lowercase, hyphens, and slashes.

+