Some fixes

This commit is contained in:
2025-06-11 23:03:40 +09:00
parent 71d3f1912d
commit 6e2700fe3d
8 changed files with 423 additions and 193 deletions

View File

@ -63,7 +63,7 @@ function EpisodeList() {
filterEpisodesByCategory();
}
}, [episodes, selectedCategory, searchQuery]);
// Reset to page 1 when category changes (but don't trigger if already on page 1)
useEffect(() => {
if (currentPage !== 1) {
@ -85,28 +85,30 @@ function EpisodeList() {
page: currentPage.toString(),
limit: pageSize.toString(),
});
if (selectedCategory) {
searchParams.append("category", selectedCategory);
}
const response = await fetch(`/api/episodes-with-feed-info?${searchParams}`);
const response = await fetch(
`/api/episodes-with-feed-info?${searchParams}`,
);
if (!response.ok) {
throw new Error("データベースからの取得に失敗しました");
}
const data = await response.json();
// Handle paginated response
if (data.episodes !== undefined) {
const dbEpisodes = data.episodes || [];
if (dbEpisodes.length === 0 && data.total === 0) {
// Database is empty, fallback to XML
console.log("Database is empty, falling back to XML parsing...");
setUseDatabase(false);
return;
}
setEpisodes(dbEpisodes);
setTotalEpisodes(data.total || 0);
setTotalPages(data.totalPages || 1);
@ -402,9 +404,7 @@ function EpisodeList() {
))}
</select>
)}
{isSearching && (
<span className="episode-meta-text">...</span>
)}
{isSearching && <span className="episode-meta-text">...</span>}
</div>
</div>
@ -527,7 +527,7 @@ function EpisodeList() {
))}
</tbody>
</table>
{/* Pagination Controls - only show for database mode */}
{useDatabase && totalPages > 1 && (
<div className="pagination-container">
@ -538,7 +538,7 @@ function EpisodeList() {
>
</button>
{/* Page numbers */}
<div className="pagination-pages">
{/* First page */}
@ -553,13 +553,13 @@ function EpisodeList() {
{currentPage > 4 && <span>...</span>}
</>
)}
{/* Current page and nearby pages */}
{Array.from({ length: Math.min(5, totalPages) }, (_, i) => {
const pageNum = Math.max(1, currentPage - 2) + i;
if (pageNum > totalPages) return null;
if (pageNum < Math.max(1, currentPage - 2)) return null;
return (
<button
key={pageNum}
@ -570,7 +570,7 @@ function EpisodeList() {
</button>
);
})}
{/* Last page */}
{currentPage < totalPages - 2 && (
<>
@ -584,15 +584,17 @@ function EpisodeList() {
</>
)}
</div>
<button
className="btn btn-secondary"
onClick={() => setCurrentPage(Math.min(totalPages, currentPage + 1))}
onClick={() =>
setCurrentPage(Math.min(totalPages, currentPage + 1))
}
disabled={currentPage === totalPages}
>
</button>
{/* Page size selector */}
<div className="pagination-size-selector">
<span style={{ fontSize: "14px" }}>:</span>