2021-05-14 18:44:36 +00:00
|
|
|
import React from 'react'
|
|
|
|
import {Link} from 'react-router-dom'
|
|
|
|
import {Message, Grid, Loader, Header, Item} from 'semantic-ui-react'
|
|
|
|
import {useObservable} from 'rxjs-hooks'
|
|
|
|
import {of, from} from 'rxjs'
|
|
|
|
import {map, switchMap} from 'rxjs/operators'
|
2022-07-24 15:28:03 +00:00
|
|
|
import {useTranslation, Trans as Translate} from 'react-i18next'
|
2021-05-14 18:44:36 +00:00
|
|
|
|
|
|
|
import api from 'api'
|
2022-07-24 15:28:43 +00:00
|
|
|
import {Stats, Page} from 'components'
|
2022-07-24 15:29:04 +00:00
|
|
|
import type {Track} from 'types'
|
2021-05-14 18:44:36 +00:00
|
|
|
|
|
|
|
import {TrackListItem} from './TracksPage'
|
|
|
|
|
|
|
|
function MostRecentTrack() {
|
2022-07-24 15:28:03 +00:00
|
|
|
const {t} = useTranslation()
|
|
|
|
|
2021-05-14 18:44:36 +00:00
|
|
|
const track: Track | null = useObservable(
|
|
|
|
() =>
|
|
|
|
of(null).pipe(
|
|
|
|
switchMap(() => from(api.fetch('/tracks?limit=1'))),
|
|
|
|
map((response) => response?.tracks?.[0])
|
|
|
|
),
|
|
|
|
null,
|
|
|
|
[]
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-07-24 15:06:44 +00:00
|
|
|
<Header as="h2">{t('HomePage.mostRecentTrack')}</Header>
|
2021-05-14 18:44:36 +00:00
|
|
|
<Loader active={track === null} />
|
|
|
|
{track === undefined ? (
|
|
|
|
<Message>
|
2022-07-24 15:28:03 +00:00
|
|
|
<Translate i18nKey="HomePage.noPublicTracks">
|
|
|
|
No public tracks yet. <Link to="/upload">Upload the first!</Link>
|
|
|
|
</Translate>
|
2021-05-14 18:44:36 +00:00
|
|
|
</Message>
|
|
|
|
) : track ? (
|
|
|
|
<Item.Group>
|
|
|
|
<TrackListItem track={track} />
|
|
|
|
</Item.Group>
|
|
|
|
) : null}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function HomePage() {
|
|
|
|
return (
|
|
|
|
<Page>
|
|
|
|
<Grid stackable>
|
|
|
|
<Grid.Row>
|
2022-03-04 11:39:42 +00:00
|
|
|
<Grid.Column width={8}>
|
2021-05-14 18:44:36 +00:00
|
|
|
<Stats />
|
2022-03-04 11:39:42 +00:00
|
|
|
</Grid.Column>
|
|
|
|
<Grid.Column width={8}>
|
2021-05-14 18:44:36 +00:00
|
|
|
<MostRecentTrack />
|
|
|
|
</Grid.Column>
|
|
|
|
</Grid.Row>
|
|
|
|
</Grid>
|
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|