import { useCallback, useEffect, useState } from "react"; import { useLocation, useSearch } from "wouter"; import type { components } from "../api/generated"; import { api } from "../services/api-client"; type Feed = components["schemas"]["Feed"]; interface Props { basePath: string; } export function FeedSidebar({ basePath }: Props) { const search = useSearch(); const [, setLocation] = useLocation(); const params = new URLSearchParams(search); const selectedFeedId = params.get("feed"); const [feeds, setFeeds] = useState([]); const [fetching, setFetching] = useState(true); const fetchFeeds = useCallback(async () => { setFetching(true); const { data } = await api.GET("/api/feeds"); if (data) { setFeeds(data); } setFetching(false); }, []); useEffect(() => { fetchFeeds(); }, [fetchFeeds]); const handleSelect = (feedId: string | null) => { if (feedId) { setLocation(`${basePath}?feed=${feedId}`); } else { setLocation(basePath); } }; return ( ); }