Skip to content

Commit 44907d3

Browse files
Samurai33claude
andauthored
fix: remove duplicate hardcoded AUDIO_MAP, use episode.audioUrl directly (#60)
lib/constants.ts's AUDIO_MAP duplicated episode.audioUrl with stale, broken paths for EP3/EP7. EpisodesSection.tsx and EpisodeRecommendations.tsx used it instead of the real field, so the homepage showed wrong play/no-audio states and 404s even after data/episodes.ts was fixed. Removed the duplicate map and its helper; both components now read episode.audioUrl directly. Fixes #59 Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
1 parent fc6945f commit 44907d3

5 files changed

Lines changed: 6 additions & 41 deletions

File tree

components/episode/EpisodeRecommendations.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ export function EpisodeRecommendations({ currentEpisodeId, limit = 3 }: EpisodeR
1818
const { playEpisode } = useAudio()
1919
const recommendations = getRecommendedEpisodes(currentEpisodeId, limit)
2020

21-
const getAudioUrl = (episodeId: string | number): string | null => {
22-
const audioMap: Record<string | number, string> = {
23-
3: "/audio/namoral-combating-digital-corruption-networks.mp3",
24-
7: "/audio/brasil-fraudes-digitais.mp3",
25-
}
26-
return audioMap[episodeId] || null
27-
}
28-
2921
if (recommendations.length === 0) {
3022
return (
3123
<Card className="bg-gray-900 border-gray-700">
@@ -43,7 +35,7 @@ export function EpisodeRecommendations({ currentEpisodeId, limit = 3 }: EpisodeR
4335
</CardHeader>
4436
<CardContent className="space-y-4">
4537
{recommendations.map((episode) => {
46-
const hasAudio = getAudioUrl(episode.id) !== null
38+
const hasAudio = !!episode.audioUrl
4739

4840
return (
4941
<Card key={episode.id} className="bg-gray-800 border-gray-600 hover:border-cyan-500/50 transition-colors">
@@ -70,12 +62,7 @@ export function EpisodeRecommendations({ currentEpisodeId, limit = 3 }: EpisodeR
7062
{hasAudio && (
7163
<Button
7264
size="sm"
73-
onClick={() =>
74-
playEpisode({
75-
...episode,
76-
audioUrl: getAudioUrl(episode.id),
77-
})
78-
}
65+
onClick={() => playEpisode(episode)}
7966
className="bg-gradient-to-r from-red-500 to-cyan-600 hover:from-red-400 hover:to-cyan-500"
8067
>
8168
<Play className="w-3 h-3 mr-1" />

components/sections/EpisodesSection.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { EpisodeBadge } from "@/components/ui/episode-badge"
99
import { useUI } from "@/contexts/UIContext"
1010
import { useAudio } from "@/contexts/AudioContext"
1111
import { useDashboard } from "@/contexts/DashboardContext"
12-
import { cn, getAudioUrl } from "@/lib/utils"
12+
import { cn } from "@/lib/utils"
1313
import type { Episode } from "@/types"
1414

1515
interface EpisodesSectionProps {
@@ -31,16 +31,10 @@ export function EpisodesSection({ episodes: originalEpisodes }: EpisodesSectionP
3131
})
3232

3333
const handlePlayEpisode = (episode: Episode) => {
34-
const audioUrl = getAudioUrl(episode.id)
35-
const episodeWithAudio = {
36-
...episode,
37-
audioUrl: audioUrl,
38-
}
39-
4034
if (isEpisodePlaying(episode.id)) {
4135
togglePlayPause()
4236
} else {
43-
playEpisode(episodeWithAudio)
37+
playEpisode(episode)
4438
}
4539
}
4640

@@ -67,7 +61,7 @@ export function EpisodesSection({ episodes: originalEpisodes }: EpisodesSectionP
6761
<div className="grid md:grid-cols-2 gap-6">
6862
{episodes.map((episode, index) => {
6963
const isCurrentlyPlaying = isEpisodePlaying(episode.id)
70-
const hasAudio = getAudioUrl(episode.id) !== null
64+
const hasAudio = !!episode.audioUrl
7165

7266
return (
7367
<Card

lib/constants.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ export const SEVERITY_COLORS: Record<SeverityLevel, string> = {
2121
low: "bg-green-500",
2222
}
2323

24-
export const AUDIO_MAP: Record<string | number, string> = {
25-
3: "/audio/namoral-combating-digital-corruption-networks.mp3",
26-
7: "/audio/brasil-fraudes-digitais.mp3",
27-
}
28-
2924
export const NAVIGATION_ITEMS = [
3025
{ label: "CASOS", href: "#casos" },
3126
{ label: "PROTOCOLOS", href: "#protocolos" },

lib/utils.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
getStatusColor,
44
getThreatColor,
55
getSeverityColor,
6-
getAudioUrl,
76
formatTime,
87
formatDate,
98
truncateText,
@@ -41,12 +40,6 @@ describe("getSeverityColor", () => {
4140
})
4241
})
4342

44-
describe("getAudioUrl", () => {
45-
it("returns null for an episode id with no mapped audio", () => {
46-
expect(getAudioUrl("no-such-episode-id")).toBeNull()
47-
})
48-
})
49-
5043
describe("formatTime", () => {
5144
it("formats seconds as m:ss", () => {
5245
expect(formatTime(0)).toBe("0:00")

lib/utils.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type ClassValue, clsx } from "clsx"
22
import { twMerge } from "tailwind-merge"
33
import type { EpisodeStatus, ThreatLevel, SeverityLevel } from "@/types"
4-
import { EPISODE_STATUS, THREAT_LEVELS, SEVERITY_COLORS, AUDIO_MAP } from "./constants"
4+
import { EPISODE_STATUS, THREAT_LEVELS, SEVERITY_COLORS } from "./constants"
55

66
export function cn(...inputs: ClassValue[]) {
77
return twMerge(clsx(inputs))
@@ -19,10 +19,6 @@ export function getSeverityColor(severity: SeverityLevel): string {
1919
return SEVERITY_COLORS[severity] || "bg-gray-500"
2020
}
2121

22-
export function getAudioUrl(episodeId: string | number): string | null {
23-
return AUDIO_MAP[episodeId] || null
24-
}
25-
2622
export function formatTime(time: number): string {
2723
const minutes = Math.floor(time / 60)
2824
const seconds = Math.floor(time % 60)

0 commit comments

Comments
 (0)