1import React, { Component } from 'react'
3import Button from '../components/Button'
4import UploadButton from '../components/UploadButton'
6import { compose } from '../lib/lib'
8import { PROFILE_STATES } from '../lib/constants'
11const NEXT_STEP_NUM = 3;
13const validateBase64 = ({ data, pass, error }) => {
14 if (pass !== true) return { data, pass, error }
18 return { data: atob(data), pass: true, error: '' }
21 return { data: data, pass: false, error: 'File is not valid base64.' }
25const validateJSON = ({ data, pass, error }) => {
26 if (pass !== true) return { data, pass, error }
30 return { data: JSON.parse(data), pass: true, error: '' }
33 return { data: data, pass: false, error: 'File does not decode into valid JSON.' }
37const validateFile = ({ data, pass, error }) => {
38 if (pass !== true) return { data, pass, error };
40 if (data.file.type !== 'text/plain') {
41 return { data: data, pass: false, error: 'File must be a .txt file' }
44 if (data.file.name.includes('urbit-ships') === false) {
45 return { data: data, pass: false, error: 'This does not appear to be the correct file.' }
48 return { data: data.event.target.result, pass, error };
53const validateObject = ({ data, pass, error }) => {
54 if (pass !== true) return { data, pass, error }
56 const checkStringField = (obj, field) =>
57 field in obj && typeof obj[field] === 'string';
59 const checkShipField = (obj, field) =>
60 field in obj || Array.isArray(obj[field]);
62 const meetsRequirements = obj =>
63 checkStringField(obj,'idCode')
64 && checkShipField(obj,'planets')
65 && checkShipField(obj,'stars')
66 && checkShipField(obj,'galaxies');
69 const didPass = meetsRequirements(data) ? true : false;
71 const err = didPass === false
72 ? 'File is missing data, or the data is of incorrect data type.'
75 return { data: data, pass: didPass, error: err }
78// const preview = ship => {
79// const name = ob.patp(ship)
80// const sig = sigil.pour({
82// colorway: ['black', 'white'],
83// renderer: ReactSVGComponents,
88// <div className={'col-md-8'}>
89// <div className={'flex items-center bg-white black'} key={ ship }>
90// <div className={'col-md-5 pt-2 pl-5'}>
93// <div className={'col-md-5'}>
94// <h4 className={'text-mono text-500 mb-0'}>
100 // <div className={'flex h-16 w-60 bg-white black items-center'} key={ ship }>
102 // <div className={'pl-4 text-mono text-500'}>
109// const shipList = profile => {
110// const ships = Object.keys(profile)
113// <h2>Total Ships: { ships.length }</h2>
115// <div className={''}>
116// { ships.map(preview) }
122class Upload extends Component {
125 this.handleTXTUpload = this.handleTXTUpload.bind(this)
129 handleTXTUpload = (event) => {
130 const { setGlobalState } = this.props
131 const file = event.files.item(0)
132 const reader = new FileReader()
134 reader.onload = (event) => {
136 const validated = compose(
141 )({ data: { event: event, file: file }, pass: true, error: '' })
143 if (validated.pass === true) {
144 const { galaxies, stars, planets } = validated.data
146 'profile.error': validated.error,
147 'profile.state': PROFILE_STATES.UPLOAD_SUCCESS,
148 'profile.value': validated.data,
149 'profile.shipCount': galaxies.length + stars.length + planets.length
153 'profile.error': validated.error,
154 'profile.state': PROFILE_STATES.UPLOAD_ERROR,
155 'profile.value': null,
160 reader.readAsText(file)
164 const { setGlobalState } = this.props;
166 const { props } = this;
169 props['profile.state'] === PROFILE_STATES.UPLOAD_SUCCESS ||
170 props['profile.state'] === PROFILE_STATES.INPUT_SUCCESS
172 let uploadButtonClass = props['profile.state'] === PROFILE_STATES.UPLOAD_ERROR
174 : props['profile.state'] === PROFILE_STATES.UPLOAD_SUCCESS
178 let uploadButtonText = props['profile.state'] === PROFILE_STATES.UPLOAD_ERROR
179 ? 'Choose file again'
180 : props['profile.state'] === PROFILE_STATES.UPLOAD_SUCCESS
185 <div className={'col-md-6'}>
186 <h2>{'Upload your '}<code>{'urbit-ships.txt'}</code></h2>
188 <p>{'This file contains your email and tells us what Urbit address space you own. Don’t have it? Return to Registration to download it.'}</p>
191 className={ `${uploadButtonClass} table mt-4` }
192 onChange={ this.handleTXTUpload }
198 { props['profil.error'] !== ''
199 ? <p className={'orange'}>{props['profile.error']}</p>
204 // ? <ShipList ships={props['profile.value'].galaxies} title={'Galaxies'} />
209 // ? <ShipList ships={props['profile.value'].stars} title={'Stars'} />
214 // ? <ShipList ships={props['profile.value'].planet} title={'Planets'} />
219 <div className={'btn-tray'}>
223 // <p>Missing ships? Email <a href={'mailto:registration@urbit.org'}>{'registration@urbit.org'}</a></p>
226 className={ success ? 'btn btn-primary mt-8' : 'btn shape-gray-10'}
227 disabled={ !success }
228 text={"I'm ready to begin →"}
229 onClick={ () => setGlobalState({ route: '/Understand', 'currentStep': NEXT_STEP_NUM })} />
239// const ShipList = (ships, title) => {
240// if (ships.length > 0) {
244// { ships.map(ship => preview(ship)) }
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