import React, { Component } from 'react'; import PropTypes from 'prop-types'; import cx from 'classnames'; import DBC from '../models/can/dbc'; import OpenDbc from '../api/OpenDbc'; import Modal from './Modals/baseModal'; import GithubDbcList from './GithubDbcList'; import DbcUpload from './DbcUpload'; export default class LoadDbcModal extends Component { static propTypes = { handleClose: PropTypes.func.isRequired, onDbcSelected: PropTypes.func.isRequired, openDbcClient: PropTypes.instanceOf(OpenDbc).isRequired, loginWithGithub: PropTypes.element.isRequired }; constructor(props) { super(props); this.state = { tab: 'OpenDBC', tabs: ['OpenDBC', 'GitHub', 'Upload'], dbc: null, dbcSource: null, userOpenDbcRepo: null }; this.onDbcLoaded = this.onDbcLoaded.bind(this); this.handleSave = this.handleSave.bind(this); this.renderTabNavigation = this.renderTabNavigation.bind(this); this.renderTabContent = this.renderTabContent.bind(this); this.renderActions = this.renderActions.bind(this); } componentWillMount() { this.props.openDbcClient.getUserOpenDbcFork().then((userOpenDbcRepo) => { this.setState({ userOpenDbcRepo }); }); } onDbcLoaded(dbcSource, dbcText) { const dbc = new DBC(dbcText); this.setState({ dbcSource, dbc }); } handleSave() { const { dbc, dbcSource } = this.state; if (dbc !== null) { this.props.onDbcSelected(dbcSource, dbc); } } renderTabNavigation() { return (
{this.state.tabs.map((tab) => ( ))}
); } renderTabContent() { const { tab } = this.state; if (tab === 'OpenDBC') { return ( ); } if (tab === 'GitHub') { if (!this.props.openDbcClient.hasAuth()) { return this.props.loginWithGithub; } if (this.state.userOpenDbcRepo === null) { return
Fork it
; } return ( ); } if (tab === 'Upload') { return ; } } renderActions() { return (
); } render() { return ( {this.renderTabContent()} ); } }