forked from Furumi/furumi-web
Browse a found podcast by season and cancel abandoned previews
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2ea3f7b337
commit
12617a6d52
7 files changed
+215
-19
No files matched your search
@@ -115,9 +115,15 @@
|
||||
<template x-if="$store.podcasts.found.preview">
|
||||
<div>
|
||||
<div class="podcast-found-status" x-show="$store.podcasts.found.preview.moved">{{ t.player_podcast_found_moved }}</div>
|
||||
<div class="podcast-chips podcast-found-seasons">
|
||||
<div class="podcast-chips podcast-found-seasons" role="group" aria-label="{{ t.player_podcast_season }}">
|
||||
<button class="podcast-chip" type="button"
|
||||
:class="{ active: $store.podcasts.found.season === 'all' }"
|
||||
@click="$store.podcasts.selectFoundSeason('all')">{{ t.player_podcast_all_seasons }}</button>
|
||||
<template x-for="season in $store.podcasts.found.preview.seasons" :key="$store.podcasts.seasonValue(season)">
|
||||
<span class="podcast-chip" x-text="`${$store.podcasts.seasonLabel(season)} · ${season.episode_count}`"></span>
|
||||
<button class="podcast-chip" type="button"
|
||||
:class="{ active: $store.podcasts.found.season === $store.podcasts.seasonValue(season) }"
|
||||
@click="$store.podcasts.selectFoundSeason($store.podcasts.seasonValue(season))"
|
||||
x-text="`${$store.podcasts.seasonLabel(season)} · ${season.episode_count}`"></button>
|
||||
</template>
|
||||
</div>
|
||||
<ul class="podcast-found-episodes">
|
||||
|
||||
@@ -3703,6 +3703,8 @@ document.addEventListener('alpine:init', () => {
|
||||
shareDialog: null,
|
||||
found: null,
|
||||
_foundToken: 0,
|
||||
_foundAbort: null,
|
||||
_foundPreviewSeq: 0,
|
||||
busy: {},
|
||||
expanded: {},
|
||||
_searchTimer: null,
|
||||
@@ -4063,15 +4065,18 @@ document.addEventListener('alpine:init', () => {
|
||||
},
|
||||
|
||||
foundMore(preview) {
|
||||
const more = Number(preview?.episode_count || 0) - (preview?.episodes?.length || 0);
|
||||
const listed = Number.isInteger(preview?.listed_count) ? preview.listed_count : Number(preview?.episode_count || 0);
|
||||
const more = listed - (preview?.episodes?.length || 0);
|
||||
return more > 0 ? T.podcastFoundMore.replace('{count}', String(more)) : '';
|
||||
},
|
||||
|
||||
openFound(hit) {
|
||||
if (GUEST || !hit?.podcast_id || !hit.feed_url) return;
|
||||
this._abortFoundPreview();
|
||||
this._foundToken += 1;
|
||||
this.found = {
|
||||
hit,
|
||||
season: 'all',
|
||||
preview: null,
|
||||
previewLoading: false,
|
||||
previewError: '',
|
||||
@@ -4085,28 +4090,60 @@ document.addEventListener('alpine:init', () => {
|
||||
},
|
||||
|
||||
closeFound() {
|
||||
// An abandoned preview is cancelled: the server stops reading
|
||||
// the feed and frees the account's feed-request slot.
|
||||
this._abortFoundPreview();
|
||||
this._foundToken += 1;
|
||||
this.found = null;
|
||||
},
|
||||
|
||||
_foundBody(hit) {
|
||||
_abortFoundPreview() {
|
||||
if (this._foundAbort) {
|
||||
try { this._foundAbort.abort(); } catch {}
|
||||
}
|
||||
this._foundAbort = null;
|
||||
},
|
||||
|
||||
_foundBody(hit, extra = {}) {
|
||||
// The card's id and origin URL, exactly as found: the server
|
||||
// checks that the id comes from this URL.
|
||||
return {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ podcast_id: hit.podcast_id, feed_url: hit.feed_url }),
|
||||
body: JSON.stringify({ podcast_id: hit.podcast_id, feed_url: hit.feed_url, ...extra }),
|
||||
};
|
||||
},
|
||||
|
||||
selectFoundSeason(value) {
|
||||
const found = this.found;
|
||||
if (!found || typeof value !== 'string') return;
|
||||
// The same chip again shows every season.
|
||||
const season = found.season === value ? 'all' : value;
|
||||
this.found = { ...found, season };
|
||||
this.loadFoundPreview();
|
||||
},
|
||||
|
||||
async loadFoundPreview() {
|
||||
const found = this.found;
|
||||
if (!found || found.previewLoading) return;
|
||||
if (!found) return;
|
||||
// A newer request (another season, Try again) replaces the
|
||||
// running one.
|
||||
this._abortFoundPreview();
|
||||
const controller = typeof AbortController === 'function' ? new AbortController() : null;
|
||||
this._foundAbort = controller;
|
||||
this._foundPreviewSeq += 1;
|
||||
const seq = this._foundPreviewSeq;
|
||||
const token = this._foundToken;
|
||||
const current = () => token === this._foundToken && seq === this._foundPreviewSeq;
|
||||
this.found = { ...found, previewLoading: true, previewError: '' };
|
||||
const season = found.season && found.season !== 'all' ? { season: found.season } : {};
|
||||
try {
|
||||
const preview = await this._json('/api/podcasts/discovery/preview', this._foundBody(found.hit));
|
||||
if (token !== this._foundToken) return;
|
||||
const preview = await this._json('/api/podcasts/discovery/preview', {
|
||||
...this._foundBody(found.hit, season),
|
||||
...(controller ? { signal: controller.signal } : {}),
|
||||
});
|
||||
if (!current()) return;
|
||||
this._foundAbort = null;
|
||||
this.found = {
|
||||
...this.found,
|
||||
preview: {
|
||||
@@ -4121,7 +4158,8 @@ document.addEventListener('alpine:init', () => {
|
||||
localPodcastId: this.found.localPodcastId || preview?.local_podcast_id || null,
|
||||
};
|
||||
} catch (error) {
|
||||
if (token !== this._foundToken) return;
|
||||
if (!current()) return;
|
||||
this._foundAbort = null;
|
||||
this.found = { ...this.found, previewLoading: false, previewError: error.message };
|
||||
}
|
||||
},
|
||||
|
||||
@@ -7207,7 +7207,6 @@ button.user-stat:hover {
|
||||
}
|
||||
.podcast-found-preview { margin: 8px 0; }
|
||||
.podcast-found-seasons { margin: 8px 0; }
|
||||
.podcast-found-seasons .podcast-chip { cursor: default; }
|
||||
.podcast-found-status {
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
|
||||
Reference in new issue
Block a user