Skip to content

Commit

Permalink
show simple progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate-Wessel committed Jul 12, 2024
1 parent e8cdca8 commit 5cd1789
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
35 changes: 23 additions & 12 deletions frontend/src/Sidebar/ResultsContainer.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { useContext, useState } from 'react'
import { useContext, useState, useEffect } from 'react'
import { DataContext } from '../Layout'
import BigButton from './BigButton'


export default function ResultsContainer(){
const [ results, setResults ] = useState(undefined)
const [ isFetchingData, setIsFetchingData ] = useState(false)
const [ doneCount, setDoneCount ] = useState(-1)
const { data } = useContext(DataContext)
const numResults = data.travelTimeQueries.length
useEffect(()=>{
data.queue.on('active',()=>{
setDoneCount(count => count + 1)
})
},[])
return (
<div>
{numResults} travel time{numResults == 1 ? '' : 's'} to estimate currently
{numResults} travel time{numResults == 1 ? '' : 's'} to be queried
{numResults > 0 && ! isFetchingData &&
<BigButton onClick={()=>{
setResults(undefined)
Expand All @@ -23,26 +28,32 @@ export default function ResultsContainer(){
Submit Query
</BigButton>
}
{isFetchingData &&
<p>Please wait while your request is being processed</p>
}
{isFetchingData && <>
<p>Finished fetching {doneCount}/{numResults} results</p>
<ProgressBar percentDone={100*doneCount/numResults}/>
</>}
{results && <>
<a download='results.json'
href={`data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(results.map(r=>r.resultsRecord('json'))))}`}
>
<BigButton>
Download results as JSON
</BigButton>
<BigButton>Download results as JSON</BigButton>
</a>
<a download='results.csv'
href={`data:text/plain;charset=utf-8,${encodeURIComponent([...results[0].resultsRecord('').keys()].join(',') + '\n' + results.map(r=>r.resultsRecord('csv')).join('\n'))}`}
>
<BigButton>
Download results as CSV
</BigButton>
<BigButton>Download results as CSV </BigButton>
</a>
</>
}
</div>
)
}

function ProgressBar({percentDone}){
return (
<svg viewBox='0 0 100 7'>
<rect height='100%' width='100%' fill='white' stroke='black' strokeWidth='1'/>
<rect height='100%' width={percentDone} fill='darkgreen' strokeWidth='1'/>
</svg>
)
}
1 change: 1 addition & 0 deletions frontend/src/spatialData.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,5 @@ export class SpatialData {
.map( TTQ => () => TTQ.fetchData() )
)
}
get queue(){ return this.#queue }
}

0 comments on commit 5cd1789

Please sign in to comment.