import React, {Component} from 'react'; import './ConnectionContent.scss'; import {Col, Container, Dropdown, Row} from 'react-bootstrap'; import axios from 'axios'; import {withRouter} from "react-router-dom"; import {Redirect} from "react-router"; class ConnectionContent extends Component { constructor(props) { super(props); this.state = { loading: false, connectionContent: null, format: "default" }; this.validFormats = ["default", "hex", "hexdump", "base32", "base64", "ascii", "binary", "decimal", "octal"]; this.setFormat = this.setFormat.bind(this); } componentDidMount() { if ('format' in this.props.match.params) { this.setFormat(this.props.match.params.format); } } componentDidUpdate(prevProps, prevState, snapshot) { if (this.props.connection !== null && ( this.props.connection !== prevProps.connection || this.state.format !== prevState.format)) { this.setState({loading: true}); axios.get(`/api/streams/${this.props.connection.id}?format=${this.state.format}`).then(res => { this.setState({ connectionContent: res.data, loading: false }); }); } } setFormat(format) { if (this.validFormats.includes(format)) { this.setState({format: format}); } } render() { let content = this.state.connectionContent; if (content === null) { return
{payload}{redirect}