feat: Add feed source filtering to settings and API
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -4,7 +4,7 @@ import { Helmet } from 'react-helmet';
|
||||
import localForage from 'localforage';
|
||||
import { sourceLink, infoLine, logos } from './utils.js';
|
||||
|
||||
function Feed({ updateCache, filterSmallweb }) {
|
||||
function Feed({ updateCache, filterSmallweb, feedSources }) {
|
||||
const [stories, setStories] = useState(() => JSON.parse(localStorage.getItem('stories')) || false);
|
||||
const [error, setError] = useState('');
|
||||
const [loadingStatus, setLoadingStatus] = useState(null);
|
||||
@@ -16,7 +16,7 @@ function Feed({ updateCache, filterSmallweb }) {
|
||||
} else {
|
||||
setStories(false);
|
||||
}
|
||||
}, [filterSmallweb]);
|
||||
}, [filterSmallweb, feedSources]);
|
||||
|
||||
useEffect(() => {
|
||||
const controller = new AbortController();
|
||||
@@ -30,7 +30,20 @@ function Feed({ updateCache, filterSmallweb }) {
|
||||
});
|
||||
}
|
||||
|
||||
fetch(filterSmallweb ? '/api?smallweb=true' : '/api', { signal: controller.signal })
|
||||
const params = new URLSearchParams();
|
||||
if (filterSmallweb) {
|
||||
params.append('smallweb', 'true');
|
||||
}
|
||||
|
||||
const allSources = Object.keys(feedSources);
|
||||
const enabledSources = allSources.filter(key => feedSources[key]);
|
||||
|
||||
if (enabledSources.length > 0 && enabledSources.length < allSources.length) {
|
||||
enabledSources.forEach(source => params.append('source', source));
|
||||
}
|
||||
const apiUrl = `/api?${params.toString()}`;
|
||||
|
||||
fetch(apiUrl, { signal: controller.signal })
|
||||
.then(res => {
|
||||
if (!res.ok) {
|
||||
throw new Error(`Server responded with ${res.status} ${res.statusText}`);
|
||||
@@ -117,7 +130,7 @@ function Feed({ updateCache, filterSmallweb }) {
|
||||
);
|
||||
|
||||
return () => controller.abort();
|
||||
}, [updateCache, filterSmallweb]);
|
||||
}, [updateCache, filterSmallweb, feedSources]);
|
||||
|
||||
return (
|
||||
<div className='container'>
|
||||
|
||||
Reference in New Issue
Block a user