Fix JobFeeds filter thresholds and direct live feed state update
This commit is contained in:
+32
-15
@@ -27,21 +27,42 @@ export const JobFeeds: React.FC<JobFeedsProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const [searchTerm, setSearchTerm] = useState('');
|
const [searchTerm, setSearchTerm] = useState('');
|
||||||
const [selectedPlatform, setSelectedPlatform] = useState<string>('ALL');
|
const [selectedPlatform, setSelectedPlatform] = useState<string>('ALL');
|
||||||
const [minMatch, setMinMatch] = useState<number>(80);
|
const [minMatch, setMinMatch] = useState<number>(0);
|
||||||
const [appliedFeedIds, setAppliedFeedIds] = useState<string[]>([]);
|
const [appliedFeedIds, setAppliedFeedIds] = useState<string[]>([]);
|
||||||
|
const [isFetchingFeeds, setIsFetchingFeeds] = useState(false);
|
||||||
|
const [localFeeds, setLocalFeeds] = useState<JobFeedItem[]>(jobFeeds);
|
||||||
|
|
||||||
const filteredFeeds = jobFeeds.filter(feed => {
|
const displayFeeds = localFeeds.length > 0 ? localFeeds : jobFeeds;
|
||||||
|
|
||||||
|
const filteredFeeds = displayFeeds.filter(feed => {
|
||||||
const matchesSearch =
|
const matchesSearch =
|
||||||
feed.title.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
feed.title.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||||
feed.company.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
feed.company.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||||
feed.location.toLowerCase().includes(searchTerm.toLowerCase());
|
feed.location.toLowerCase().includes(searchTerm.toLowerCase());
|
||||||
|
|
||||||
const matchesPlatform = selectedPlatform === 'ALL' || feed.platform === selectedPlatform;
|
const matchesPlatform = selectedPlatform === 'ALL' || feed.platform === selectedPlatform;
|
||||||
const matchesMatch = feed.estimatedMatch >= minMatch;
|
const matchesMatch = (feed.estimatedMatch || 80) >= minMatch;
|
||||||
|
|
||||||
return matchesSearch && matchesPlatform && matchesMatch;
|
return matchesSearch && matchesPlatform && matchesMatch;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleFetchLiveFeeds = async () => {
|
||||||
|
setIsFetchingFeeds(true);
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/jobs/fetch-feeds');
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
if (data.success && Array.isArray(data.jobs)) {
|
||||||
|
setLocalFeeds(data.jobs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to fetch live job feeds:', e);
|
||||||
|
} finally {
|
||||||
|
setIsFetchingFeeds(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleApply = async (feed: JobFeedItem) => {
|
const handleApply = async (feed: JobFeedItem) => {
|
||||||
setAppliedFeedIds(prev => [...prev, feed.id]);
|
setAppliedFeedIds(prev => [...prev, feed.id]);
|
||||||
await onQuickApplyFeed(feed);
|
await onQuickApplyFeed(feed);
|
||||||
@@ -63,19 +84,15 @@ export const JobFeeds: React.FC<JobFeedsProps> = ({
|
|||||||
|
|
||||||
<div className="flex items-center gap-2 text-xs font-semibold text-slate-300">
|
<div className="flex items-center gap-2 text-xs font-semibold text-slate-300">
|
||||||
<button
|
<button
|
||||||
onClick={async () => {
|
onClick={handleFetchLiveFeeds}
|
||||||
const res = await fetch('/api/jobs/fetch-feeds');
|
disabled={isFetchingFeeds}
|
||||||
if (res.ok) {
|
className="px-3.5 py-2 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-white transition flex items-center gap-1.5 shadow-lg shadow-indigo-600/20 disabled:opacity-50"
|
||||||
const data = await res.json();
|
|
||||||
if (data.jobs) window.location.reload();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
className="px-3 py-1.5 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-white transition flex items-center gap-1.5 shadow-lg shadow-indigo-600/20"
|
|
||||||
>
|
>
|
||||||
<Rss className="w-3.5 h-3.5" /> Refresh Live Feeds (API & RSS)
|
<Rss className={`w-3.5 h-3.5 ${isFetchingFeeds ? 'animate-spin' : ''}`} />
|
||||||
|
<span>{isFetchingFeeds ? 'Fetching Feeds...' : 'Refresh Live Feeds (API & RSS)'}</span>
|
||||||
</button>
|
</button>
|
||||||
<span className="px-3 py-1.5 rounded-xl bg-slate-800 border border-slate-700">
|
<span className="px-3 py-2 rounded-xl bg-slate-800 border border-slate-700">
|
||||||
Total Feeds: <strong className="text-indigo-400">{jobFeeds.length}</strong>
|
Total Feeds: <strong className="text-indigo-400">{displayFeeds.length}</strong>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -116,7 +133,7 @@ export const JobFeeds: React.FC<JobFeedsProps> = ({
|
|||||||
<span className="font-bold text-indigo-300">{minMatch}%</span>
|
<span className="font-bold text-indigo-300">{minMatch}%</span>
|
||||||
<input
|
<input
|
||||||
type="range"
|
type="range"
|
||||||
min="70"
|
min="0"
|
||||||
max="95"
|
max="95"
|
||||||
value={minMatch}
|
value={minMatch}
|
||||||
onChange={(e) => setMinMatch(Number(e.target.value))}
|
onChange={(e) => setMinMatch(Number(e.target.value))}
|
||||||
|
|||||||
Reference in New Issue
Block a user