import { useState } from 'react' import fetch from 'isomorphic-unfetch' import {useSocket} from '../../hooks/useSocket' import Layout from '../../components/Layout' const Tally = require('../../domain/Tally') const Log = require('../../domain/Log') const TallyDetails = props => { const [tally, setTally] = useState(Tally.fromValueObject(props.tally)) const [logs, setLogs] = useState(props.logs.map(log => Log.fromValueObject(log))) const socket = useSocket('tally.logged.' + tally.name, log => { const newLogs = logs.slice() newLogs.push(Log.fromValueObject(log)) setLogs(newLogs) }) const format = (log, idx) => { let className = "log " if(log.isWarning()) { className = className + "bg-warning " } else if (log.isError()) { className = className + "bg-danger " } else if (log.isStatus()) { className = className + "bg-primary " } return (