From e3af0bcde9e44df69ed96258f82081439c19689c Mon Sep 17 00:00:00 2001 From: A Arroyo Date: Mon, 3 Feb 2020 13:11:49 -0800 Subject: [PATCH 1/4] basic join screen --- .../publish/src/js/components/lib/join.js | 118 +++++++++++++++++- .../publish/src/js/components/root.js | 2 +- 2 files changed, 116 insertions(+), 4 deletions(-) diff --git a/pkg/interface/publish/src/js/components/lib/join.js b/pkg/interface/publish/src/js/components/lib/join.js index d61b4d1eaa..f3b4d57b6a 100644 --- a/pkg/interface/publish/src/js/components/lib/join.js +++ b/pkg/interface/publish/src/js/components/lib/join.js @@ -1,13 +1,125 @@ 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); + } + + componentDidUpdate(prevProps, prevState) { + const { props, state } = this; + if (state.book in props.notebooks) { + props.history.push('/~publish'); + } + } + + onClickJoin() { + const { props, state } = this; + + let text = state.book; + // an error condition to prevent double joins? + if (text in props.notebooks || + text.length === 0) { + this.setState({ + error: true, + }); + return; + } + + 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.

+