diff options
Diffstat (limited to 'Biz/PodcastItLater')
| -rw-r--r-- | Biz/PodcastItLater/Web.py | 54 |
1 files changed, 47 insertions, 7 deletions
diff --git a/Biz/PodcastItLater/Web.py b/Biz/PodcastItLater/Web.py index ab46811..6d00649 100644 --- a/Biz/PodcastItLater/Web.py +++ b/Biz/PodcastItLater/Web.py @@ -570,6 +570,42 @@ class EpisodeList(Component[AnyChildren, EpisodeListAttrs]): ], ) + # "Add to my feed" button for logged-in users + user_button: html.div | html.button = html.div() + if user: + # Check if user already has this episode + user_has_episode = Core.Database.user_has_episode( + user["id"], + episode["id"], + ) + if user_has_episode: + user_button = html.button( + html.i(classes=["bi", "bi-check-circle-fill", "me-1"]), + "In your feed", + disabled=True, + classes=[ + "btn", + "btn-sm", + "btn-secondary", + "mt-2", + "ms-2", + ], + ) + else: + user_button = html.button( + html.i(classes=["bi", "bi-plus-circle", "me-1"]), + "Add to my feed", + hx_post=f"/episode/{episode['id']}/add-to-feed", + hx_swap="none", + classes=[ + "btn", + "btn-sm", + "btn-outline-primary", + "mt-2", + "ms-2", + ], + ) + episode_items.append( html.div( html.div( @@ -618,8 +654,12 @@ class EpisodeList(Component[AnyChildren, EpisodeListAttrs]): ) if episode.get("original_url") else html.div(), - # Admin button to add/remove from public feed - admin_button, + # Buttons row (admin and user buttons) + html.div( + admin_button, + user_button, + classes=["d-flex", "flex-wrap"], + ), classes=["card-body"], ), classes=["card", "mb-3"], @@ -1707,13 +1747,13 @@ def add_episode_to_feed(request: Request, episode_id: int) -> Response: # Track the "added" event Core.Database.track_episode_metric(episode_id, "added", user_id) + # Reload the current page to show updated button state + # Check referer to determine where to redirect + referer = request.headers.get("referer", "/") return Response( - '<div class="alert alert-success">' - '<i class="bi bi-check-circle me-2"></i>' - "Added to your feed! " - '<a href="/" class="alert-link">View your feed</a>' - "</div>", + "", status_code=200, + headers={"HX-Redirect": referer}, ) |
