Spaces:
Paused
Paused
CBV01 commited on
Commit ·
bce1b2b
1
Parent(s): 7667f35
Fix: Disabled scraper auto-save to leads and added 'Joined' badge tracking on Leads page
Browse files- backend/main.py +2 -2
- frontend/src/app/leads/page.tsx +24 -10
backend/main.py
CHANGED
|
@@ -966,8 +966,8 @@ async def _scrape_telegram_search(base_query: str, rows: list, queue: Optional[a
|
|
| 966 |
"is_member": is_member
|
| 967 |
}
|
| 968 |
unique_groups[chat_id_str] = item
|
| 969 |
-
# Auto-saving disabled
|
| 970 |
-
if user_id: asyncio.create_task(asyncio.to_thread(lambda: save_scraped_group(user_id, item)))
|
| 971 |
|
| 972 |
if queue:
|
| 973 |
await queue.put({"type": "result", "layer": 1, "data": item}) # type: ignore
|
|
|
|
| 966 |
"is_member": is_member
|
| 967 |
}
|
| 968 |
unique_groups[chat_id_str] = item
|
| 969 |
+
# Auto-saving disabled - user must manually select and save to leads
|
| 970 |
+
# if user_id: asyncio.create_task(asyncio.to_thread(lambda: save_scraped_group(user_id, item)))
|
| 971 |
|
| 972 |
if queue:
|
| 973 |
await queue.put({"type": "result", "layer": 1, "data": item}) # type: ignore
|
frontend/src/app/leads/page.tsx
CHANGED
|
@@ -18,6 +18,7 @@ interface SavedGroup {
|
|
| 18 |
global_shows: number;
|
| 19 |
source: string;
|
| 20 |
created_at: string;
|
|
|
|
| 21 |
}
|
| 22 |
|
| 23 |
interface MemberLead {
|
|
@@ -43,6 +44,7 @@ export default function LeadsPage() {
|
|
| 43 |
|
| 44 |
// Actions state
|
| 45 |
const [joining, setJoining] = useState(false);
|
|
|
|
| 46 |
const [isDeleting, setIsDeleting] = useState(false);
|
| 47 |
const [isExtracting, setIsExtracting] = useState(false);
|
| 48 |
const [extractingGroup, setExtractingGroup] = useState<string | null>(null);
|
|
@@ -133,6 +135,8 @@ export default function LeadsPage() {
|
|
| 133 |
...p, joined: data.joined, failed: data.failed,
|
| 134 |
log: [{ type: 'joined', name: data.name }, ...p.log.slice(0, 49)]
|
| 135 |
}));
|
|
|
|
|
|
|
| 136 |
} else if (data.type === 'failed') {
|
| 137 |
setJoinProgress(p => ({
|
| 138 |
...p, joined: data.joined, failed: data.failed,
|
|
@@ -222,13 +226,14 @@ export default function LeadsPage() {
|
|
| 222 |
body: JSON.stringify({ group_id: username || id, phone_number: phoneNumber })
|
| 223 |
});
|
| 224 |
if (res.ok) {
|
| 225 |
-
|
|
|
|
| 226 |
} else {
|
| 227 |
const d = await res.json();
|
| 228 |
-
|
| 229 |
}
|
| 230 |
} catch (e: any) {
|
| 231 |
-
|
| 232 |
}
|
| 233 |
};
|
| 234 |
|
|
@@ -510,13 +515,22 @@ export default function LeadsPage() {
|
|
| 510 |
<div className="flex gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
|
| 511 |
{l.itemType === 'community' && (
|
| 512 |
<>
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 520 |
<button
|
| 521 |
onClick={(e) => { e.stopPropagation(); setExtractingGroup(l.username || l.id); }}
|
| 522 |
className="p-1.5 bg-foreground/5 hover:bg-indigo-500/10 hover:text-indigo-500 rounded-lg text-foreground/30 transition-all"
|
|
|
|
| 18 |
global_shows: number;
|
| 19 |
source: string;
|
| 20 |
created_at: string;
|
| 21 |
+
is_joined?: boolean;
|
| 22 |
}
|
| 23 |
|
| 24 |
interface MemberLead {
|
|
|
|
| 44 |
|
| 45 |
// Actions state
|
| 46 |
const [joining, setJoining] = useState(false);
|
| 47 |
+
const [joinedIds, setJoinedIds] = useState<Set<string>>(new Set()); // Tracks which groups have been joined this session
|
| 48 |
const [isDeleting, setIsDeleting] = useState(false);
|
| 49 |
const [isExtracting, setIsExtracting] = useState(false);
|
| 50 |
const [extractingGroup, setExtractingGroup] = useState<string | null>(null);
|
|
|
|
| 135 |
...p, joined: data.joined, failed: data.failed,
|
| 136 |
log: [{ type: 'joined', name: data.name }, ...p.log.slice(0, 49)]
|
| 137 |
}));
|
| 138 |
+
// Mark this group as joined in local state so the badge appears
|
| 139 |
+
setJoinedIds(prev => new Set([...prev, data.name]));
|
| 140 |
} else if (data.type === 'failed') {
|
| 141 |
setJoinProgress(p => ({
|
| 142 |
...p, joined: data.joined, failed: data.failed,
|
|
|
|
| 226 |
body: JSON.stringify({ group_id: username || id, phone_number: phoneNumber })
|
| 227 |
});
|
| 228 |
if (res.ok) {
|
| 229 |
+
// Mark as joined immediately in UI so the button changes to a badge
|
| 230 |
+
setJoinedIds(prev => new Set([...prev, id, username || id]));
|
| 231 |
} else {
|
| 232 |
const d = await res.json();
|
| 233 |
+
setError(d.detail || 'Join failed');
|
| 234 |
}
|
| 235 |
} catch (e: any) {
|
| 236 |
+
setError(e.message);
|
| 237 |
}
|
| 238 |
};
|
| 239 |
|
|
|
|
| 515 |
<div className="flex gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
|
| 516 |
{l.itemType === 'community' && (
|
| 517 |
<>
|
| 518 |
+
{joinedIds.has(l.id) || (l.username && joinedIds.has(l.username)) ? (
|
| 519 |
+
<div
|
| 520 |
+
className="px-2 py-1 h-7 bg-emerald-500/10 text-emerald-500 rounded-lg text-[10px] font-bold tracking-wider uppercase flex items-center justify-center border border-emerald-500/20 shadow-sm"
|
| 521 |
+
title="Joined"
|
| 522 |
+
>
|
| 523 |
+
Joined
|
| 524 |
+
</div>
|
| 525 |
+
) : (
|
| 526 |
+
<button
|
| 527 |
+
onClick={(e) => { e.stopPropagation(); handleSingleJoin(l.id, l.username); }}
|
| 528 |
+
className="p-1.5 bg-foreground/5 hover:bg-emerald-500/10 hover:text-emerald-500 rounded-lg text-foreground/30 transition-all"
|
| 529 |
+
title="Join"
|
| 530 |
+
>
|
| 531 |
+
<UserPlus size={14} />
|
| 532 |
+
</button>
|
| 533 |
+
)}
|
| 534 |
<button
|
| 535 |
onClick={(e) => { e.stopPropagation(); setExtractingGroup(l.username || l.id); }}
|
| 536 |
className="p-1.5 bg-foreground/5 hover:bg-indigo-500/10 hover:text-indigo-500 rounded-lg text-foreground/30 transition-all"
|