|
| 1 | +import axios from 'axios' |
| 2 | +import React from 'react' |
| 3 | +import { Button, Tab, Tabs } from 'react-bootstrap' |
| 4 | +import config from '../config' |
| 5 | +import ErrorHandler from '../components/ErrorHandler' |
| 6 | +import FormFieldValidator from '../components/FormFieldValidator' |
| 7 | +import FormFieldTypeaheadRow from '../components/FormFieldTypeaheadRow' |
| 8 | +import CategoryScroll from '../components/CategoryScroll' |
| 9 | +import CategoryItemIcon from '../components/CategoryItemIcon' |
| 10 | +import CategoryItemBox from '../components/CategoryItemBox' |
| 11 | +import SubscribeButton from '../components/SubscribeButton' |
| 12 | +import FormFieldAlertRow from '../components/FormFieldAlertRow' |
| 13 | +import FormFieldWideRow from '../components/FormFieldWideRow' |
| 14 | +import { sortCommon, sortAlphabetical } from '../components/SortFunctions' |
| 15 | +import SotaChart from '../components/SotaChart' |
| 16 | +import { withRouter, Link } from 'react-router-dom' |
| 17 | +import { library } from '@fortawesome/fontawesome-svg-core' |
| 18 | +import { faHeart, faExternalLinkAlt, faChartLine } from '@fortawesome/free-solid-svg-icons' |
| 19 | +import TopSubmitters from '../components/TopSubmitters' |
| 20 | +import SubmissionScroll from '../components/SubmissionScroll' |
| 21 | + |
| 22 | +library.add(faHeart, faExternalLinkAlt, faChartLine) |
| 23 | + |
| 24 | +const qedcIds = [34, 2, 97, 142, 150, 172, 173, 174, 175, 176, 177, 178, 179] |
| 25 | + |
| 26 | +class Home extends React.Component { |
| 27 | + constructor (props) { |
| 28 | + super(props) |
| 29 | + this.state = { |
| 30 | + isLoading: true, |
| 31 | + alphabetical: [], |
| 32 | + allNames: [], |
| 33 | + platforms: [], |
| 34 | + featured: [], |
| 35 | + trending: [], |
| 36 | + popular: [], |
| 37 | + latest: [], |
| 38 | + topSubmitters: [], |
| 39 | + activeTab: 'Trending', |
| 40 | + filterId: null, |
| 41 | + requestFailedMessage: '' |
| 42 | + } |
| 43 | + |
| 44 | + this.handleOnFilter = this.handleOnFilter.bind(this) |
| 45 | + this.handleOnSelect = this.handleOnSelect.bind(this) |
| 46 | + } |
| 47 | + |
| 48 | + handleOnFilter (value) { |
| 49 | + if (value) { |
| 50 | + this.setState({ filterId: value.id }) |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + handleOnSelect (value) { |
| 55 | + if (value) { |
| 56 | + this.props.history.push('/Task/' + value.id) |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + componentDidMount () { |
| 61 | + axios.get(config.api.getUriPrefix() + '/task/submissionCount') |
| 62 | + .then(res => { |
| 63 | + const alphabetical = res.data.data |
| 64 | + alphabetical.sort(sortAlphabetical) |
| 65 | + this.setState({ alphabetical, isLoading: false }) |
| 66 | + }) |
| 67 | + .catch(err => { |
| 68 | + this.setState({ requestFailedMessage: ErrorHandler(err) }) |
| 69 | + }) |
| 70 | + |
| 71 | + axios.get(config.api.getUriPrefix() + '/task/names') |
| 72 | + .then(res => { |
| 73 | + this.setState({ |
| 74 | + requestFailedMessage: '', |
| 75 | + allNames: res.data.data |
| 76 | + }) |
| 77 | + }) |
| 78 | + .catch(err => { |
| 79 | + this.setState({ requestFailedMessage: ErrorHandler(err) }) |
| 80 | + }) |
| 81 | + |
| 82 | + axios.get(config.api.getUriPrefix() + '/platform/submissionCount') |
| 83 | + .then(res => { |
| 84 | + const common = [...res.data.data] |
| 85 | + common.sort(sortCommon) |
| 86 | + const rws = [] |
| 87 | + for (let i = 0; i < 2; ++i) { |
| 88 | + const row = [] |
| 89 | + for (let j = 0; j < 3; ++j) { |
| 90 | + row.push(common[3 * i + j]) |
| 91 | + } |
| 92 | + rws.push(row) |
| 93 | + } |
| 94 | + this.setState({ |
| 95 | + requestFailedMessage: '', |
| 96 | + platforms: rws |
| 97 | + }) |
| 98 | + }) |
| 99 | + .catch(err => { |
| 100 | + this.setState({ requestFailedMessage: ErrorHandler(err) }) |
| 101 | + }) |
| 102 | + |
| 103 | + axios.get(config.api.getUriPrefix() + '/task/submissionCount/34') |
| 104 | + .then(res => { |
| 105 | + const featured = [res.data.data] |
| 106 | + |
| 107 | + axios.get(config.api.getUriPrefix() + '/task/submissionCount/50') |
| 108 | + .then(res => { |
| 109 | + featured.push(res.data.data) |
| 110 | + |
| 111 | + axios.get(config.api.getUriPrefix() + '/task/submissionCount/164') |
| 112 | + .then(res => { |
| 113 | + featured.push(res.data.data) |
| 114 | + this.setState({ featured }) |
| 115 | + }) |
| 116 | + .catch(err => { |
| 117 | + this.setState({ requestFailedMessage: ErrorHandler(err) }) |
| 118 | + }) |
| 119 | + }) |
| 120 | + .catch(err => { |
| 121 | + this.setState({ requestFailedMessage: ErrorHandler(err) }) |
| 122 | + }) |
| 123 | + }) |
| 124 | + .catch(err => { |
| 125 | + this.setState({ requestFailedMessage: ErrorHandler(err) }) |
| 126 | + }) |
| 127 | + } |
| 128 | + |
| 129 | + render () { |
| 130 | + return ( |
| 131 | + <div id='metriq-main-content'> |
| 132 | + <p className='text-left'>Metriq is a platform for tracking and sharing quantum technology benchmarks. Users can make new submissions (link) that show the performance of different methods (link) on platforms (link) against tasks (link).</p> |
| 133 | + <p className='text-left'>We have highlighted tasks here and you can search for more:</p> |
| 134 | + <br /> |
| 135 | + <FormFieldTypeaheadRow |
| 136 | + className='search-bar' |
| 137 | + innerClassName='search-accent' |
| 138 | + options={this.state.allNames} |
| 139 | + labelKey='name' |
| 140 | + inputName='name' |
| 141 | + value='' |
| 142 | + placeholder='🔎' |
| 143 | + onChange={(field, value) => this.handleOnFilter(value)} |
| 144 | + onSelect={this.handleOnSelect} |
| 145 | + alignLabelRight |
| 146 | + isRow |
| 147 | + /> |
| 148 | + <FormFieldWideRow> |
| 149 | + <div className='row'> |
| 150 | + <div className='col'> |
| 151 | + <h4 align='left'>Featured Tasks</h4> |
| 152 | + </div> |
| 153 | + </div> |
| 154 | + <div className='row'> |
| 155 | + <div className='col-md-9'> |
| 156 | + {this.state.featured.map((item, index) => |
| 157 | + <span key={index}> |
| 158 | + <div className='task card'> |
| 159 | + <div className='row h-100 text-left'> |
| 160 | + <div className='col-lg-3 col-md-5 col'> |
| 161 | + <Link to={'/Task/' + item.id} className='active-navlink'> |
| 162 | + <SotaChart |
| 163 | + isPreview |
| 164 | + chartId={index} |
| 165 | + xLabel='Time' |
| 166 | + taskId={item.id} |
| 167 | + key={index} |
| 168 | + isLog |
| 169 | + logBase={(index === 0) ? '2' : '10'} |
| 170 | + /> |
| 171 | + </Link> |
| 172 | + </div> |
| 173 | + <div className='col-lg-9 col-md-7 col'> |
| 174 | + <h5> |
| 175 | + <Link to={'/Task/' + item.id} className='active-navlink'>{item.name}</Link> |
| 176 | + {qedcIds.includes(parseInt(item.id)) && |
| 177 | + <span> <Link to='/QEDC'><span className='link'>(QED-C)</span></Link></span>} |
| 178 | + <span className='float-right'><SubscribeButton item={item} type='task' isLoggedIn={this.props.isLoggedIn} /></span> |
| 179 | + </h5> |
| 180 | + <Link to={'/Task/' + item.id} className='active-navlink'>{item.description}</Link> |
| 181 | + </div> |
| 182 | + </div> |
| 183 | + <div className='row h-100'> |
| 184 | + <div className='col-lg-4 col text-left'> |
| 185 | + <Link to={'/Task/' + item.parentTask.id}>{item.parentTask.name}</Link> |
| 186 | + </div> |
| 187 | + <div className='col-lg-8 col'> |
| 188 | + <Link to={'/Task/' + item.id} className='active-navlink' style={{ width: 'auto' }}> |
| 189 | + <CategoryItemIcon count={item.resultCount} type='task' word='results' icon={faChartLine} /> |
| 190 | + <CategoryItemIcon count={item.submissionCount} type='task' word='submissions' icon={faExternalLinkAlt} /> |
| 191 | + <CategoryItemIcon count={item.upvoteTotal} type='task' word='up-votes' icon={faHeart} /> |
| 192 | + </Link> |
| 193 | + </div> |
| 194 | + </div> |
| 195 | + </div> |
| 196 | + <br /> |
| 197 | + </span> |
| 198 | + )} |
| 199 | + </div> |
| 200 | + <div className='col-md-3'> |
| 201 | + <div className='card top-submitters-card'> |
| 202 | + <TopSubmitters isOnlyAllTime /> |
| 203 | + </div> |
| 204 | + <br /> |
| 205 | + <div className='card top-submitters-card'> |
| 206 | + <h5>Top Submissions</h5> |
| 207 | + <Tabs id='top-submissions-tabs' activeKey={this.state.activeTab} onSelect={activeTab => this.setState({ activeTab })}> |
| 208 | + <Tab eventKey='Trending' title='Trending' className='metriq-nav-tab'> |
| 209 | + <SubmissionScroll isSmall sortType='trending' isLoggedIn={this.props.isLoggedIn} key={Math.random()} /> |
| 210 | + </Tab> |
| 211 | + <Tab eventKey='Popular' title='Popular' className='metriq-nav-tab'> |
| 212 | + <SubmissionScroll isSmall sortType='popular' isLoggedIn={this.props.isLoggedIn} key={Math.random()} /> |
| 213 | + </Tab> |
| 214 | + <Tab eventKey='Latest' title='Latest' className='metriq-nav-tab'> |
| 215 | + <SubmissionScroll isSmall sortType='latest' isLoggedIn={this.props.isLoggedIn} key={Math.random()} /> |
| 216 | + </Tab> |
| 217 | + </Tabs> |
| 218 | + </div> |
| 219 | + </div> |
| 220 | + </div> |
| 221 | + </FormFieldWideRow> |
| 222 | + <br /> |
| 223 | + <FormFieldWideRow className='centered-tabs'> |
| 224 | + <CategoryScroll className='col-lg-9 col' type='task' isLoading={this.state.isLoading} items={this.state.alphabetical} isLoggedIn={this.props.isLoggedIn} heading={<span>Platforms <Link to='/Tasks'><Button variant='outline-light' className='platforms-more-button'>Explore tasks</Button></Link></span>} /> |
| 225 | + </FormFieldWideRow> |
| 226 | + <br /> |
| 227 | + {(this.state.platforms.length > 0) && |
| 228 | + <span> |
| 229 | + <FormFieldWideRow className='text-left'> |
| 230 | + <h4 align='left' style={{ display: 'inline-block' }}>Platforms</h4> <Link to='/Platforms'><Button variant='outline-light' className='platforms-more-button'>See more platforms</Button></Link> |
| 231 | + </FormFieldWideRow> |
| 232 | + <FormFieldWideRow> |
| 233 | + <div className='row h-100'> |
| 234 | + <div className='col-lg-9 col h-100'> |
| 235 | + {this.state.platforms.map((row, rid) => <div className='row' key={rid}>{row.map((item, id) => <CategoryItemBox item={item} key={3 * rid + id} isLoggedIn={this.props.isLoggedIn} type='platform' />)}</div>)} |
| 236 | + </div> |
| 237 | + </div> |
| 238 | + </FormFieldWideRow> |
| 239 | + <br /> |
| 240 | + </span>} |
| 241 | + <FormFieldAlertRow> |
| 242 | + <FormFieldValidator invalid={!!this.state.requestFailedMessage} message={this.state.requestFailedMessage} /> |
| 243 | + </FormFieldAlertRow> |
| 244 | + </div> |
| 245 | + ) |
| 246 | + } |
| 247 | +} |
| 248 | + |
| 249 | +export default withRouter(Home) |
0 commit comments