1import React, { Component } from 'react';
3import Button from '../components/Button';
4import UploadButton from '../components/UploadButton';
6import { compose } from '../../bridge/lib/lib';
8import { PROFILE_STATES } from '../../lib/constants';
10const NEXT_STEP_NUM = 3;
12const validateBase64 = ({ data, pass, error }) => {
13 if (pass !== true) return { data, pass, error };
17 return { data: atob(data), pass: true, error: '' };
20 return { data: data, pass: false, error: 'File is not valid base64.' };
24const validateJSON = ({ data, pass, error }) => {
25 if (pass !== true) return { data, pass, error };
29 return { data: JSON.parse(data), pass: true, error: '' };
35 error: 'File does not decode into valid JSON.',
40const validateFile = ({ data, pass, error }) => {
41 if (pass !== true) return { data, pass, error };
43 if (data.file.type !== 'text/plain') {
44 return { data: data, pass: false, error: 'File must be a .txt file' };
47 if (data.file.name.includes('urbit-ships') === false) {
51 error: 'This does not appear to be the correct file.',
55 return { data: data.event.target.result, pass, error };
58const validateObject = ({ data, pass, error }) => {
59 if (pass !== true) return { data, pass, error };
61 const checkStringField = (obj, field) =>
62 field in obj && typeof obj[field] === 'string';
64 const checkShipField = (obj, field) =>
65 field in obj || Array.isArray(obj[field]);
67 const meetsRequirements = obj =>
68 checkStringField(obj, 'idCode') &&
69 checkShipField(obj, 'planets') &&
70 checkShipField(obj, 'stars') &&
71 checkShipField(obj, 'galaxies');
73 const didPass = meetsRequirements(data) ? true : false;
77 ? 'File is missing data, or the data is of incorrect data type.'
80 return { data: data, pass: didPass, error: err };
83// const preview = ship => {
84// const name = ob.patp(ship)
85// const sig = sigil.pour({
87// colorway: ['black', 'white'],
88// renderer: ReactSVGComponents,
93// <div className={'col-md-8'}>
94// <div className={'flex items-center bg-white black'} key={ ship }>
95// <div className={'col-md-5 pt-2 pl-5'}>
98// <div className={'col-md-5'}>
99// <h4 className={'text-mono text-500 mb-0'}>
105// <div className={'flex h-16 w-60 bg-white black items-center'} key={ ship }>
107// <div className={'pl-4 text-mono text-500'}>
114// const shipList = profile => {
115// const ships = Object.keys(profile)
118// <h2>Total Ships: { ships.length }</h2>
120// <div className={''}>
121// { ships.map(preview) }
127class Upload extends Component {
130 this.handleTXTUpload = this.handleTXTUpload.bind(this);
133 handleTXTUpload = event => {
134 const { setGlobalState } = this.props;
135 const file = event.files.item(0);
136 const reader = new FileReader();
138 reader.onload = event => {
139 const validated = compose(
144 )({ data: { event: event, file: file }, pass: true, error: '' });
146 if (validated.pass === true) {
147 const { galaxies, stars, planets } = validated.data;
149 'profile.error': validated.error,
150 'profile.state': PROFILE_STATES.UPLOAD_SUCCESS,
151 'profile.value': validated.data,
152 'profile.shipCount': galaxies.length + stars.length + planets.length,
156 'profile.error': validated.error,
157 'profile.state': PROFILE_STATES.UPLOAD_ERROR,
158 'profile.value': null,
163 reader.readAsText(file);
167 const { setGlobalState } = this.props;
169 const { props } = this;
172 props['profile.state'] === PROFILE_STATES.UPLOAD_SUCCESS ||
173 props['profile.state'] === PROFILE_STATES.INPUT_SUCCESS;
175 let uploadButtonClass =
176 props['profile.state'] === PROFILE_STATES.UPLOAD_ERROR
178 : props['profile.state'] === PROFILE_STATES.UPLOAD_SUCCESS
182 let uploadButtonText =
183 props['profile.state'] === PROFILE_STATES.UPLOAD_ERROR
184 ? 'Choose file again'
185 : props['profile.state'] === PROFILE_STATES.UPLOAD_SUCCESS
190 <div className={'col-md-6'}>
193 <code>{'urbit-ships.txt'}</code>
198 'This file contains your email and tells us what Urbit address space you own. Don’t have it? Return to Registration to download it.'
203 className={`${uploadButtonClass} table mt-4`}
204 onChange={this.handleTXTUpload}
209 {props['profil.error'] !== '' ? (
210 <p className={'orange'}>{props['profile.error']}</p>
216 // ? <ShipList ships={props['profile.value'].galaxies} title={'Galaxies'} />
221 // ? <ShipList ships={props['profile.value'].stars} title={'Stars'} />
226 // ? <ShipList ships={props['profile.value'].planet} title={'Planets'} />
231 <div className={'btn-tray'}>
235 // <p>Missing ships? Email <a href={'mailto:registration@urbit.org'}>{'registration@urbit.org'}</a></p>
239 success ? 'btn btn-primary mt-8' : 'btn shape-gray-10'
242 text={"I'm ready to begin →"}
245 route: '/Understand',
246 currentStep: NEXT_STEP_NUM,
260// const ShipList = (ships, title) => {
261// if (ships.length > 0) {
265// { ships.map(ship => preview(ship)) }
273export default Upload;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list