Skip to content

Commit

Permalink
Added live episodes to the front page
Browse files Browse the repository at this point in the history
  • Loading branch information
ericpp committed Mar 7, 2023
1 parent 40e5050 commit 2017979
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
21 changes: 21 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ app.use('/api/episodes/byfeedid', async (req, res) => {
res.send(response)
})

app.use('/api/episodes/live', async (req, res) => {
let max = req.query.max
const response = await api.custom('episodes/live', {pretty: true, max: max})
const minPublished = Math.floor(new Date().getTime() / 1000) - 3600

// assume live episodes posted within the past hour are live
// since the api doesn't provide start and end times

response.items = response.items.filter(item => {
return item.datePublished >= minPublished
})

response.count = response.items.length;

if (response.count === 0) {
response.description = 'No matching items'
}

res.send(response)
})

app.use('/api/add/byfeedurl', async (req, res) => {
let feedUrl = req.query.url
const response = await apiAdd.addByFeedUrl(feedUrl)
Expand Down
5 changes: 3 additions & 2 deletions ui/src/components/RecentPodcasts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {Link} from "react-router-dom";

interface IProps {
title?: string
liveTitle?: string
podcasts?: Array<any>
loading?: boolean
}
Expand Down Expand Up @@ -60,7 +61,7 @@ export default class RecentPodcasts extends React.Component<IProps, IState> {
}

render() {
const {loading, title, podcasts} = this.props
const {loading, title, liveTitle, podcasts} = this.props
const {index} = this.state
const selectedPodcast = podcasts[index]
return (
Expand All @@ -87,7 +88,7 @@ export default class RecentPodcasts extends React.Component<IProps, IState> {
</div>
{title && (
<div className="player-title">
<b>{title}</b>
<b>{selectedPodcast.live ? liveTitle : title}</b>
</div>
)}
<div className="player-cover-art">
Expand Down
34 changes: 28 additions & 6 deletions ui/src/pages/landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import './styles.scss'
interface IProps {}
interface IState {
loading?: boolean
recentPodcasts?: Array<any>
podcasts?: Array<any>
stats?: {}
}

export default class Landing extends React.Component<IProps, IState> {
state = {
loading: true,
recentPodcasts: [],
podcasts: [],
stats: {
feedCountTotal: '1,318,328',
feedCount3days: '81,919',
Expand All @@ -36,13 +36,13 @@ export default class Landing extends React.Component<IProps, IState> {

async componentDidMount(): Promise<void> {
this._isMounted = true
const recentPodcasts = (await this.getRecentEpisodes()).items
const podcasts = await this.getEpisodes()
const stats = await this.getStats()

if (this._isMounted) {
this.setState({
loading: false,
recentPodcasts,
podcasts,
stats,
})
}
Expand All @@ -68,8 +68,29 @@ export default class Landing extends React.Component<IProps, IState> {
return await response.json()
}

async getLiveEpisodes() {
let response = await fetch(`/api/episodes/live?max=3`, {
credentials: 'same-origin',
method: 'GET',
})
return await response.json()
}

async getEpisodes() {
let liveResponse = await this.getLiveEpisodes()
let episodes = liveResponse.items.map(ep => {
ep.live = true
return ep
})

let recentResponse = await this.getRecentEpisodes()
episodes = episodes.concat(recentResponse.items)

return episodes;
}

render() {
const { loading, recentPodcasts, stats } = this.state
const { loading, podcasts, stats } = this.state
updateTitle('Home')
return (
<div className="landing-content">
Expand Down Expand Up @@ -108,8 +129,9 @@ export default class Landing extends React.Component<IProps, IState> {
<div className="hero-pitch-right">
<RecentPodcasts
title="Recent Podcasts"
liveTitle="⬤ Live Podcasts"
loading={loading}
podcasts={recentPodcasts}
podcasts={podcasts}
/>
</div>
</div>
Expand Down

0 comments on commit 2017979

Please sign in to comment.