2021-05-14 18:44:36 +00:00
|
|
|
import React from 'react'
|
2022-07-24 15:45:10 +00:00
|
|
|
import {Grid, Loader, Header, Item} from 'semantic-ui-react'
|
2021-05-14 18:44:36 +00:00
|
|
|
import {useObservable} from 'rxjs-hooks'
|
|
|
|
import {of, from} from 'rxjs'
|
|
|
|
import {map, switchMap} from 'rxjs/operators'
|
2022-07-24 15:45:10 +00:00
|
|
|
import {useTranslation} 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
|
|
|
|
2022-07-24 15:45:10 +00:00
|
|
|
import {TrackListItem, NoPublicTracksMessage} from './TracksPage'
|
2021-05-14 18:44:36 +00:00
|
|
|
|
|
|
|
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 ? (
|
2022-07-24 15:45:10 +00:00
|
|
|
<NoPublicTracksMessage />
|
2021-05-14 18:44:36 +00:00
|
|
|
) : 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>
|
|
|
|
)
|
|
|
|
}
|