import { useState, useEffect } from 'react' interface Episode { id: string title: string audioPath: string createdAt: string article?: { link: string } feed?: { title: string } } function EpisodeList() { const [episodes, setEpisodes] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const [currentAudio, setCurrentAudio] = useState(null) useEffect(() => { fetchEpisodes() }, []) const fetchEpisodes = async () => { try { setLoading(true) const response = await fetch('/api/episodes') if (!response.ok) throw new Error('エピソードの取得に失敗しました') const data = await response.json() setEpisodes(data) } catch (err) { setError(err instanceof Error ? err.message : 'エラーが発生しました') } finally { setLoading(false) } } const formatDate = (dateString: string) => { return new Date(dateString).toLocaleString('ja-JP') } const playAudio = (audioPath: string) => { if (currentAudio) { const currentPlayer = document.getElementById(currentAudio) as HTMLAudioElement if (currentPlayer) { currentPlayer.pause() currentPlayer.currentTime = 0 } } setCurrentAudio(audioPath) } if (loading) { return
読み込み中...
} if (error) { return
{error}
} if (episodes.length === 0) { return (

エピソードがありません

フィード管理でRSSフィードを追加してください

) } return (

エピソード一覧 ({episodes.length}件)

{episodes.map((episode) => ( ))}
タイトル フィード 作成日時 操作
{episode.title}
{episode.article?.link && ( 元記事を見る )}
{episode.feed?.title || '不明'} {formatDate(episode.createdAt)} {currentAudio === episode.audioPath && (
)}
) } export default EpisodeList