Skip to content

Commit 8a2b384

Browse files
authored
Merge pull request #256 from stevencrader/v4v-api-change
Change V4V page to load in chunks using new paginated feature of endpoint
2 parents 56c2cee + 8e65060 commit 8a2b384

File tree

2 files changed

+57
-25
lines changed

2 files changed

+57
-25
lines changed

server/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,13 @@ app.use('/api/recent/episodes', async (req, res) => {
8888
})
8989

9090
app.use('/api/podcasts/bytag', async (req, res) => {
91-
const response = await api.podcastsByTag()
91+
let max = req.query.max
92+
let start_at = req.query.start_at
93+
const response = await api.custom('podcasts/bytag', {
94+
'podcast-value': '',
95+
'max': max,
96+
'start_at': start_at,
97+
})
9298
res.send(response)
9399
})
94100

ui/src/pages/Podcast/Value4Value/index.tsx

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ export default class Value4Value extends React.PureComponent<IProps> {
5858
const {initialDisplay} = this.state
5959
this._isMounted = true
6060

61-
let results = (await this.getValue4ValuePodcasts()).feeds as Array<any>
61+
let popular = (await this.getValue4ValuePodcasts(200)).feeds as Array<any>
6262

6363
let pages = new Map<string, PageData>(
6464
[
65-
[SpecialPages.POPULAR, {groupPages: results, displayCount: initialDisplay}],
65+
[SpecialPages.POPULAR, {groupPages: popular, displayCount: initialDisplay}],
6666
[SpecialPages.SYMBOL, {groupPages: [], displayCount: initialDisplay}],
6767
[SpecialPages.NUMERIC, {groupPages: [], displayCount: initialDisplay}],
6868
]
@@ -73,25 +73,40 @@ export default class Value4Value extends React.PureComponent<IProps> {
7373
pages.set(SpecialPages.OTHER, {groupPages: [], displayCount: initialDisplay})
7474

7575
const allPages = []
76-
results.forEach((value) => {
77-
allPages.push(value)
78-
const title = value.title
79-
let startChar = SpecialPages.OTHER
80-
if (title) {
81-
startChar = title[0].toUpperCase()
82-
// handle
83-
if (!pages.has(startChar)) {
84-
if (SYMBOLS.includes(startChar)) {
85-
startChar = SpecialPages.SYMBOL
86-
} else if (NUMBERS.includes(startChar)) {
87-
startChar = SpecialPages.NUMERIC
88-
} else {
89-
startChar = SpecialPages.OTHER
76+
77+
let grandTotal = 0
78+
let startAt = 1
79+
while (true) {
80+
let v4vData = (await this.getValue4ValuePodcastsPaginated(startAt, 1000))
81+
const {status, feeds, total, nextStartAt} = v4vData
82+
startAt = nextStartAt
83+
grandTotal += total
84+
85+
if (status !== "true" || startAt === undefined) {
86+
break
87+
}
88+
89+
feeds.forEach((value) => {
90+
allPages.push(value)
91+
const title = value.title
92+
let startChar = SpecialPages.OTHER
93+
if (title) {
94+
startChar = title[0].toUpperCase()
95+
// handle
96+
if (!pages.has(startChar)) {
97+
if (SYMBOLS.includes(startChar)) {
98+
startChar = SpecialPages.SYMBOL
99+
} else if (NUMBERS.includes(startChar)) {
100+
startChar = SpecialPages.NUMERIC
101+
} else {
102+
startChar = SpecialPages.OTHER
103+
}
90104
}
91105
}
92-
}
93-
pages.get(startChar).groupPages.push(value)
94-
})
106+
pages.get(startChar).groupPages.push(value)
107+
})
108+
}
109+
95110
pages.set(SpecialPages.ALL, {groupPages: allPages, displayCount: initialDisplay})
96111

97112
const hash = this.getHash()
@@ -101,7 +116,7 @@ export default class Value4Value extends React.PureComponent<IProps> {
101116
{
102117
loading: false,
103118
pages: pages,
104-
total: results.length,
119+
total: grandTotal,
105120
},
106121
() => {
107122
this.updateSelectedPage(hash)
@@ -201,9 +216,18 @@ export default class Value4Value extends React.PureComponent<IProps> {
201216
})
202217
}
203218

204-
async getValue4ValuePodcasts() {
219+
async getValue4ValuePodcasts(max: number) {
220+
// noinspection SpellCheckingInspection
221+
let response = await fetch(`/api/podcasts/bytag?podcast-value&max=${max}`, {
222+
// credentials: 'same-origin',
223+
method: 'GET',
224+
})
225+
return await response.json()
226+
}
227+
228+
async getValue4ValuePodcastsPaginated(startAt: number, max: number) {
205229
// noinspection SpellCheckingInspection
206-
let response = await fetch(`/api/podcasts/bytag?podcast-value`, {
230+
let response = await fetch(`/api/podcasts/bytag?podcast-value&max=${max}&start_at=${startAt}`, {
207231
// credentials: 'same-origin',
208232
method: 'GET',
209233
})
@@ -406,11 +430,13 @@ export default class Value4Value extends React.PureComponent<IProps> {
406430
<p>These podcasts are set up to receive Bitcoin payments in real-time over the Lightning network using
407431
compatible <b><Link to="/apps">Podcasting 2.0 apps</Link></b>.</p>
408432

409-
<p>There are <b>{total}</b> Value 4 Value podcasts! Add yours by including the value block on your feed using <b><Link to="https://podcasterwallet.com/">podcasterwallet.com</Link></b></p>
433+
<p>There are <b>{total}</b> Value 4 Value podcasts! Add yours by including the value block on your feed
434+
using <b><Link to="https://podcasterwallet.com/">podcasterwallet.com</Link></b></p>
410435

411436
<br/>
412437

413-
<p>Podcasts are grouped by the first character of the title and then displayed in sort order for that page.</p>
438+
<p>Podcasts are grouped by the first character of the title and then displayed in sort order for that
439+
page.</p>
414440
<p>The "Popular" page shows all podcasts in the "popularity" order returned from the API.</p>
415441
<p>The "All" page shows all podcasts in sort order.</p>
416442

0 commit comments

Comments
 (0)