on e366ef3 help sign in
bridge/src/views/ViewPoint.js
89 lines 2.3 kB history raw
1import Maybe from 'folktale/maybe';
2import React from 'react';
3import * as ob from 'urbit-ob';
5import { Button } from '../components/old/Base';
6import { Row, Col, H1, P } from '../components/old/Base';
7import { InnerLabel, PointInput, ValidatedSigil } from '../components/old/Base';
9import { ROUTE_NAMES } from '../lib/routeNames';
10import { withHistory } from '../store/history';
11import { compose } from '../lib/lib';
12import { withPointCursor } from '../store/pointCursor';
14class ViewPoint extends React.Component {
15 constructor(props) {
16 super(props);
18 this.state = {
19 pointName: '',
20 };
22 this.handlePointInput = this.handlePointInput.bind(this);
23 }
25 handlePointInput = pointName => {
26 if (pointName.length < 15) {
27 this.setState({ pointName });
28 }
29 };
31 render() {
32 const { pointName } = this.state;
33 const { history, setPointCursor } = this.props;
35 // NB (jtobin):
36 //
37 // could use a better patp parser in urbit-ob
38 let valid;
39 try {
40 valid = ob.isValidPatp(pointName);
41 } catch (err) {
42 valid = false;
43 }
45 return (
46 <Row>
47 <Col>
48 <H1>{'View a Point'}</H1>
50 <P>{'Enter a point name to view its public information.'}</P>
52 <PointInput
53 autoFocus
54 prop-size="lg"
55 prop-format="innerLabel"
56 className="mono"
57 placeholder="e.g. ~zod"
58 onChange={this.handlePointInput}
59 value={pointName}>
60 <InnerLabel>{'Point Name'}</InnerLabel>
61 <ValidatedSigil
62 className={'tr-0 mt-05 mr-0 abs'}
63 patp={pointName}
64 show
65 size={68}
66 margin={8}
67 />
68 </PointInput>
70 <Button
71 className={'mt-8'}
72 disabled={valid === false}
73 onClick={() => {
74 setPointCursor(Maybe.Just(parseInt(ob.patp2dec(pointName), 10)));
75 // ^ pointCursor expects native number type, not string
76 history.popAndPush(ROUTE_NAMES.SHIP);
77 }}>
78 {'Continue →'}
79 </Button>
80 </Col>
81 </Row>
82 );
83 }
86export default compose(
87 withHistory,
88 withPointCursor
89)(ViewPoint);