import React, { FunctionComponent } from 'react'; import { dateReviver } from '../../helpers'; import { NavLink } from 'react-router-dom'; interface ExtractViewModel { extract_id: number; extracted_on: Date; download_path: string; } interface DataExtractsState { extracts: ExtractViewModel[]; latestExtract: ExtractViewModel; previousExtracts: ExtractViewModel[]; } export default class DataExtracts extends React.Component<{}, DataExtractsState> { constructor(props) { super(props); this.state = { extracts: undefined, latestExtract: undefined, previousExtracts: undefined }; } async componentDidMount() { const res = await fetch('/api/extracts'); const data = JSON.parse(await res.text(), dateReviver); const extracts = (data.extracts as ExtractViewModel[]) .sort((a, b) => a.extracted_on.valueOf() - b.extracted_on.valueOf()) .reverse(); this.setState({ extracts: extracts, latestExtract: extracts[0], previousExtracts: extracts.slice(1) }); } render() { return (

Open data extracts

Choose one of the links below to download an archive containing the open data collected on the Colouring London platform

By downloading data extracts from this site, you agree to the data accuracy agreement

{ this.state.extracts == undefined ?

Loading extracts...

: ( this.state.extracts.length === 0 ?

No extracts available

: null ) } { this.state.latestExtract != undefined ?

Latest extract

: null } { this.state.previousExtracts && this.state.previousExtracts.length > 0 ? (

Older extracts

    { this.state.previousExtracts.map(e =>
  • ) }
) : null }
); } } const ExtractDownloadLink: FunctionComponent = (props) => (

Extracted on {props.extracted_on.toDateString()}

);