Skip to content

Commit

Permalink
Feedback from Will
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Jul 24, 2023
1 parent 7bee1b8 commit dd107f7
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 169 deletions.
7 changes: 5 additions & 2 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,20 @@ form > span > .row > label {
}

.submission {
border-radius: 16px;
padding: 8px;
margin: 6px;
background-color: #FFFFFF;
box-shadow: 0 3px 12px rgba(33,33,33,.2);
}

.submission:hover {
box-shadow: 0 3px 16px rgba(33,33,33,.2);
}

.submission-large {
border-radius: 16px;
box-shadow: 0 3px 12px rgba(33,33,33,.2);
}

.category-item-box {
display: inline-block;
height: 128px;
Expand Down
3 changes: 2 additions & 1 deletion src/MainRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BrowserRouter as Router, Redirect, Route, Switch } from 'react-router-d
import axios from 'axios'
import React, { useState } from 'react'
import config from './config'
import Home from './views/Home'
import Submissions from './views/Submissions'
import LogIn from './views/LogIn'
import Register from './views/Register'
Expand Down Expand Up @@ -60,7 +61,7 @@ const MainRouter = (props) => {
exact
path='/'
>
<Tasks isLoggedIn={isLoggedIn} isHomepage />
<Home isLoggedIn={isLoggedIn} isHomepage />
</Route>
<Route
exact
Expand Down
2 changes: 1 addition & 1 deletion src/components/CategoryItemBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const pickDetailUrl = (type, item) => {
const CategoryItemBox = (props) => {
return (
<div className={'col-lg-4 col ' + (props.isPreview ? '' : 'submission-cell')}>
<div className='submission'>
<div className='submission submission-large'>
<Link to={pickDetailUrl(props.type, props.item)} className='category-item-box'>
{props.type !== 'tag' && props.item.description &&
<div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/SubmissionBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const SubmissionBox = (props) => {
}

return (
<div className='submission'>
<div className='submission submission-large'>
<Link to={'/Submission/' + props.item.id}>
<div className='row h-100'>
<div className='col-md-2 col-sm-12 h-100'>
Expand Down
6 changes: 1 addition & 5 deletions src/components/SubmissionBoxSmall.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react'
import { Link } from 'react-router-dom'
import { library } from '@fortawesome/fontawesome-svg-core'
import { faExternalLinkAlt } from '@fortawesome/free-solid-svg-icons'
import logo from './../images/metriq_logo_secondary_blue.png'

library.add(faExternalLinkAlt)

Expand All @@ -11,10 +10,7 @@ const SubmissionBoxSmall = (props) =>
<div className='submission'>
<Link to={'/Submission/' + props.item.id}>
<div className='row'>
<div className='col-md-3 col-sm-12'>
<img src={props.item.thumbnailUrl ? props.item.thumbnailUrl : logo} alt='Submission thumbnail' className='submission-image-small' />
</div>
<div className='col-md-9 col-sm-12'>
<div className='col col-md-12'>
<div className='text-left submission-heading-small'>{(props.item.name.length > 80) ? (props.item.name.substring(0, 77) + '...') : props.item.name}</div>
</div>
</div>
Expand Down
2 changes: 0 additions & 2 deletions src/components/SubmissionScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ class SubmissionScroll extends React.Component {
key={index}
isLoggedIn={this.props.isLoggedIn}
isEditView={this.props.isEditView}
isUnderReview={!(item.approvedAt)}
isDraft={!(item.publishedAt)}
/>)}
{!this.props.isSmall && this.state.items.length && (
<Suspense fallback={<div>Loading...</div>}>
Expand Down
249 changes: 249 additions & 0 deletions src/views/Home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
import axios from 'axios'
import React from 'react'
import { Button, Tab, Tabs } from 'react-bootstrap'
import config from '../config'
import ErrorHandler from '../components/ErrorHandler'
import FormFieldValidator from '../components/FormFieldValidator'
import FormFieldTypeaheadRow from '../components/FormFieldTypeaheadRow'
import CategoryScroll from '../components/CategoryScroll'
import CategoryItemIcon from '../components/CategoryItemIcon'
import CategoryItemBox from '../components/CategoryItemBox'
import SubscribeButton from '../components/SubscribeButton'
import FormFieldAlertRow from '../components/FormFieldAlertRow'
import FormFieldWideRow from '../components/FormFieldWideRow'
import { sortCommon, sortAlphabetical } from '../components/SortFunctions'
import SotaChart from '../components/SotaChart'
import { withRouter, Link } from 'react-router-dom'
import { library } from '@fortawesome/fontawesome-svg-core'
import { faHeart, faExternalLinkAlt, faChartLine } from '@fortawesome/free-solid-svg-icons'
import TopSubmitters from '../components/TopSubmitters'
import SubmissionScroll from '../components/SubmissionScroll'

library.add(faHeart, faExternalLinkAlt, faChartLine)

const qedcIds = [34, 2, 97, 142, 150, 172, 173, 174, 175, 176, 177, 178, 179]

class Home extends React.Component {
constructor (props) {
super(props)
this.state = {
isLoading: true,
alphabetical: [],
allNames: [],
platforms: [],
featured: [],
trending: [],
popular: [],
latest: [],
topSubmitters: [],
activeTab: 'Trending',
filterId: null,
requestFailedMessage: ''
}

this.handleOnFilter = this.handleOnFilter.bind(this)
this.handleOnSelect = this.handleOnSelect.bind(this)
}

handleOnFilter (value) {
if (value) {
this.setState({ filterId: value.id })
}
}

handleOnSelect (value) {
if (value) {
this.props.history.push('/Task/' + value.id)
}
}

componentDidMount () {
axios.get(config.api.getUriPrefix() + '/task/submissionCount')
.then(res => {
const alphabetical = res.data.data
alphabetical.sort(sortAlphabetical)
this.setState({ alphabetical, isLoading: false })
})
.catch(err => {
this.setState({ requestFailedMessage: ErrorHandler(err) })
})

axios.get(config.api.getUriPrefix() + '/task/names')
.then(res => {
this.setState({
requestFailedMessage: '',
allNames: res.data.data
})
})
.catch(err => {
this.setState({ requestFailedMessage: ErrorHandler(err) })
})

axios.get(config.api.getUriPrefix() + '/platform/submissionCount')
.then(res => {
const common = [...res.data.data]
common.sort(sortCommon)
const rws = []
for (let i = 0; i < 2; ++i) {
const row = []
for (let j = 0; j < 3; ++j) {
row.push(common[3 * i + j])
}
rws.push(row)
}
this.setState({
requestFailedMessage: '',
platforms: rws
})
})
.catch(err => {
this.setState({ requestFailedMessage: ErrorHandler(err) })
})

axios.get(config.api.getUriPrefix() + '/task/submissionCount/34')
.then(res => {
const featured = [res.data.data]

axios.get(config.api.getUriPrefix() + '/task/submissionCount/50')
.then(res => {
featured.push(res.data.data)

axios.get(config.api.getUriPrefix() + '/task/submissionCount/164')
.then(res => {
featured.push(res.data.data)
this.setState({ featured })
})
.catch(err => {
this.setState({ requestFailedMessage: ErrorHandler(err) })
})
})
.catch(err => {
this.setState({ requestFailedMessage: ErrorHandler(err) })
})
})
.catch(err => {
this.setState({ requestFailedMessage: ErrorHandler(err) })
})
}

render () {
return (
<div id='metriq-main-content'>
<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>
<p className='text-left'>We have highlighted tasks here and you can search for more:</p>
<br />
<FormFieldTypeaheadRow
className='search-bar'
innerClassName='search-accent'
options={this.state.allNames}
labelKey='name'
inputName='name'
value=''
placeholder='🔎'
onChange={(field, value) => this.handleOnFilter(value)}
onSelect={this.handleOnSelect}
alignLabelRight
isRow
/>
<FormFieldWideRow>
<div className='row'>
<div className='col'>
<h4 align='left'>Featured Tasks</h4>
</div>
</div>
<div className='row'>
<div className='col-md-9'>
{this.state.featured.map((item, index) =>
<span key={index}>
<div className='task card'>
<div className='row h-100 text-left'>
<div className='col-lg-3 col-md-5 col'>
<Link to={'/Task/' + item.id} className='active-navlink'>
<SotaChart
isPreview
chartId={index}
xLabel='Time'
taskId={item.id}
key={index}
isLog
logBase={(index === 0) ? '2' : '10'}
/>
</Link>
</div>
<div className='col-lg-9 col-md-7 col'>
<h5>
<Link to={'/Task/' + item.id} className='active-navlink'>{item.name}</Link>
{qedcIds.includes(parseInt(item.id)) &&
<span> <Link to='/QEDC'><span className='link'>(QED-C)</span></Link></span>}
<span className='float-right'><SubscribeButton item={item} type='task' isLoggedIn={this.props.isLoggedIn} /></span>
</h5>
<Link to={'/Task/' + item.id} className='active-navlink'>{item.description}</Link>
</div>
</div>
<div className='row h-100'>
<div className='col-lg-4 col text-left'>
<Link to={'/Task/' + item.parentTask.id}>{item.parentTask.name}</Link>
</div>
<div className='col-lg-8 col'>
<Link to={'/Task/' + item.id} className='active-navlink' style={{ width: 'auto' }}>
<CategoryItemIcon count={item.resultCount} type='task' word='results' icon={faChartLine} />
<CategoryItemIcon count={item.submissionCount} type='task' word='submissions' icon={faExternalLinkAlt} />
<CategoryItemIcon count={item.upvoteTotal} type='task' word='up-votes' icon={faHeart} />
</Link>
</div>
</div>
</div>
<br />
</span>
)}
</div>
<div className='col-md-3'>
<div className='card top-submitters-card'>
<TopSubmitters isOnlyAllTime />
</div>
<br />
<div className='card top-submitters-card'>
<h5>Top Submissions</h5>
<Tabs id='top-submissions-tabs' activeKey={this.state.activeTab} onSelect={activeTab => this.setState({ activeTab })}>
<Tab eventKey='Trending' title='Trending' className='metriq-nav-tab'>
<SubmissionScroll isSmall sortType='trending' isLoggedIn={this.props.isLoggedIn} key={Math.random()} />
</Tab>
<Tab eventKey='Popular' title='Popular' className='metriq-nav-tab'>
<SubmissionScroll isSmall sortType='popular' isLoggedIn={this.props.isLoggedIn} key={Math.random()} />
</Tab>
<Tab eventKey='Latest' title='Latest' className='metriq-nav-tab'>
<SubmissionScroll isSmall sortType='latest' isLoggedIn={this.props.isLoggedIn} key={Math.random()} />
</Tab>
</Tabs>
</div>
</div>
</div>
</FormFieldWideRow>
<br />
<FormFieldWideRow className='centered-tabs'>
<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>} />
</FormFieldWideRow>
<br />
{(this.state.platforms.length > 0) &&
<span>
<FormFieldWideRow className='text-left'>
<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>
</FormFieldWideRow>
<FormFieldWideRow>
<div className='row h-100'>
<div className='col-lg-9 col h-100'>
{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>)}
</div>
</div>
</FormFieldWideRow>
<br />
</span>}
<FormFieldAlertRow>
<FormFieldValidator invalid={!!this.state.requestFailedMessage} message={this.state.requestFailedMessage} />
</FormFieldAlertRow>
</div>
)
}
}

export default withRouter(Home)
Loading

0 comments on commit dd107f7

Please sign in to comment.