Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | 14x 14x 14x 14x 14x 14x 4x 4x 4x 4x 4x 4x 14x 3x 14x 1x 1x 1x 1x 1x 1x 1x 1x 14x 1x 1x 1x 1x 1x 1x 14x 14x 1x 5x 1x | import React, { useEffect, useState } from 'react';
import type { Feed } from '../types';
import './Settings.css';
import { apiFetch } from '../utils';
export default function Settings() {
const [feeds, setFeeds] = useState<Feed[]>([]);
const [newFeedUrl, setNewFeedUrl] = useState('');
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [importFile, setImportFile] = useState<File | null>(null);
const fetchFeeds = () => {
setLoading(true);
apiFetch('/api/feed/')
.then((res) => {
Iif (!res.ok) throw new Error('Failed to fetch feeds');
return res.json();
})
.then((data) => {
setFeeds(data);
setLoading(false);
})
.catch((err) => {
setError(err.message);
setLoading(false);
});
};
useEffect(() => {
fetchFeeds();
}, []);
const handleAddFeed = (e: React.FormEvent) => {
e.preventDefault();
Iif (!newFeedUrl) return;
setLoading(true);
apiFetch('/api/feed/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url: newFeedUrl }),
})
.then((res) => {
Iif (!res.ok) throw new Error('Failed to add feed');
return res.json();
})
.then(() => {
setNewFeedUrl('');
fetchFeeds();
})
.catch((err) => {
setError(err.message);
setLoading(false);
});
};
const handleDeleteFeed = (id: number) => {
Iif (!globalThis.confirm('Are you sure you want to delete this feed?')) return;
setLoading(true);
apiFetch(`/api/feed/${id}`, {
method: 'DELETE',
})
.then((res) => {
Iif (!res.ok) throw new Error('Failed to delete feed');
setFeeds(feeds.filter((f) => f._id !== id));
setLoading(false);
})
.catch((err) => {
setError(err.message);
setLoading(false);
});
};
const handleImport = (e: React.FormEvent) => {
e.preventDefault();
if (!importFile) return;
setLoading(true);
const formData = new FormData();
formData.append('file', importFile);
formData.append('format', 'opml');
apiFetch('/api/import', {
method: 'POST',
body: formData,
})
.then((res) => {
if (!res.ok) throw new Error('Failed to import feeds');
return res.json();
})
.then(() => {
setImportFile(null);
fetchFeeds();
alert('Import successful!');
})
.catch((err) => {
setError(err.message);
setLoading(false);
});
};
return (
<div className="settings-page">
<h2>Settings</h2>
<div className="add-feed-section">
<h3>Add New Feed</h3>
<form onSubmit={handleAddFeed} className="add-feed-form">
<input
type="url"
value={newFeedUrl}
onChange={(e) => setNewFeedUrl(e.target.value)}
placeholder="https://example.com/feed.xml"
required
className="feed-input"
disabled={loading}
/>
<button type="submit" disabled={loading}>
Add Feed
</button>
</form>
</div>
<div className="import-export-section">
<div className="import-section">
<h3>Import Feeds (OPML)</h3>
<form onSubmit={handleImport} className="import-form">
<input
type="file"
accept=".opml,.xml,.txt"
onChange={(e) => setImportFile(e.target.files?.[0] || null)}
className="file-input"
disabled={loading}
/>
<button type="submit" disabled={!importFile || loading}>
Import
</button>
</form>
</div>
<div className="export-section">
<h3>Export Feeds</h3>
<div className="export-buttons">
<a href="/api/export/opml" className="export-btn">OPML</a>
<a href="/api/export/text" className="export-btn">Text</a>
<a href="/api/export/json" className="export-btn">JSON</a>
</div>
</div>
</div>
{error && <p className="error-message">{error}</p>}
<div className="feed-list-section">
<h3>Manage Feeds</h3>
{loading && <p>Loading...</p>}
<ul className="settings-feed-list">
{feeds.map((feed) => (
<li key={feed._id} className="settings-feed-item">
<div className="feed-info">
<span className="feed-title">{feed.title || '(No Title)'}</span>
<span className="feed-url">{feed.url}</span>
</div>
<button
onClick={() => handleDeleteFeed(feed._id)}
className="delete-btn"
disabled={loading}
title="Delete Feed"
>
Delete
</button>
</li>
))}
</ul>
</div>
</div>
);
}
|