import React, { PropTypes } from "react" //import "./topbar.less" import Logo from "./logo_small.png" export default class Topbar extends React.Component { constructor(props, context) { super(props, context) this.state = { url: props.specSelectors.url(), selectedIndex: 0 } } componentWillReceiveProps(nextProps) { this.setState({ url: nextProps.specSelectors.url() }) } onUrlChange =(e)=> { let {target: {value}} = e this.setState({url: value}) } loadSpec = (url) => { this.props.specActions.updateUrl(url) this.props.specActions.download(url) } onUrlSelect =(e)=> { let url = e.target.value || e.target.href this.loadSpec(url) this.setSelectedUrl(url) e.preventDefault() } downloadUrl = (e) => { this.loadSpec(this.state.url) e.preventDefault() } setSelectedUrl = (selectedUrl) => { const configs = this.props.getConfigs() const urls = configs.urls || [] if(urls && urls.length) { if(selectedUrl) { urls.forEach((spec, i) => { if(spec.url === selectedUrl) { this.setState({selectedIndex: i}) } }) } } } componentWillMount() { const configs = this.props.getConfigs() const urls = configs.urls || [] if(urls && urls.length) { let primaryName = configs["urls.primaryName"] if(primaryName) { urls.forEach((spec, i) => { if(spec.name === primaryName) { this.setState({selectedIndex: i}) } }) } } } componentDidMount() { const urls = this.props.getConfigs().urls || [] if(urls && urls.length) { this.loadSpec(urls[this.state.selectedIndex].url) } } render() { let { getComponent, specSelectors, getConfigs } = this.props const Button = getComponent("Button") const Link = getComponent("Link") let isLoading = specSelectors.loadingStatus() === "loading" let isFailed = specSelectors.loadingStatus() === "failed" let inputStyle = {} if(isFailed) inputStyle.color = "red" if(isLoading) inputStyle.color = "#aaa" const { urls } = getConfigs() let control = [] let formOnSubmit = null if(urls) { let rows = [] urls.forEach((link, i) => { rows.push() }) control.push( ) } else { formOnSubmit = this.downloadUrl control.push() control.push() } return (