This commit is contained in:
2025-06-07 21:47:43 +09:00
parent ed47add7bc
commit 10612d245a
2 changed files with 52 additions and 48 deletions

View File

@ -7,58 +7,47 @@ import EpisodeDetail from './components/EpisodeDetail'
function App() { function App() {
const location = useLocation() const location = useLocation()
const isEpisodeDetail = location.pathname.startsWith('/episode/') const isMainPage = ['/', '/feeds', '/feed-requests'].includes(location.pathname)
const isFeedDetail = location.pathname.startsWith('/feeds/') && location.pathname.split('/').length === 3
if (isEpisodeDetail) {
return (
<Routes>
<Route path="/episode/:episodeId" element={<EpisodeDetail />} />
</Routes>
)
}
if (isFeedDetail) {
return (
<Routes>
<Route path="/feeds/:feedId" element={<FeedDetail />} />
</Routes>
)
}
return ( return (
<div className="container"> <div className="container">
<div className="header"> {isMainPage && (
<div className="title">Voice RSS Summary</div> <>
<div className="subtitle">RSS </div> <div className="header">
</div> <div className="title">Voice RSS Summary</div>
<div className="subtitle">RSS </div>
</div>
<div className="tabs"> <div className="tabs">
<Link <Link
to="/" to="/"
className={`tab ${location.pathname === '/' ? 'active' : ''}`} className={`tab ${location.pathname === '/' ? 'active' : ''}`}
> >
</Link> </Link>
<Link <Link
to="/feeds" to="/feeds"
className={`tab ${location.pathname === '/feeds' ? 'active' : ''}`} className={`tab ${location.pathname === '/feeds' ? 'active' : ''}`}
> >
</Link> </Link>
<Link <Link
to="/feed-requests" to="/feed-requests"
className={`tab ${location.pathname === '/feed-requests' ? 'active' : ''}`} className={`tab ${location.pathname === '/feed-requests' ? 'active' : ''}`}
> >
</Link> </Link>
</div> </div>
</>
)}
<div className="content"> <div className="content">
<Routes> <Routes>
<Route path="/" element={<EpisodeList />} /> <Route path="/" element={<EpisodeList />} />
<Route path="/feeds" element={<FeedList />} /> <Route path="/feeds" element={<FeedList />} />
<Route path="/feed-requests" element={<FeedManager />} /> <Route path="/feed-requests" element={<FeedManager />} />
<Route path="/episode/:episodeId" element={<EpisodeDetail />} />
<Route path="/feeds/:feedId" element={<FeedDetail />} />
</Routes> </Routes>
</div> </div>
</div> </div>

View File

@ -34,7 +34,7 @@ function EpisodeList() {
const [loading, setLoading] = useState(true) const [loading, setLoading] = useState(true)
const [error, setError] = useState<string | null>(null) const [error, setError] = useState<string | null>(null)
const [currentAudio, setCurrentAudio] = useState<string | null>(null) const [currentAudio, setCurrentAudio] = useState<string | null>(null)
const [useDatabase, setUseDatabase] = useState(true) const [useDatabase, setUseDatabase] = useState(false)
useEffect(() => { useEffect(() => {
fetchEpisodes() fetchEpisodes()
@ -43,6 +43,7 @@ function EpisodeList() {
const fetchEpisodes = async () => { const fetchEpisodes = async () => {
try { try {
setLoading(true) setLoading(true)
setError(null)
if (useDatabase) { if (useDatabase) {
// Try to fetch from database first // Try to fetch from database first
@ -51,9 +52,18 @@ function EpisodeList() {
throw new Error('データベースからの取得に失敗しました') throw new Error('データベースからの取得に失敗しました')
} }
const data = await response.json() const data = await response.json()
setEpisodes(data.episodes || []) const dbEpisodes = data.episodes || []
if (dbEpisodes.length === 0) {
// Database is empty, fallback to XML
console.log('Database is empty, falling back to XML parsing...')
setUseDatabase(false)
return
}
setEpisodes(dbEpisodes)
} else { } else {
// Fallback to XML parsing (existing functionality) // Use XML parsing as primary source
const response = await fetch('/api/episodes-from-xml') const response = await fetch('/api/episodes-from-xml')
if (!response.ok) { if (!response.ok) {
const errorData = await response.json() const errorData = await response.json()
@ -168,9 +178,14 @@ function EpisodeList() {
<div> <div>
<div style={{ marginBottom: '20px', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}> <div style={{ marginBottom: '20px', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<h2> ({episodes.length})</h2> <h2> ({episodes.length})</h2>
<button className="btn btn-secondary" onClick={fetchEpisodes}> <div style={{ display: 'flex', gap: '10px', alignItems: 'center' }}>
<span style={{ fontSize: '12px', color: '#666' }}>
</button> : {useDatabase ? 'データベース' : 'XML'}
</span>
<button className="btn btn-secondary" onClick={fetchEpisodes}>
</button>
</div>
</div> </div>
<table className="table"> <table className="table">