Update category management and RSS endpoint handling

This commit is contained in:
2025-06-08 21:50:31 +09:00
parent 4aa1b5c56a
commit cd0e4065fc
13 changed files with 1171 additions and 70 deletions

View File

@ -18,7 +18,6 @@ interface CategoryGroup {
function CategoryList() {
const [groupedFeeds, setGroupedFeeds] = useState<CategoryGroup>({});
const [categories, setCategories] = useState<string[]>([]);
const [selectedCategory, setSelectedCategory] = useState<string | null>(null);
const [filteredFeeds, setFilteredFeeds] = useState<Feed[]>([]);
const [loading, setLoading] = useState(true);
@ -52,10 +51,9 @@ function CategoryList() {
}
const groupedData = await groupedResponse.json();
const categoriesData = await categoriesResponse.json();
await categoriesResponse.json();
setGroupedFeeds(groupedData.groupedFeeds || {});
setCategories(categoriesData.categories || []);
} catch (err) {
console.error("Category fetch error:", err);
setError(err instanceof Error ? err.message : "エラーが発生しました");
@ -72,11 +70,6 @@ function CategoryList() {
return groupedFeeds[category]?.length || 0;
};
const getTotalEpisodesCount = (feeds: Feed[]) => {
// This would require an additional API call to get episode counts per feed
// For now, just return the feed count
return feeds.length;
};
if (loading) {
return <div className="loading">...</div>;

View File

@ -0,0 +1,199 @@
import { useEffect, useState } from "react";
interface RSSEndpoint {
title: string;
url: string;
description: string;
feedCategory?: string;
}
interface RSSEndpointsData {
main: RSSEndpoint;
categories: RSSEndpoint[];
feeds: RSSEndpoint[];
}
export default function RSSEndpoints() {
const [endpoints, setEndpoints] = useState<RSSEndpointsData | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [copiedUrl, setCopiedUrl] = useState<string | null>(null);
useEffect(() => {
fetchRSSEndpoints();
}, []);
const fetchRSSEndpoints = async () => {
try {
setLoading(true);
const response = await fetch("/api/rss-endpoints");
if (!response.ok) {
throw new Error("RSS エンドポイント情報の取得に失敗しました");
}
const data = await response.json();
setEndpoints(data.endpoints);
} catch (err) {
setError(err instanceof Error ? err.message : "エラーが発生しました");
} finally {
setLoading(false);
}
};
const copyToClipboard = async (url: string) => {
try {
await navigator.clipboard.writeText(url);
setCopiedUrl(url);
setTimeout(() => setCopiedUrl(null), 2000);
} catch (err) {
console.error("クリップボードへのコピーに失敗しました:", err);
}
};
const openInNewTab = (url: string) => {
window.open(url, "_blank");
};
if (loading) return <div className="loading">...</div>;
if (error) return <div className="error">: {error}</div>;
if (!endpoints) return <div className="error"></div>;
return (
<div className="rss-endpoints">
<div className="rss-endpoints-header">
<h1>RSS </h1>
<p>RSSフィードURLをポッドキャストアプリに追加して音声コンテンツをお楽しみください</p>
</div>
{/* メインフィード */}
<section className="rss-section">
<h2>📻 </h2>
<div className="rss-endpoint-card main-feed">
<div className="endpoint-header">
<h3>{endpoints.main.title}</h3>
<span className="endpoint-badge main"></span>
</div>
<p className="endpoint-description">{endpoints.main.description}</p>
<div className="endpoint-url">
<code>{endpoints.main.url}</code>
<div className="endpoint-actions">
<button
onClick={() => copyToClipboard(endpoints.main.url)}
className={`copy-btn ${copiedUrl === endpoints.main.url ? "copied" : ""}`}
title="URLをコピー"
>
{copiedUrl === endpoints.main.url ? "✓" : "📋"}
</button>
<button
onClick={() => openInNewTab(endpoints.main.url)}
className="open-btn"
title="新しいタブで開く"
>
🔗
</button>
</div>
</div>
</div>
</section>
{/* カテゴリ別フィード */}
{endpoints.categories.length > 0 && (
<section className="rss-section">
<h2>🏷 </h2>
<div className="rss-endpoints-grid">
{endpoints.categories.map((endpoint, index) => (
<div key={index} className="rss-endpoint-card">
<div className="endpoint-header">
<h3>{endpoint.title}</h3>
<span className="endpoint-badge category"></span>
</div>
<p className="endpoint-description">{endpoint.description}</p>
<div className="endpoint-url">
<code>{endpoint.url}</code>
<div className="endpoint-actions">
<button
onClick={() => copyToClipboard(endpoint.url)}
className={`copy-btn ${copiedUrl === endpoint.url ? "copied" : ""}`}
title="URLをコピー"
>
{copiedUrl === endpoint.url ? "✓" : "📋"}
</button>
<button
onClick={() => openInNewTab(endpoint.url)}
className="open-btn"
title="新しいタブで開く"
>
🔗
</button>
</div>
</div>
</div>
))}
</div>
</section>
)}
{/* フィード別フィード */}
{endpoints.feeds.length > 0 && (
<section className="rss-section">
<h2>📡 </h2>
<div className="rss-endpoints-grid">
{endpoints.feeds.map((endpoint, index) => (
<div key={index} className="rss-endpoint-card">
<div className="endpoint-header">
<h3>{endpoint.title}</h3>
<div className="endpoint-badges">
<span className="endpoint-badge feed"></span>
{endpoint.feedCategory && (
<span className="endpoint-badge category-tag">
{endpoint.feedCategory}
</span>
)}
</div>
</div>
<p className="endpoint-description">{endpoint.description}</p>
<div className="endpoint-url">
<code>{endpoint.url}</code>
<div className="endpoint-actions">
<button
onClick={() => copyToClipboard(endpoint.url)}
className={`copy-btn ${copiedUrl === endpoint.url ? "copied" : ""}`}
title="URLをコピー"
>
{copiedUrl === endpoint.url ? "✓" : "📋"}
</button>
<button
onClick={() => openInNewTab(endpoint.url)}
className="open-btn"
title="新しいタブで開く"
>
🔗
</button>
</div>
</div>
</div>
))}
</div>
</section>
)}
{/* 使用方法の説明 */}
<section className="rss-section usage-info">
<h2>📱 使</h2>
<div className="usage-cards">
<div className="usage-card">
<h3>1. </h3>
<p>Apple PodcastsGoogle PodcastsSpotifyPocket Casts RSS 使</p>
</div>
<div className="usage-card">
<h3>2. RSS </h3>
<p>URLをコピーしてURLから購読使</p>
</div>
<div className="usage-card">
<h3>3. </h3>
<p></p>
</div>
</div>
</section>
</div>
);
}