diff --git a/frontend/src/components/Header.tsx b/frontend/src/components/Header.tsx
index 7729f51..1d535f5 100644
--- a/frontend/src/components/Header.tsx
+++ b/frontend/src/components/Header.tsx
@@ -90,7 +90,11 @@ export default function Header({
) : (
- {page === "stats" ? t("header.usageStats") : t("header.channelManager")}
+ {page === "stats"
+ ? t("header.usageStats")
+ : page === "playlists"
+ ? t("header.account.playlists")
+ : t("header.channelManager")}
)}
diff --git a/frontend/src/components/Playlists.tsx b/frontend/src/components/Playlists.tsx
index d9dd279..b547cf5 100644
--- a/frontend/src/components/Playlists.tsx
+++ b/frontend/src/components/Playlists.tsx
@@ -110,9 +110,16 @@ export default function Playlists() {
const listQuery = useQuery({ queryKey: ["playlists"], queryFn: () => api.playlists() });
const playlists = listQuery.data ?? [];
- // Default the selection to the first playlist once the list loads.
+ // Keep the selection valid: default to the first playlist, and if the selected one
+ // disappears (e.g. just deleted) drop to the next available, or clear when none remain.
useEffect(() => {
- if (selectedId == null && playlists.length) setSelectedId(playlists[0].id);
+ if (!playlists.length) {
+ if (selectedId != null) setSelectedId(null);
+ return;
+ }
+ if (selectedId == null || !playlists.some((p) => p.id === selectedId)) {
+ setSelectedId(playlists[0].id);
+ }
}, [playlists, selectedId]);
const detailQuery = useQuery({
@@ -182,8 +189,13 @@ export default function Playlists() {
danger: true,
});
if (!ok) return;
- await api.deletePlaylist(selectedId);
- setSelectedId(null);
+ const deletedId = selectedId;
+ // Pick the next selection from what's left *now* (don't go via null, or the
+ // auto-select effect would re-pick the just-deleted id from the stale list).
+ const remaining = playlists.filter((p) => p.id !== deletedId);
+ setSelectedId(remaining[0]?.id ?? null);
+ await api.deletePlaylist(deletedId);
+ qc.removeQueries({ queryKey: ["playlist", deletedId] });
qc.invalidateQueries({ queryKey: ["playlists"] });
}